garten
diff weather.c @ 3:0c19ad487f02
first weather implementation (static values)
author | meillo@marmaro.de |
---|---|
date | Wed, 14 May 2008 21:09:09 +0200 |
parents | |
children | 9bd0a2100694 |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/weather.c Wed May 14 21:09:09 2008 +0200 1.3 @@ -0,0 +1,67 @@ 1.4 +#include <stdio.h> 1.5 +#include <stdlib.h> 1.6 +#include <mysql.h> 1.7 + 1.8 +#include "db.h" 1.9 +#include "game.h" 1.10 + 1.11 + 1.12 + 1.13 + 1.14 +void set_weather() { 1.15 + int temperature, sun, rain, wind, humidity; 1.16 + 1.17 + /* get last weather and calculate the next one * 1.18 + sprintf(query, "select time from simulation where name = '%s' ", gamename); 1.19 + db_query(query); 1.20 + result = mysql_store_result(conn); 1.21 + if (mysql_num_rows(result)) { 1.22 + row = mysql_fetch_row(result); 1.23 + time = atoi(row[0]); 1.24 + } 1.25 + mysql_free_result(result); 1.26 + */ 1.27 + 1.28 + temperature = 20; 1.29 + sun = 5; 1.30 + rain = 1; 1.31 + wind = 10; 1.32 + humidity = 40; 1.33 + 1.34 + 1.35 + /* set weather */ 1.36 + sprintf(query, " insert into weather \ 1.37 + (tick, game_id, temperature, sun, rain, wind, humidity) \ 1.38 + values ('%d', '%d', '%d', '%d', '%d', '%d', '%d') ", 1.39 + gametime, gameid, temperature, sun, rain, wind, humidity); 1.40 + db_query(query); 1.41 + if (mysql_affected_rows(conn) > 0) { 1.42 + printf("weather successful inserted\n"); 1.43 + } else { 1.44 + printf("E: weather insertion failed\n"); 1.45 + } 1.46 + 1.47 +} 1.48 + 1.49 + 1.50 +int main(int argc, char* argv[]) { 1.51 + printf(" --> weather\n"); 1.52 + 1.53 + /* init */ 1.54 + if (argc != 2) { 1.55 + printf("usage: %s <game>\n", argv[0]); 1.56 + exit(1); 1.57 + } 1.58 + gamename = argv[1]; 1.59 + 1.60 + db_connect(); 1.61 + check_game(); 1.62 + 1.63 + set_weather(); 1.64 + 1.65 + 1.66 + db_close(); 1.67 + 1.68 + printf(" --< weather\n"); 1.69 + return 0; 1.70 +}