annotate environment.c @ 20:17b2bcc42d72 default tip

added check for empty result; minor stuff
author meillo@marmaro.de
date Sun, 27 Jul 2008 21:34:54 +0200
parents 5937504619f2
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
e3679f888813 added environment module (only static code)
meillo@marmaro.de
parents:
diff changeset
1 #include <stdio.h>
e3679f888813 added environment module (only static code)
meillo@marmaro.de
parents:
diff changeset
2 #include <stdlib.h>
e3679f888813 added environment module (only static code)
meillo@marmaro.de
parents:
diff changeset
3 #include "db.h"
e3679f888813 added environment module (only static code)
meillo@marmaro.de
parents:
diff changeset
4
e3679f888813 added environment module (only static code)
meillo@marmaro.de
parents:
diff changeset
5
18
5937504619f2 rename game.h -> modules.h; added some error handling; and more
meillo@marmaro.de
parents: 17
diff changeset
6 int set_environment() {
6
e3679f888813 added environment module (only static code)
meillo@marmaro.de
parents:
diff changeset
7 int groundwater, slugs, earthworms;
e3679f888813 added environment module (only static code)
meillo@marmaro.de
parents:
diff changeset
8
e3679f888813 added environment module (only static code)
meillo@marmaro.de
parents:
diff changeset
9 /* get weather and last environments to calculate the next one *
11
176ee28e7464 switched from mysql to sqlite; (+ some cleanups)
meillo@marmaro.de
parents: 6
diff changeset
10 sprintf(query, "select time from simulation");
6
e3679f888813 added environment module (only static code)
meillo@marmaro.de
parents:
diff changeset
11 db_query(query);
e3679f888813 added environment module (only static code)
meillo@marmaro.de
parents:
diff changeset
12 result = mysql_store_result(conn);
e3679f888813 added environment module (only static code)
meillo@marmaro.de
parents:
diff changeset
13 if (mysql_num_rows(result)) {
e3679f888813 added environment module (only static code)
meillo@marmaro.de
parents:
diff changeset
14 row = mysql_fetch_row(result);
e3679f888813 added environment module (only static code)
meillo@marmaro.de
parents:
diff changeset
15 time = atoi(row[0]);
e3679f888813 added environment module (only static code)
meillo@marmaro.de
parents:
diff changeset
16 }
e3679f888813 added environment module (only static code)
meillo@marmaro.de
parents:
diff changeset
17 mysql_free_result(result);
e3679f888813 added environment module (only static code)
meillo@marmaro.de
parents:
diff changeset
18 */
e3679f888813 added environment module (only static code)
meillo@marmaro.de
parents:
diff changeset
19
e3679f888813 added environment module (only static code)
meillo@marmaro.de
parents:
diff changeset
20 groundwater = 20;
e3679f888813 added environment module (only static code)
meillo@marmaro.de
parents:
diff changeset
21 slugs = 5;
e3679f888813 added environment module (only static code)
meillo@marmaro.de
parents:
diff changeset
22 earthworms = 10;
e3679f888813 added environment module (only static code)
meillo@marmaro.de
parents:
diff changeset
23
e3679f888813 added environment module (only static code)
meillo@marmaro.de
parents:
diff changeset
24 /* set weather */
17
5e6c9260913a lots of cleanups and small fixes
meillo@marmaro.de
parents: 12
diff changeset
25 sprintf(query,
5e6c9260913a lots of cleanups and small fixes
meillo@marmaro.de
parents: 12
diff changeset
26 "insert into environment "
5e6c9260913a lots of cleanups and small fixes
meillo@marmaro.de
parents: 12
diff changeset
27 "(tick, groundwater, slugs, earthworms) "
5e6c9260913a lots of cleanups and small fixes
meillo@marmaro.de
parents: 12
diff changeset
28 "values ('%d', '%d', '%d', '%d') "
5e6c9260913a lots of cleanups and small fixes
meillo@marmaro.de
parents: 12
diff changeset
29 , gametime
5e6c9260913a lots of cleanups and small fixes
meillo@marmaro.de
parents: 12
diff changeset
30 , groundwater
5e6c9260913a lots of cleanups and small fixes
meillo@marmaro.de
parents: 12
diff changeset
31 , slugs
5e6c9260913a lots of cleanups and small fixes
meillo@marmaro.de
parents: 12
diff changeset
32 , earthworms
5e6c9260913a lots of cleanups and small fixes
meillo@marmaro.de
parents: 12
diff changeset
33 );
12
8db6497d6065 merged everything to only one program
meillo@marmaro.de
parents: 11
diff changeset
34 if (!db_update(query)) {
17
5e6c9260913a lots of cleanups and small fixes
meillo@marmaro.de
parents: 12
diff changeset
35 db_error("environment insertion");
18
5937504619f2 rename game.h -> modules.h; added some error handling; and more
meillo@marmaro.de
parents: 17
diff changeset
36 return 0;
6
e3679f888813 added environment module (only static code)
meillo@marmaro.de
parents:
diff changeset
37 }
18
5937504619f2 rename game.h -> modules.h; added some error handling; and more
meillo@marmaro.de
parents: 17
diff changeset
38 return 1;
6
e3679f888813 added environment module (only static code)
meillo@marmaro.de
parents:
diff changeset
39 }
e3679f888813 added environment module (only static code)
meillo@marmaro.de
parents:
diff changeset
40
e3679f888813 added environment module (only static code)
meillo@marmaro.de
parents:
diff changeset
41
18
5937504619f2 rename game.h -> modules.h; added some error handling; and more
meillo@marmaro.de
parents: 17
diff changeset
42 int environment(void) {
5937504619f2 rename game.h -> modules.h; added some error handling; and more
meillo@marmaro.de
parents: 17
diff changeset
43 return set_environment();
6
e3679f888813 added environment module (only static code)
meillo@marmaro.de
parents:
diff changeset
44 }