garten

view weather.c @ 3:0c19ad487f02

first weather implementation (static values)
author meillo@marmaro.de
date Wed, 14 May 2008 21:09:09 +0200
parents
children 9bd0a2100694
line source
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <mysql.h>
5 #include "db.h"
6 #include "game.h"
11 void set_weather() {
12 int temperature, sun, rain, wind, humidity;
14 /* get last weather and calculate the next one *
15 sprintf(query, "select time from simulation where name = '%s' ", gamename);
16 db_query(query);
17 result = mysql_store_result(conn);
18 if (mysql_num_rows(result)) {
19 row = mysql_fetch_row(result);
20 time = atoi(row[0]);
21 }
22 mysql_free_result(result);
23 */
25 temperature = 20;
26 sun = 5;
27 rain = 1;
28 wind = 10;
29 humidity = 40;
32 /* set weather */
33 sprintf(query, " insert into weather \
34 (tick, game_id, temperature, sun, rain, wind, humidity) \
35 values ('%d', '%d', '%d', '%d', '%d', '%d', '%d') ",
36 gametime, gameid, temperature, sun, rain, wind, humidity);
37 db_query(query);
38 if (mysql_affected_rows(conn) > 0) {
39 printf("weather successful inserted\n");
40 } else {
41 printf("E: weather insertion failed\n");
42 }
44 }
47 int main(int argc, char* argv[]) {
48 printf(" --> weather\n");
50 /* init */
51 if (argc != 2) {
52 printf("usage: %s <game>\n", argv[0]);
53 exit(1);
54 }
55 gamename = argv[1];
57 db_connect();
58 check_game();
60 set_weather();
63 db_close();
65 printf(" --< weather\n");
66 return 0;
67 }