garten
view growth.c @ 7:b1e309dc0b98
added growth module (quite static and limited implementation)
author | meillo@marmaro.de |
---|---|
date | Thu, 15 May 2008 21:42:01 +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 grow_plants() {
12 int i;
13 unsigned char r[6];
15 /* get weather and last environments to calculate the next one */
16 sprintf(query, "select\
17 f.id, f.size, f.age, p.size, p.growspeed, p.age\
18 from field f\
19 join plant p on f.plant_id = p.id\
20 where f.game_id = '%d' ",
21 gameid);
22 db_query(query);
23 result = mysql_store_result(conn);
24 printf("number of plants to process: %d\n", (int)mysql_num_rows(result));
25 while ((row = mysql_fetch_row(result)) != NULL) {
26 for (i = 0; i < 6; i++) {
27 r[i] = atoi(row[i]);
28 }
30 sprintf(query, "update field set \
31 size = '%d', age = '%d' \
32 where id = '%d' ",
33 (r[1] + 1), r[2]+1, r[0]);
34 db_query(query);
36 if (mysql_affected_rows(conn) > 0) {
37 printf("update successful ++ %s\n", query);
38 } else {
39 printf("E: update failed ++ %s\n", query);
40 }
42 }
43 mysql_free_result(result);
48 }
51 int main(int argc, char* argv[]) {
52 printf(" --> %s\n", argv[0]);
54 /* init */
55 if (argc != 2) {
56 printf("usage: %s <game>\n", argv[0]);
57 exit(1);
58 }
59 gamename = argv[1];
61 db_connect();
62 check_game();
64 grow_plants();
67 db_close();
69 printf(" --< %s\n", argv[0]);
70 return 0;
71 }