garten

diff growth.c @ 12:8db6497d6065

merged everything to only one program
author meillo@marmaro.de
date Wed, 23 Jul 2008 15:19:45 +0200
parents 176ee28e7464
children 5e6c9260913a
line diff
     1.1 --- a/growth.c	Wed Jul 23 11:41:38 2008 +0200
     1.2 +++ b/growth.c	Wed Jul 23 15:19:45 2008 +0200
     1.3 @@ -1,68 +1,21 @@
     1.4  #include <stdio.h>
     1.5  #include <stdlib.h>
     1.6 -
     1.7  #include "db.h"
     1.8  #include "game.h"
     1.9  
    1.10  
    1.11 -
    1.12 -
    1.13  void grow_plants() {
    1.14 -	int i;
    1.15 -	unsigned char r[6];
    1.16 -
    1.17  	/* get weather and last environments to calculate the next one */
    1.18 -	sprintf(query, "select\
    1.19 -			f.id, f.size, f.age, p.size, p.growspeed, p.age\
    1.20 -			from field f\
    1.21 -			join plant p on f.plant_id = p.id ");
    1.22 -	db_query(query);
    1.23 -	/* printf("number of plants to process: %d\n", (int)mysql_num_rows(result)); */
    1.24 -	while (sqlite3_step(stmt) == SQLITE_ROW) {
    1.25 -		for (i = 0; i < 6; i++) {
    1.26 -			r[i] = (char) sqlite3_column_int(stmt, i);
    1.27 -		}
    1.28 -
    1.29 -		sprintf(query, "update field set \
    1.30 -				size = '%d', age = '%d' \
    1.31 -				where id = '%d' ",
    1.32 -				(r[1] + 1), r[2]+1, r[0]);
    1.33 -		db_query(query);
    1.34 -		;
    1.35 -
    1.36 -		if (sqlite3_step(stmt) == SQLITE_DONE) {
    1.37 -			printf("update successful  ++  %s\n", query);
    1.38 -		} else {
    1.39 -			printf("E: update failed  ++  %s\n", sqlite3_errmsg(db));
    1.40 -		}
    1.41 -
    1.42 +	sprintf(query, "update field \
    1.43 +			set age = age+1, size = size+1 ");
    1.44 +	stmt = db_query(query);
    1.45 +	if (!db_update(query)) {
    1.46 +		printf("E: update failed  ++  %s\n", sqlite3_errmsg(db));
    1.47  	}
    1.48  	sqlite3_finalize(stmt);
    1.49 -
    1.50 -
    1.51 -
    1.52 -
    1.53  }
    1.54  
    1.55  
    1.56 -int main(int argc, char* argv[]) {
    1.57 -	printf("  --> %s\n", argv[0]);
    1.58 -
    1.59 -	/* init */
    1.60 -	if (argc != 2) {
    1.61 -		printf("usage: %s <database>\n", argv[0]);
    1.62 -		exit(1);
    1.63 -	}
    1.64 -	database = argv[1];
    1.65 -
    1.66 -	db_connect();
    1.67 -	read_time();
    1.68 -
    1.69 +void growth(void) {
    1.70  	grow_plants();
    1.71 -
    1.72 -
    1.73 -	db_close();
    1.74 -
    1.75 -	printf("  --< %s\n", argv[0]);
    1.76 -	return 0;
    1.77  }