# HG changeset patch # User meillo@marmaro.de # Date 1210795175 -7200 # Node ID e3679f888813b2cef712555ece3db53635482cf0 # Parent 26ca6c79fc22138c4d48cbdbb3576099a97bbb04 added environment module (only static code) diff -r 26ca6c79fc22 -r e3679f888813 Makefile --- a/Makefile Wed May 14 21:10:45 2008 +0200 +++ b/Makefile Wed May 14 21:59:35 2008 +0200 @@ -46,8 +46,11 @@ bin/weather: weather.c db.h game.h $(CC) -o $@ $(LDFLAGS) `mysql_config --cflags` weather.c `mysql_config --libs` +bin/environment: environment.c db.h game.h + $(CC) -o $@ $(LDFLAGS) `mysql_config --cflags` environment.c `mysql_config --libs` -${NAME}: bin/clock bin/weather + +${NAME}: bin/clock bin/weather bin/environment #${OBJ}: ${DEP} diff -r 26ca6c79fc22 -r e3679f888813 environment.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/environment.c Wed May 14 21:59:35 2008 +0200 @@ -0,0 +1,65 @@ +#include +#include +#include + +#include "db.h" +#include "game.h" + + + + +void set_environment() { + int groundwater, slugs, earthworms; + + /* get weather and last environments to calculate the next one * + sprintf(query, "select time from simulation where name = '%s' ", gamename); + db_query(query); + result = mysql_store_result(conn); + if (mysql_num_rows(result)) { + row = mysql_fetch_row(result); + time = atoi(row[0]); + } + mysql_free_result(result); + */ + + groundwater = 20; + slugs = 5; + earthworms = 10; + + + /* set weather */ + sprintf(query, " insert into environment \ + (tick, game_id, groundwater, slugs, earthworms) \ + values ('%d', '%d', '%d', '%d', '%d') ", + gametime, gameid, groundwater, slugs, earthworms); + db_query(query); + if (mysql_affected_rows(conn) > 0) { + printf("environment successful inserted\n"); + } else { + printf("E: environment insertion failed\n"); + } + +} + + +int main(int argc, char* argv[]) { + printf(" --> environment\n"); + + /* init */ + if (argc != 2) { + printf("usage: %s \n", argv[0]); + exit(1); + } + gamename = argv[1]; + + db_connect(); + check_game(); + + set_environment(); + + + db_close(); + + printf(" --< environment\n"); + return 0; +} diff -r 26ca6c79fc22 -r e3679f888813 runtick.sh --- a/runtick.sh Wed May 14 21:10:45 2008 +0200 +++ b/runtick.sh Wed May 14 21:59:35 2008 +0200 @@ -15,7 +15,7 @@ ./bin/clock $gamename ./bin/weather $gamename -#./bin/environmant $gamename +./bin/environment $gamename #./bin/market $gamename #./bin/growth $gamename #./bin/orderexec $gamename