Mercurial > garten
comparison 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 |
comparison
equal
deleted
inserted
replaced
2:8369454d4ec9 | 3:0c19ad487f02 |
---|---|
1 #include <stdio.h> | |
2 #include <stdlib.h> | |
3 #include <mysql.h> | |
4 | |
5 #include "db.h" | |
6 #include "game.h" | |
7 | |
8 | |
9 | |
10 | |
11 void set_weather() { | |
12 int temperature, sun, rain, wind, humidity; | |
13 | |
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 */ | |
24 | |
25 temperature = 20; | |
26 sun = 5; | |
27 rain = 1; | |
28 wind = 10; | |
29 humidity = 40; | |
30 | |
31 | |
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 } | |
43 | |
44 } | |
45 | |
46 | |
47 int main(int argc, char* argv[]) { | |
48 printf(" --> weather\n"); | |
49 | |
50 /* init */ | |
51 if (argc != 2) { | |
52 printf("usage: %s <game>\n", argv[0]); | |
53 exit(1); | |
54 } | |
55 gamename = argv[1]; | |
56 | |
57 db_connect(); | |
58 check_game(); | |
59 | |
60 set_weather(); | |
61 | |
62 | |
63 db_close(); | |
64 | |
65 printf(" --< weather\n"); | |
66 return 0; | |
67 } |