Mercurial > garten
diff environment.c @ 6:e3679f888813
added environment module (only static code)
author | meillo@marmaro.de |
---|---|
date | Wed, 14 May 2008 21:59:35 +0200 |
parents | |
children | 176ee28e7464 |
line wrap: on
line diff
--- /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; +}