meillo@7: #include meillo@7: #include meillo@7: #include meillo@7: meillo@7: #include "db.h" meillo@7: #include "game.h" meillo@7: meillo@7: meillo@7: meillo@7: meillo@7: void grow_plants() { meillo@7: int i; meillo@7: unsigned char r[6]; meillo@7: meillo@7: /* get weather and last environments to calculate the next one */ meillo@7: sprintf(query, "select\ meillo@7: f.id, f.size, f.age, p.size, p.growspeed, p.age\ meillo@7: from field f\ meillo@7: join plant p on f.plant_id = p.id\ meillo@7: where f.game_id = '%d' ", meillo@7: gameid); meillo@7: db_query(query); meillo@7: result = mysql_store_result(conn); meillo@7: printf("number of plants to process: %d\n", (int)mysql_num_rows(result)); meillo@7: while ((row = mysql_fetch_row(result)) != NULL) { meillo@7: for (i = 0; i < 6; i++) { meillo@7: r[i] = atoi(row[i]); meillo@7: } meillo@7: meillo@7: sprintf(query, "update field set \ meillo@7: size = '%d', age = '%d' \ meillo@7: where id = '%d' ", meillo@7: (r[1] + 1), r[2]+1, r[0]); meillo@7: db_query(query); meillo@7: meillo@7: if (mysql_affected_rows(conn) > 0) { meillo@7: printf("update successful ++ %s\n", query); meillo@7: } else { meillo@7: printf("E: update failed ++ %s\n", query); meillo@7: } meillo@7: meillo@7: } meillo@7: mysql_free_result(result); meillo@7: meillo@7: meillo@7: meillo@7: meillo@7: } meillo@7: meillo@7: meillo@7: int main(int argc, char* argv[]) { meillo@7: printf(" --> %s\n", argv[0]); meillo@7: meillo@7: /* init */ meillo@7: if (argc != 2) { meillo@7: printf("usage: %s \n", argv[0]); meillo@7: exit(1); meillo@7: } meillo@7: gamename = argv[1]; meillo@7: meillo@7: db_connect(); meillo@7: check_game(); meillo@7: meillo@7: grow_plants(); meillo@7: meillo@7: meillo@7: db_close(); meillo@7: meillo@7: printf(" --< %s\n", argv[0]); meillo@7: return 0; meillo@7: }