garten

annotate environment.c @ 9:ac67f688ed2e

switched from gamename to database for identifing we have one db per game now
author meillo@marmaro.de
date Wed, 23 Jul 2008 11:39:15 +0200
parents
children 176ee28e7464
rev   line source
meillo@6 1 #include <stdio.h>
meillo@6 2 #include <stdlib.h>
meillo@6 3 #include <mysql.h>
meillo@6 4
meillo@6 5 #include "db.h"
meillo@6 6 #include "game.h"
meillo@6 7
meillo@6 8
meillo@6 9
meillo@6 10
meillo@6 11 void set_environment() {
meillo@6 12 int groundwater, slugs, earthworms;
meillo@6 13
meillo@6 14 /* get weather and last environments to calculate the next one *
meillo@6 15 sprintf(query, "select time from simulation where name = '%s' ", gamename);
meillo@6 16 db_query(query);
meillo@6 17 result = mysql_store_result(conn);
meillo@6 18 if (mysql_num_rows(result)) {
meillo@6 19 row = mysql_fetch_row(result);
meillo@6 20 time = atoi(row[0]);
meillo@6 21 }
meillo@6 22 mysql_free_result(result);
meillo@6 23 */
meillo@6 24
meillo@6 25 groundwater = 20;
meillo@6 26 slugs = 5;
meillo@6 27 earthworms = 10;
meillo@6 28
meillo@6 29
meillo@6 30 /* set weather */
meillo@6 31 sprintf(query, " insert into environment \
meillo@6 32 (tick, game_id, groundwater, slugs, earthworms) \
meillo@6 33 values ('%d', '%d', '%d', '%d', '%d') ",
meillo@6 34 gametime, gameid, groundwater, slugs, earthworms);
meillo@6 35 db_query(query);
meillo@6 36 if (mysql_affected_rows(conn) > 0) {
meillo@6 37 printf("environment successful inserted\n");
meillo@6 38 } else {
meillo@6 39 printf("E: environment insertion failed\n");
meillo@6 40 }
meillo@6 41
meillo@6 42 }
meillo@6 43
meillo@6 44
meillo@6 45 int main(int argc, char* argv[]) {
meillo@6 46 printf(" --> environment\n");
meillo@6 47
meillo@6 48 /* init */
meillo@6 49 if (argc != 2) {
meillo@6 50 printf("usage: %s <game>\n", argv[0]);
meillo@6 51 exit(1);
meillo@6 52 }
meillo@6 53 gamename = argv[1];
meillo@6 54
meillo@6 55 db_connect();
meillo@6 56 check_game();
meillo@6 57
meillo@6 58 set_environment();
meillo@6 59
meillo@6 60
meillo@6 61 db_close();
meillo@6 62
meillo@6 63 printf(" --< environment\n");
meillo@6 64 return 0;
meillo@6 65 }