garten

diff environment.c @ 6:e3679f888813

added environment module (only static code)
author meillo@marmaro.de
date Wed, 14 May 2008 21:59:35 +0200
parents
children 176ee28e7464
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/environment.c	Wed May 14 21:59:35 2008 +0200
     1.3 @@ -0,0 +1,65 @@
     1.4 +#include <stdio.h>
     1.5 +#include <stdlib.h>
     1.6 +#include <mysql.h>
     1.7 +
     1.8 +#include "db.h"
     1.9 +#include "game.h"
    1.10 +
    1.11 +
    1.12 +
    1.13 +
    1.14 +void set_environment() {
    1.15 +	int groundwater, slugs, earthworms;
    1.16 +
    1.17 +	/* get weather and last environments to calculate the next one *
    1.18 +	sprintf(query, "select time from simulation where name = '%s' ", gamename);
    1.19 +	db_query(query);
    1.20 +	result = mysql_store_result(conn);
    1.21 +	if (mysql_num_rows(result)) {
    1.22 +		row = mysql_fetch_row(result);
    1.23 +		time = atoi(row[0]);
    1.24 +	}
    1.25 +	mysql_free_result(result);
    1.26 +	*/
    1.27 +
    1.28 +	groundwater = 20;
    1.29 +	slugs = 5;
    1.30 +	earthworms = 10;
    1.31 +
    1.32 +
    1.33 +	/* set weather */
    1.34 +	sprintf(query, " insert into environment \
    1.35 +			(tick, game_id, groundwater, slugs, earthworms) \
    1.36 +			values ('%d', '%d', '%d', '%d', '%d') ",
    1.37 +			gametime, gameid, groundwater, slugs, earthworms);
    1.38 +	db_query(query);
    1.39 +	if (mysql_affected_rows(conn) > 0) {
    1.40 +		printf("environment successful inserted\n");
    1.41 +	} else {
    1.42 +		printf("E: environment insertion failed\n");
    1.43 +	}
    1.44 +
    1.45 +}
    1.46 +
    1.47 +
    1.48 +int main(int argc, char* argv[]) {
    1.49 +	printf("  --> environment\n");
    1.50 +
    1.51 +	/* init */
    1.52 +	if (argc != 2) {
    1.53 +		printf("usage: %s <game>\n", argv[0]);
    1.54 +		exit(1);
    1.55 +	}
    1.56 +	gamename = argv[1];
    1.57 +
    1.58 +	db_connect();
    1.59 +	check_game();
    1.60 +
    1.61 +	set_environment();
    1.62 +
    1.63 +
    1.64 +	db_close();
    1.65 +
    1.66 +	printf("  --< environment\n");
    1.67 +	return 0;
    1.68 +}