Mercurial > garten
comparison environment.c @ 6:e3679f888813
added environment module (only static code)
author | meillo@marmaro.de |
---|---|
date | Wed, 14 May 2008 21:59:35 +0200 |
parents | |
children | 176ee28e7464 |
comparison
equal
deleted
inserted
replaced
5:26ca6c79fc22 | 6:e3679f888813 |
---|---|
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_environment() { | |
12 int groundwater, slugs, earthworms; | |
13 | |
14 /* get weather and last environments to 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 groundwater = 20; | |
26 slugs = 5; | |
27 earthworms = 10; | |
28 | |
29 | |
30 /* set weather */ | |
31 sprintf(query, " insert into environment \ | |
32 (tick, game_id, groundwater, slugs, earthworms) \ | |
33 values ('%d', '%d', '%d', '%d', '%d') ", | |
34 gametime, gameid, groundwater, slugs, earthworms); | |
35 db_query(query); | |
36 if (mysql_affected_rows(conn) > 0) { | |
37 printf("environment successful inserted\n"); | |
38 } else { | |
39 printf("E: environment insertion failed\n"); | |
40 } | |
41 | |
42 } | |
43 | |
44 | |
45 int main(int argc, char* argv[]) { | |
46 printf(" --> environment\n"); | |
47 | |
48 /* init */ | |
49 if (argc != 2) { | |
50 printf("usage: %s <game>\n", argv[0]); | |
51 exit(1); | |
52 } | |
53 gamename = argv[1]; | |
54 | |
55 db_connect(); | |
56 check_game(); | |
57 | |
58 set_environment(); | |
59 | |
60 | |
61 db_close(); | |
62 | |
63 printf(" --< environment\n"); | |
64 return 0; | |
65 } |