garten
view environment.c @ 8:9bd0a2100694
new weather implementation
author | meillo@marmaro.de |
---|---|
date | Mon, 26 May 2008 23:25:36 +0200 |
parents | |
children | 176ee28e7464 |
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_environment() {
12 int groundwater, slugs, earthworms;
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 */
25 groundwater = 20;
26 slugs = 5;
27 earthworms = 10;
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 }
42 }
45 int main(int argc, char* argv[]) {
46 printf(" --> environment\n");
48 /* init */
49 if (argc != 2) {
50 printf("usage: %s <game>\n", argv[0]);
51 exit(1);
52 }
53 gamename = argv[1];
55 db_connect();
56 check_game();
58 set_environment();
61 db_close();
63 printf(" --< environment\n");
64 return 0;
65 }