Mercurial > 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 wrap: on
line diff
--- 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}
--- /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 <stdio.h> +#include <stdlib.h> +#include <mysql.h> + +#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 <game>\n", argv[0]); + exit(1); + } + gamename = argv[1]; + + db_connect(); + check_game(); + + set_environment(); + + + db_close(); + + printf(" --< environment\n"); + return 0; +}