garten
changeset 6:e3679f888813
added environment module (only static code)
author | meillo@marmaro.de |
---|---|
date | Wed, 14 May 2008 21:59:35 +0200 |
parents | 26ca6c79fc22 |
children | b1e309dc0b98 |
files | Makefile environment.c runtick.sh |
diffstat | 3 files changed, 70 insertions(+), 2 deletions(-) [+] |
line diff
1.1 --- a/Makefile Wed May 14 21:10:45 2008 +0200 1.2 +++ b/Makefile Wed May 14 21:59:35 2008 +0200 1.3 @@ -46,8 +46,11 @@ 1.4 bin/weather: weather.c db.h game.h 1.5 $(CC) -o $@ $(LDFLAGS) `mysql_config --cflags` weather.c `mysql_config --libs` 1.6 1.7 +bin/environment: environment.c db.h game.h 1.8 + $(CC) -o $@ $(LDFLAGS) `mysql_config --cflags` environment.c `mysql_config --libs` 1.9 1.10 -${NAME}: bin/clock bin/weather 1.11 + 1.12 +${NAME}: bin/clock bin/weather bin/environment 1.13 1.14 1.15 #${OBJ}: ${DEP}
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/environment.c Wed May 14 21:59:35 2008 +0200 2.3 @@ -0,0 +1,65 @@ 2.4 +#include <stdio.h> 2.5 +#include <stdlib.h> 2.6 +#include <mysql.h> 2.7 + 2.8 +#include "db.h" 2.9 +#include "game.h" 2.10 + 2.11 + 2.12 + 2.13 + 2.14 +void set_environment() { 2.15 + int groundwater, slugs, earthworms; 2.16 + 2.17 + /* get weather and last environments to calculate the next one * 2.18 + sprintf(query, "select time from simulation where name = '%s' ", gamename); 2.19 + db_query(query); 2.20 + result = mysql_store_result(conn); 2.21 + if (mysql_num_rows(result)) { 2.22 + row = mysql_fetch_row(result); 2.23 + time = atoi(row[0]); 2.24 + } 2.25 + mysql_free_result(result); 2.26 + */ 2.27 + 2.28 + groundwater = 20; 2.29 + slugs = 5; 2.30 + earthworms = 10; 2.31 + 2.32 + 2.33 + /* set weather */ 2.34 + sprintf(query, " insert into environment \ 2.35 + (tick, game_id, groundwater, slugs, earthworms) \ 2.36 + values ('%d', '%d', '%d', '%d', '%d') ", 2.37 + gametime, gameid, groundwater, slugs, earthworms); 2.38 + db_query(query); 2.39 + if (mysql_affected_rows(conn) > 0) { 2.40 + printf("environment successful inserted\n"); 2.41 + } else { 2.42 + printf("E: environment insertion failed\n"); 2.43 + } 2.44 + 2.45 +} 2.46 + 2.47 + 2.48 +int main(int argc, char* argv[]) { 2.49 + printf(" --> environment\n"); 2.50 + 2.51 + /* init */ 2.52 + if (argc != 2) { 2.53 + printf("usage: %s <game>\n", argv[0]); 2.54 + exit(1); 2.55 + } 2.56 + gamename = argv[1]; 2.57 + 2.58 + db_connect(); 2.59 + check_game(); 2.60 + 2.61 + set_environment(); 2.62 + 2.63 + 2.64 + db_close(); 2.65 + 2.66 + printf(" --< environment\n"); 2.67 + return 0; 2.68 +}
3.1 --- a/runtick.sh Wed May 14 21:10:45 2008 +0200 3.2 +++ b/runtick.sh Wed May 14 21:59:35 2008 +0200 3.3 @@ -15,7 +15,7 @@ 3.4 3.5 ./bin/clock $gamename 3.6 ./bin/weather $gamename 3.7 -#./bin/environmant $gamename 3.8 +./bin/environment $gamename 3.9 #./bin/market $gamename 3.10 #./bin/growth $gamename 3.11 #./bin/orderexec $gamename