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