changeset 3:0c19ad487f02

first weather implementation (static values)
author meillo@marmaro.de
date Wed, 14 May 2008 21:09:09 +0200
parents 8369454d4ec9
children 32c4212f05d9
files weather.c
diffstat 1 files changed, 67 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /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 <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;
+}