# HG changeset patch # User meillo@marmaro.de # Date 1210880521 -7200 # Node ID b1e309dc0b981df7f56fface53565bdafe8e2827 # Parent e3679f888813b2cef712555ece3db53635482cf0 added growth module (quite static and limited implementation) diff -r e3679f888813 -r b1e309dc0b98 Makefile --- a/Makefile Wed May 14 21:59:35 2008 +0200 +++ b/Makefile Thu May 15 21:42:01 2008 +0200 @@ -49,8 +49,11 @@ bin/environment: environment.c db.h game.h $(CC) -o $@ $(LDFLAGS) `mysql_config --cflags` environment.c `mysql_config --libs` +bin/growth: growth.c db.h game.h + $(CC) -o $@ $(LDFLAGS) `mysql_config --cflags` growth.c `mysql_config --libs` -${NAME}: bin/clock bin/weather bin/environment + +${NAME}: bin/clock bin/weather bin/environment bin/growth #${OBJ}: ${DEP} diff -r e3679f888813 -r b1e309dc0b98 growth.c --- /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 +#include +#include + +#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 \n", argv[0]); + exit(1); + } + gamename = argv[1]; + + db_connect(); + check_game(); + + grow_plants(); + + + db_close(); + + printf(" --< %s\n", argv[0]); + return 0; +} diff -r e3679f888813 -r b1e309dc0b98 runtick.sh --- a/runtick.sh Wed May 14 21:59:35 2008 +0200 +++ b/runtick.sh Thu May 15 21:42:01 2008 +0200 @@ -17,7 +17,7 @@ ./bin/weather $gamename ./bin/environment $gamename #./bin/market $gamename -#./bin/growth $gamename +./bin/growth $gamename #./bin/orderexec $gamename echo "finished backend cycle at `date +%F\ %H:%M:%S`"