# HG changeset patch # User meillo@marmaro.de # Date 1210792149 -7200 # Node ID 0c19ad487f028b7b83d65553343d358e67e655a3 # Parent 8369454d4ec91bc1b1b25ca86b2996b12968703c first weather implementation (static values) diff -r 8369454d4ec9 -r 0c19ad487f02 weather.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/weather.c Wed May 14 21:09:09 2008 +0200 @@ -0,0 +1,67 @@ +#include +#include +#include + +#include "db.h" +#include "game.h" + + + + +void set_weather() { + int temperature, sun, rain, wind, humidity; + + /* get last weather and 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); + */ + + temperature = 20; + sun = 5; + rain = 1; + wind = 10; + humidity = 40; + + + /* set weather */ + sprintf(query, " insert into weather \ + (tick, game_id, temperature, sun, rain, wind, humidity) \ + values ('%d', '%d', '%d', '%d', '%d', '%d', '%d') ", + gametime, gameid, temperature, sun, rain, wind, humidity); + db_query(query); + if (mysql_affected_rows(conn) > 0) { + printf("weather successful inserted\n"); + } else { + printf("E: weather insertion failed\n"); + } + +} + + +int main(int argc, char* argv[]) { + printf(" --> weather\n"); + + /* init */ + if (argc != 2) { + printf("usage: %s \n", argv[0]); + exit(1); + } + gamename = argv[1]; + + db_connect(); + check_game(); + + set_weather(); + + + db_close(); + + printf(" --< weather\n"); + return 0; +}