annotate environment.c @ 11:176ee28e7464
switched from mysql to sqlite; (+ some cleanups)
author |
meillo@marmaro.de |
date |
Wed, 23 Jul 2008 11:41:38 +0200 |
parents |
e3679f888813 |
children |
8db6497d6065 |
rev |
line source |
meillo@6
|
1 #include <stdio.h>
|
meillo@6
|
2 #include <stdlib.h>
|
meillo@6
|
3
|
meillo@6
|
4 #include "db.h"
|
meillo@6
|
5 #include "game.h"
|
meillo@6
|
6
|
meillo@6
|
7
|
meillo@6
|
8
|
meillo@6
|
9
|
meillo@6
|
10 void set_environment() {
|
meillo@6
|
11 int groundwater, slugs, earthworms;
|
meillo@6
|
12
|
meillo@6
|
13 /* get weather and last environments to calculate the next one *
|
meillo@11
|
14 sprintf(query, "select time from simulation");
|
meillo@6
|
15 db_query(query);
|
meillo@6
|
16 result = mysql_store_result(conn);
|
meillo@6
|
17 if (mysql_num_rows(result)) {
|
meillo@6
|
18 row = mysql_fetch_row(result);
|
meillo@6
|
19 time = atoi(row[0]);
|
meillo@6
|
20 }
|
meillo@6
|
21 mysql_free_result(result);
|
meillo@6
|
22 */
|
meillo@6
|
23
|
meillo@6
|
24 groundwater = 20;
|
meillo@6
|
25 slugs = 5;
|
meillo@6
|
26 earthworms = 10;
|
meillo@6
|
27
|
meillo@6
|
28
|
meillo@6
|
29 /* set weather */
|
meillo@6
|
30 sprintf(query, " insert into environment \
|
meillo@11
|
31 (tick, groundwater, slugs, earthworms) \
|
meillo@11
|
32 values ('%d', '%d', '%d', '%d') ",
|
meillo@11
|
33 gametime, groundwater, slugs, earthworms);
|
meillo@6
|
34 db_query(query);
|
meillo@11
|
35 if (sqlite3_step(stmt) == SQLITE_DONE) {
|
meillo@6
|
36 printf("environment successful inserted\n");
|
meillo@6
|
37 } else {
|
meillo@11
|
38 printf("error: environment insertion failed: %s\n", sqlite3_errmsg(db));
|
meillo@6
|
39 }
|
meillo@6
|
40
|
meillo@6
|
41 }
|
meillo@6
|
42
|
meillo@6
|
43
|
meillo@6
|
44 int main(int argc, char* argv[]) {
|
meillo@6
|
45 printf(" --> environment\n");
|
meillo@6
|
46
|
meillo@6
|
47 /* init */
|
meillo@6
|
48 if (argc != 2) {
|
meillo@11
|
49 printf("usage: %s <database>\n", argv[0]);
|
meillo@6
|
50 exit(1);
|
meillo@6
|
51 }
|
meillo@11
|
52 database = argv[1];
|
meillo@6
|
53
|
meillo@6
|
54 db_connect();
|
meillo@11
|
55 read_time();
|
meillo@6
|
56
|
meillo@6
|
57 set_environment();
|
meillo@6
|
58
|
meillo@6
|
59
|
meillo@6
|
60 db_close();
|
meillo@6
|
61
|
meillo@6
|
62 printf(" --< environment\n");
|
meillo@6
|
63 return 0;
|
meillo@6
|
64 }
|