comparison environment.c @ 18:5937504619f2

rename game.h -> modules.h; added some error handling; and more
author meillo@marmaro.de
date Wed, 23 Jul 2008 17:40:55 +0200
parents 5e6c9260913a
children
comparison
equal deleted inserted replaced
17:5e6c9260913a 18:5937504619f2
1 #include <stdio.h> 1 #include <stdio.h>
2 #include <stdlib.h> 2 #include <stdlib.h>
3 #include "db.h" 3 #include "db.h"
4 #include "game.h"
5 4
6 5
7 void set_environment() { 6 int set_environment() {
8 int groundwater, slugs, earthworms; 7 int groundwater, slugs, earthworms;
9 8
10 /* get weather and last environments to calculate the next one * 9 /* get weather and last environments to calculate the next one *
11 sprintf(query, "select time from simulation"); 10 sprintf(query, "select time from simulation");
12 db_query(query); 11 db_query(query);
20 19
21 groundwater = 20; 20 groundwater = 20;
22 slugs = 5; 21 slugs = 5;
23 earthworms = 10; 22 earthworms = 10;
24 23
25
26 /* set weather */ 24 /* set weather */
27 sprintf(query, 25 sprintf(query,
28 "insert into environment " 26 "insert into environment "
29 "(tick, groundwater, slugs, earthworms) " 27 "(tick, groundwater, slugs, earthworms) "
30 "values ('%d', '%d', '%d', '%d') " 28 "values ('%d', '%d', '%d', '%d') "
33 , slugs 31 , slugs
34 , earthworms 32 , earthworms
35 ); 33 );
36 if (!db_update(query)) { 34 if (!db_update(query)) {
37 db_error("environment insertion"); 35 db_error("environment insertion");
36 return 0;
38 } 37 }
39 38 return 1;
40 } 39 }
41 40
42 41
43 void environment(void) { 42 int environment(void) {
44 set_environment(); 43 return set_environment();
45 } 44 }