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@11: join plant p on f.plant_id = p.id "); meillo@7: db_query(query); meillo@11: /* printf("number of plants to process: %d\n", (int)mysql_num_rows(result)); */ meillo@11: while (sqlite3_step(stmt) == SQLITE_ROW) { meillo@7: for (i = 0; i < 6; i++) { meillo@11: r[i] = (char) sqlite3_column_int(stmt, 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@11: ; meillo@7: meillo@11: if (sqlite3_step(stmt) == SQLITE_DONE) { meillo@7: printf("update successful ++ %s\n", query); meillo@7: } else { meillo@11: printf("E: update failed ++ %s\n", sqlite3_errmsg(db)); meillo@7: } meillo@7: meillo@7: } meillo@11: sqlite3_finalize(stmt); 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@11: printf("usage: %s \n", argv[0]); meillo@7: exit(1); meillo@7: } meillo@11: database = argv[1]; meillo@7: meillo@7: db_connect(); meillo@11: read_time(); 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: }