diff growth.c @ 7:b1e309dc0b98

added growth module (quite static and limited implementation)
author meillo@marmaro.de
date Thu, 15 May 2008 21:42:01 +0200
parents
children 176ee28e7464
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/growth.c	Thu May 15 21:42:01 2008 +0200
@@ -0,0 +1,71 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <mysql.h>
+
+#include "db.h"
+#include "game.h"
+
+
+
+
+void grow_plants() {
+	int i;
+	unsigned char r[6];
+
+	/* get weather and last environments to calculate the next one */
+	sprintf(query, "select\
+			f.id, f.size, f.age, p.size, p.growspeed, p.age\
+			from field f\
+			join plant p on f.plant_id = p.id\
+			where f.game_id = '%d' ",
+			gameid);
+	db_query(query);
+	result = mysql_store_result(conn);
+	printf("number of plants to process: %d\n", (int)mysql_num_rows(result));
+	while ((row = mysql_fetch_row(result)) != NULL) {
+		for (i = 0; i < 6; i++) {
+			r[i] = atoi(row[i]);
+		}
+
+		sprintf(query, "update field set \
+				size = '%d', age = '%d' \
+				where id = '%d' ",
+				(r[1] + 1), r[2]+1, r[0]);
+		db_query(query);
+
+		if (mysql_affected_rows(conn) > 0) {
+			printf("update successful  ++  %s\n", query);
+		} else {
+			printf("E: update failed  ++  %s\n", query);
+		}
+
+	}
+	mysql_free_result(result);
+
+
+
+
+}
+
+
+int main(int argc, char* argv[]) {
+	printf("  --> %s\n", argv[0]);
+
+	/* init */
+	if (argc != 2) {
+		printf("usage: %s <game>\n", argv[0]);
+		exit(1);
+	}
+	gamename = argv[1];
+
+	db_connect();
+	check_game();
+
+	grow_plants();
+
+
+	db_close();
+
+	printf("  --< %s\n", argv[0]);
+	return 0;
+}