Mercurial > garten
view weather.c @ 5:26ca6c79fc22
added a Makefile (which needs improvement)
author | meillo@marmaro.de |
---|---|
date | Wed, 14 May 2008 21:10:45 +0200 |
parents | 0c19ad487f02 |
children | 9bd0a2100694 |
line wrap: on
line source
#include <stdio.h> #include <stdlib.h> #include <mysql.h> #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 <game>\n", argv[0]); exit(1); } gamename = argv[1]; db_connect(); check_game(); set_weather(); db_close(); printf(" --< weather\n"); return 0; }