annotate environment.c @ 17:5e6c9260913a

lots of cleanups and small fixes
author meillo@marmaro.de
date Wed, 23 Jul 2008 17:14:38 +0200
parents 8db6497d6065
children 5937504619f2
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 #include "game.h"
e3679f888813 added environment module (only static code)
meillo@marmaro.de
parents:
diff changeset
5
e3679f888813 added environment module (only static code)
meillo@marmaro.de
parents:
diff changeset
6
e3679f888813 added environment module (only static code)
meillo@marmaro.de
parents:
diff changeset
7 void set_environment() {
e3679f888813 added environment module (only static code)
meillo@marmaro.de
parents:
diff changeset
8 int groundwater, slugs, earthworms;
e3679f888813 added environment module (only static code)
meillo@marmaro.de
parents:
diff changeset
9
e3679f888813 added environment module (only static code)
meillo@marmaro.de
parents:
diff changeset
10 /* 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
11 sprintf(query, "select time from simulation");
6
e3679f888813 added environment module (only static code)
meillo@marmaro.de
parents:
diff changeset
12 db_query(query);
e3679f888813 added environment module (only static code)
meillo@marmaro.de
parents:
diff changeset
13 result = mysql_store_result(conn);
e3679f888813 added environment module (only static code)
meillo@marmaro.de
parents:
diff changeset
14 if (mysql_num_rows(result)) {
e3679f888813 added environment module (only static code)
meillo@marmaro.de
parents:
diff changeset
15 row = mysql_fetch_row(result);
e3679f888813 added environment module (only static code)
meillo@marmaro.de
parents:
diff changeset
16 time = atoi(row[0]);
e3679f888813 added environment module (only static code)
meillo@marmaro.de
parents:
diff changeset
17 }
e3679f888813 added environment module (only static code)
meillo@marmaro.de
parents:
diff changeset
18 mysql_free_result(result);
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
e3679f888813 added environment module (only static code)
meillo@marmaro.de
parents:
diff changeset
21 groundwater = 20;
e3679f888813 added environment module (only static code)
meillo@marmaro.de
parents:
diff changeset
22 slugs = 5;
e3679f888813 added environment module (only static code)
meillo@marmaro.de
parents:
diff changeset
23 earthworms = 10;
e3679f888813 added environment module (only static code)
meillo@marmaro.de
parents:
diff changeset
24
e3679f888813 added environment module (only static code)
meillo@marmaro.de
parents:
diff changeset
25
e3679f888813 added environment module (only static code)
meillo@marmaro.de
parents:
diff changeset
26 /* set weather */
17
5e6c9260913a lots of cleanups and small fixes
meillo@marmaro.de
parents: 12
diff changeset
27 sprintf(query,
5e6c9260913a lots of cleanups and small fixes
meillo@marmaro.de
parents: 12
diff changeset
28 "insert into environment "
5e6c9260913a lots of cleanups and small fixes
meillo@marmaro.de
parents: 12
diff changeset
29 "(tick, groundwater, slugs, earthworms) "
5e6c9260913a lots of cleanups and small fixes
meillo@marmaro.de
parents: 12
diff changeset
30 "values ('%d', '%d', '%d', '%d') "
5e6c9260913a lots of cleanups and small fixes
meillo@marmaro.de
parents: 12
diff changeset
31 , gametime
5e6c9260913a lots of cleanups and small fixes
meillo@marmaro.de
parents: 12
diff changeset
32 , groundwater
5e6c9260913a lots of cleanups and small fixes
meillo@marmaro.de
parents: 12
diff changeset
33 , slugs
5e6c9260913a lots of cleanups and small fixes
meillo@marmaro.de
parents: 12
diff changeset
34 , earthworms
5e6c9260913a lots of cleanups and small fixes
meillo@marmaro.de
parents: 12
diff changeset
35 );
12
8db6497d6065 merged everything to only one program
meillo@marmaro.de
parents: 11
diff changeset
36 if (!db_update(query)) {
17
5e6c9260913a lots of cleanups and small fixes
meillo@marmaro.de
parents: 12
diff changeset
37 db_error("environment insertion");
6
e3679f888813 added environment module (only static code)
meillo@marmaro.de
parents:
diff changeset
38 }
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
e3679f888813 added environment module (only static code)
meillo@marmaro.de
parents:
diff changeset
42
12
8db6497d6065 merged everything to only one program
meillo@marmaro.de
parents: 11
diff changeset
43 void environment(void) {
6
e3679f888813 added environment module (only static code)
meillo@marmaro.de
parents:
diff changeset
44 set_environment();
e3679f888813 added environment module (only static code)
meillo@marmaro.de
parents:
diff changeset
45 }