10 #include "gb/files_shl.h" 26 #include "gb/files_rw.h" 30 #include "gb/tweakables.h" 43 const char *tbl_create = R"(
44 CREATE TABLE tbl_planet(
45 planet_id INT PRIMARY KEY NOT NULL, star_id INT NOT NULL,
46 planet_order INT NOT NULL, name TEXT NOT NULL, xpos DOUBLE,
47 ypos DOUBLE, ships INT64, Maxx INT, Maxy INT, popn INT64,
48 troops INT64, maxpopn INT64, total_resources INT64, slaved_to INT,
49 type INT, expltimer INT, condition_rtemp INT, condition_temp INT,
50 condition_methane INT, condition_oxygen INT, condition_co2 INT,
51 condition_hydrogen INT, condition_nitrogen INT, condition_sulfur INT,
52 condition_helium INT, condition_other INT, condition_toxic INT,
55 CREATE INDEX star_planet ON tbl_planet (star_id, planet_order);
58 tbl_sector(planet_id INT NOT NULL, xpos INT NOT NULL, ypos INT NOT NULL,
59 eff INT, fert INT, mobilization INT, crystals INT, resource INT,
60 popn INT64, troops INT64, owner INT, race INT, type INT,
61 condition INT, PRIMARY KEY(planet_id, xpos, ypos));
63 CREATE TABLE tbl_plinfo(
64 planet_id INT PRIMARY KEY NOT NULL, player_id INT NOT NULL, fuel INT,
65 destruct INT, resource INT, popn INT64, troops INT64, crystals INT,
66 prod_res INT, prod_fuel INT, prod_dest INT, prod_crystals INT,
67 prod_money INT64, prod_tech DOUBLE, tech_invest INT, numsectsowned INT,
68 comread INT, mob_set INT, tox_thresh INT, explored INT, autorep INT,
69 tax INT, newtax INT, guns INT, mob_points INT64, est_production DOUBLE);
71 CREATE TABLE tbl_plinfo_routes(planet_id INT PRIMARY KEY NOT NULL,
72 player_id INT, routenum INT,
73 order_set INT, dest_star INT, dest_planet INT,
74 load INT, unload INT, x INT, y INT);
76 CREATE TABLE tbl_star(star_id INT NOT NULL PRIMARY KEY, ships INT, name TEXT,
77 xpos DOUBLE, ypos DOUBLE, numplanets INT, stability INT,
78 nova_stage INT, temperature INT, gravity DOUBLE);
80 CREATE TABLE tbl_star_governor(star_id INT NOT NULL, player_id INT NOT NULL,
81 governor_id INT NOT NULL,
82 PRIMARY KEY(star_id, player_id));
85 tbl_star_explored(star_id INT NOT NULL, player_id INT NOT NULL, explored INT,
86 PRIMARY KEY(star_id, player_id));
89 tbl_star_inhabited(star_id INT NOT NULL, player_id INT NOT NULL, explored INT,
90 PRIMARY KEY(star_id, player_id));
92 CREATE TABLE tbl_star_playerap(star_id INT NOT NULL, player_id INT NOT NULL,
94 PRIMARY KEY(star_id, player_id));
96 CREATE TABLE tbl_stardata(indexnum INT PRIMARY KEY NOT NULL, ships INT);
98 CREATE TABLE tbl_stardata_perplayer(
99 player_id INT PRIMARY KEY NOT NULL, ap INT NOT NULL,
100 VN_hitlist INT NOT NULL, VN_index1 INT NOT NULL, VN_index2 INT NOT NULL);
102 CREATE TABLE tbl_ship(
103 ship_id INT PRIMARY KEY NOT NULL,
104 player_id INT NOT NULL,
105 governor_id INT NOT NULL,
107 shipclass TEXT NOT NULL,
109 xpos DOUBLE NOT NULL,
110 ypos DOUBLE NOT NULL,
111 mass DOUBLE NOT NULL,
164 transport_target INT,
173 navigate_bearing INT,
175 protect_maxrng DOUBLE,
182 hyper_drive_charge INT,
183 hyper_drive_ready INT,
231 char *err_msg =
nullptr;
232 int err = sqlite3_exec(
dbconn, tbl_create,
nullptr,
nullptr, &err_msg);
233 if (err != SQLITE_OK) {
234 fprintf(stderr,
"SQL error: %s\n", err_msg);
235 sqlite3_free(err_msg);
241 if ((*fd = open(
STARDATAFL, O_RDWR | O_CREAT, 0777)) < 0) {
242 perror(
"openstardata");
249 if ((*fd = open(
SHIPDATAFL, O_RDWR | O_CREAT, 0777)) < 0) {
250 perror(
"openshdata");
257 if ((*fd = open(
COMMODDATAFL, O_RDWR | O_CREAT, 0777)) < 0) {
258 perror(
"opencommoddata");
265 if ((*fd = open(
RACEDATAFL, O_RDWR | O_CREAT, 0777)) < 0) {
273 Fileread(
stdata, (
char *)S,
sizeof(
struct stardata), 0);
277 *r = (Race *)malloc(
sizeof(Race));
278 Fileread(
racedata, (
char *)*r,
sizeof(Race), (rnum - 1) *
sizeof(Race));
282 if (s >= &Stars[0] && s < &Stars[
NUMSTARS])
285 *s = (startype *)malloc(
sizeof(startype));
287 memset(*s, 0,
sizeof(startype));
288 Fileread(
stdata, (
char *)*s,
sizeof(startype),
289 (
int)(
sizeof(Sdata) + star *
sizeof(startype)));
295 "SELECT ships, name, xpos, ypos, " 296 "numplanets, stability, nova_stage, temperature, gravity " 297 "FROM tbl_star WHERE star_id=?1 LIMIT 1";
298 sqlite3_prepare_v2(
dbconn, sql, -1, &stmt, &tail);
300 sqlite3_bind_int(stmt, 1, star);
302 (*s)->ships =
static_cast<
short>(sqlite3_column_int(stmt, 0));
304 reinterpret_cast<
const char *>(sqlite3_column_text(stmt, 1)));
305 (*s)->xpos = sqlite3_column_double(stmt, 2);
306 (*s)->ypos = sqlite3_column_double(stmt, 3);
307 (*s)->numplanets =
static_cast<
short>(sqlite3_column_int(stmt, 4));
308 (*s)->stability =
static_cast<
short>(sqlite3_column_int(stmt, 5));
309 (*s)->nova_stage =
static_cast<
short>(sqlite3_column_int(stmt, 6));
310 (*s)->temperature =
static_cast<
short>(sqlite3_column_int(stmt, 7));
311 (*s)->gravity = sqlite3_column_double(stmt, 8);
313 sqlite3_clear_bindings(stmt);
319 "SELECT player_id, governor_id FROM tbl_star_governor " 321 sqlite3_prepare_v2(
dbconn, sql, -1, &stmt, &tail);
323 sqlite3_bind_int(stmt, 1, star);
325 while (sqlite3_step(stmt) == SQLITE_ROW) {
326 player_t p = sqlite3_column_int(stmt, 0);
327 (*s)->governor[p - 1] = sqlite3_column_int(stmt, 1);
330 sqlite3_clear_bindings(stmt);
335 Planet
getplanet(
const starnum_t star,
const planetnum_t pnum) {
337 const char *plinfo_tail;
338 const char *plinfo_routes_tail;
340 sqlite3_stmt *plinfo_stmt;
341 sqlite3_stmt *plinfo_routes_stmt;
343 "SELECT planet_id, star_id, planet_order, name, " 344 "xpos, ypos, ships, maxx, maxy, popn, troops, maxpopn, total_resources, " 345 "slaved_to, type, expltimer, condition_rtemp, condition_temp, " 346 "condition_methane, condition_oxygen, condition_co2, " 347 "condition_hydrogen, condition_nitrogen, condition_sulfur, " 348 "condition_helium, condition_other, condition_toxic, " 349 "explored FROM tbl_planet WHERE star_id=?1 AND planet_order=?2";
350 sqlite3_prepare_v2(
dbconn, sql, -1, &stmt, &tail);
352 sqlite3_bind_int(stmt, 1, star);
353 sqlite3_bind_int(stmt, 2, pnum);
355 auto result = sqlite3_step(stmt);
356 if (result != SQLITE_ROW) {
357 throw std::runtime_error(
"Database unable to return the requested planet");
361 p.planet_id = sqlite3_column_int(stmt, 0);
362 p.xpos = sqlite3_column_double(stmt, 4);
363 p.ypos = sqlite3_column_double(stmt, 5);
364 p.ships = sqlite3_column_int(stmt, 6);
365 p.Maxx = sqlite3_column_int(stmt, 7);
366 p.Maxy = sqlite3_column_int(stmt, 8);
367 p.popn = sqlite3_column_int(stmt, 9);
368 p.troops = sqlite3_column_int(stmt, 10);
369 p.maxpopn = sqlite3_column_int(stmt, 11);
370 p.total_resources = sqlite3_column_int(stmt, 12);
371 p.slaved_to = sqlite3_column_int(stmt, 13);
372 int p_type = sqlite3_column_int(stmt, 14);
375 p.type = PlanetType::EARTH;
378 p.type = PlanetType::ASTEROID;
381 p.type = PlanetType::MARS;
384 p.type = PlanetType::ICEBALL;
387 p.type = PlanetType::GASGIANT;
390 p.type = PlanetType::WATER;
393 p.type = PlanetType::FOREST;
396 p.type = PlanetType::DESERT;
399 throw std::runtime_error(
"Bad data in type field");
401 p.expltimer = sqlite3_column_int(stmt, 15);
402 p.conditions[
RTEMP] = sqlite3_column_int(stmt, 16);
403 p.conditions[
TEMP] = sqlite3_column_int(stmt, 17);
404 p.conditions[
METHANE] = sqlite3_column_int(stmt, 18);
405 p.conditions[
OXYGEN] = sqlite3_column_int(stmt, 19);
406 p.conditions[
CO2] = sqlite3_column_int(stmt, 20);
407 p.conditions[
HYDROGEN] = sqlite3_column_int(stmt, 21);
408 p.conditions[
NITROGEN] = sqlite3_column_int(stmt, 22);
409 p.conditions[
SULFUR] = sqlite3_column_int(stmt, 23);
410 p.conditions[
HELIUM] = sqlite3_column_int(stmt, 24);
411 p.conditions[
OTHER] = sqlite3_column_int(stmt, 25);
412 p.conditions[
TOXIC] = sqlite3_column_int(stmt, 26);
414 const char *plinfo_sql =
415 "SELECT planet_id, player_id, fuel, destruct, " 416 "resource, popn, troops, crystals, prod_res, " 417 "prod_fuel, prod_dest, prod_crystals, prod_money, " 418 "prod_tech, tech_invest, numsectsowned, comread, " 419 "mob_set, tox_thresh, explored, autorep, tax, " 420 "newtax, guns, mob_points, est_production FROM tbl_plinfo " 421 "WHERE planet_id=?1";
422 sqlite3_prepare_v2(
dbconn, plinfo_sql, -1, &plinfo_stmt, &plinfo_tail);
423 sqlite3_bind_int(plinfo_stmt, 1, p.planet_id);
424 while (sqlite3_step(stmt) == SQLITE_ROW) {
425 int player_id = sqlite3_column_int(plinfo_stmt, 1);
426 p.info[player_id].fuel = sqlite3_column_int(plinfo_stmt, 2);
427 p.info[player_id].destruct = sqlite3_column_int(plinfo_stmt, 3);
428 p.info[player_id].resource = sqlite3_column_int(plinfo_stmt, 4);
429 p.info[player_id].popn = sqlite3_column_int(plinfo_stmt, 5);
430 p.info[player_id].troops = sqlite3_column_int(plinfo_stmt, 6);
431 p.info[player_id].crystals = sqlite3_column_int(plinfo_stmt, 7);
432 p.info[player_id].prod_res = sqlite3_column_int(plinfo_stmt, 8);
433 p.info[player_id].prod_fuel = sqlite3_column_int(plinfo_stmt, 9);
434 p.info[player_id].prod_dest = sqlite3_column_int(plinfo_stmt, 10);
435 p.info[player_id].prod_crystals = sqlite3_column_int(plinfo_stmt, 11);
436 p.info[player_id].prod_money = sqlite3_column_int(plinfo_stmt, 12);
437 p.info[player_id].prod_tech = sqlite3_column_int(plinfo_stmt, 13);
438 p.info[player_id].tech_invest = sqlite3_column_int(plinfo_stmt, 14);
439 p.info[player_id].numsectsowned = sqlite3_column_int(plinfo_stmt, 15);
440 p.info[player_id].comread = sqlite3_column_int(plinfo_stmt, 16);
441 p.info[player_id].mob_set = sqlite3_column_int(plinfo_stmt, 17);
442 p.info[player_id].tox_thresh = sqlite3_column_int(plinfo_stmt, 18);
443 p.info[player_id].explored = sqlite3_column_int(plinfo_stmt, 19);
444 p.info[player_id].autorep = sqlite3_column_int(plinfo_stmt, 20);
445 p.info[player_id].tax = sqlite3_column_int(plinfo_stmt, 21);
446 p.info[player_id].newtax = sqlite3_column_int(plinfo_stmt, 22);
447 p.info[player_id].guns = sqlite3_column_int(plinfo_stmt, 23);
448 p.info[player_id].mob_points = sqlite3_column_int(plinfo_stmt, 24);
449 p.info[player_id].est_production = sqlite3_column_int(plinfo_stmt, 25);
452 const char *plinfo_routes_sql =
453 "SELECT planet_id, player_id, routenum, order_set, dest_star, " 454 "dest_planet, load, unload, x, y FROM tbl_plinfo_routes WHERE " 456 sqlite3_prepare_v2(
dbconn, plinfo_routes_sql, -1, &plinfo_routes_stmt,
457 &plinfo_routes_tail);
458 sqlite3_bind_int(plinfo_routes_stmt, 1, p.planet_id);
459 while (sqlite3_step(stmt) == SQLITE_ROW) {
460 int player_id = sqlite3_column_int(plinfo_routes_stmt, 1);
461 int routenum = sqlite3_column_int(plinfo_routes_stmt, 2);
462 p.info[player_id].route[routenum].set =
463 sqlite3_column_int(plinfo_routes_stmt, 3);
464 p.info[player_id].route[routenum].dest_star =
465 sqlite3_column_int(plinfo_routes_stmt, 4);
466 p.info[player_id].route[routenum].dest_planet =
467 sqlite3_column_int(plinfo_routes_stmt, 5);
468 p.info[player_id].route[routenum].load =
469 sqlite3_column_int(plinfo_routes_stmt, 6);
470 p.info[player_id].route[routenum].unload =
471 sqlite3_column_int(plinfo_routes_stmt, 7);
472 p.info[player_id].route[routenum].x =
473 sqlite3_column_int(plinfo_routes_stmt, 8);
474 p.info[player_id].route[routenum].y =
475 sqlite3_column_int(plinfo_routes_stmt, 9);
480 Sector
getsector(
const Planet &p,
const int x,
const int y) {
484 "SELECT planet_id, xpos, ypos, eff, fert, " 485 "mobilization, crystals, resource, popn, troops, owner, " 486 "race, type, condition FROM tbl_sector " 487 "WHERE planet_id=?1 AND xpos=?2 AND ypos=?3";
488 sqlite3_prepare_v2(
dbconn, sql, -1, &stmt, &tail);
490 sqlite3_bind_int(stmt, 1, p.planet_id);
491 sqlite3_bind_int(stmt, 2, x);
492 sqlite3_bind_int(stmt, 3, y);
494 auto result = sqlite3_step(stmt);
495 if (result != SQLITE_ROW) {
496 throw std::runtime_error(
"Database unable to return the requested sector");
499 Sector s(sqlite3_column_int(stmt, 1),
500 sqlite3_column_int(stmt, 2),
501 sqlite3_column_int(stmt, 3),
502 sqlite3_column_int(stmt, 4),
503 sqlite3_column_int(stmt, 5),
504 sqlite3_column_int(stmt, 6),
505 sqlite3_column_int(stmt, 7),
506 sqlite3_column_int(stmt, 8),
507 sqlite3_column_int(stmt, 9),
508 sqlite3_column_int(stmt, 10),
509 sqlite3_column_int(stmt, 11),
510 sqlite3_column_int(stmt, 12),
511 sqlite3_column_int(stmt, 13)
514 int err = sqlite3_finalize(stmt);
515 if (err != SQLITE_OK) {
516 fprintf(stderr,
"SQLite Error: %s\n", sqlite3_errmsg(
dbconn));
523 const char *tail =
nullptr;
526 "SELECT planet_id, xpos, ypos, eff, fert, " 527 "mobilization, crystals, resource, popn, troops, owner, " 528 "race, type, condition FROM tbl_sector " 529 "WHERE planet_id=?1 ORDER BY ypos, xpos";
530 sqlite3_prepare_v2(
dbconn, sql, -1, &stmt, &tail);
532 sqlite3_bind_int(stmt, 1, p.planet_id);
536 while (sqlite3_step(stmt) == SQLITE_ROW) {
537 Sector s(sqlite3_column_int(stmt, 1),
538 sqlite3_column_int(stmt, 2),
539 sqlite3_column_int(stmt, 3),
540 sqlite3_column_int(stmt, 4),
541 sqlite3_column_int(stmt, 5),
542 sqlite3_column_int(stmt, 6),
543 sqlite3_column_int(stmt, 7),
544 sqlite3_column_int(stmt, 8),
545 sqlite3_column_int(stmt, 9),
546 sqlite3_column_int(stmt, 10),
547 sqlite3_column_int(stmt, 11),
548 sqlite3_column_int(stmt, 12),
549 sqlite3_column_int(stmt, 13)
551 smap.put(std::move(s));
554 sqlite3_clear_bindings(stmt);
561 return getship(
nullptr, shipnum);
567 if (shipnum <= 0)
return {};
570 if (buffer.st_size /
sizeof(Ship) < shipnum)
return {};
577 }
else if ((*s = (Ship *)malloc(
sizeof(Ship))) ==
nullptr) {
578 printf(
"getship:malloc() error \n");
582 Fileread(
shdata, (
char *)*s,
sizeof(Ship), (shipnum - 1) *
sizeof(Ship));
587 "SELECT ship_id, player_id, governor_id, name, " 588 "shipclass, race, xpos, ypos, mass," 589 "land_x, land_y, destshipno, nextship, ships, armor, size," 590 "max_crew, max_resource, max_destruct, max_fuel, max_speed, build_type," 591 "build_cost, base_mass, tech, complexity," 592 "destruct, resource, population, troops, crystals," 594 "navigate_on, navigate_speed, navigate_turns, navigate_bearing," 595 "protect_maxrng, protect_on, protect_planet, protect_self," 596 "protect_evade, protect_ship," 597 "hyper_drive_charge, hyper_drive_ready, hyper_drive_on," 599 "cew, cew_range, cloak, laser, focus, fire_laser," 600 "storbits, deststar, destpnum, pnumorbits, whatdest," 602 "damage, rad, retaliate, target," 604 "active, alive, mode, bombard, mounted, cloaked," 605 "sheep, docked, notified, examined, on_off," 606 "merchant, guns, primary_gun, primtype," 607 "secondary_gun, sectype," 608 "hanger, max_hanger, mount," 609 "aimed_shipno, aimed_snum," 610 "aimed_intensity, aimed_pnum, aimed_level," 611 "mind_progenitor, mind_target," 612 "mind_generation, mind_busy, mind_tampered," 614 "pod_decay, pod_temperature," 616 "impact_x, impact_y, impact_scatter," 621 "FROM tbl_ship WHERE ship_id=?1 LIMIT 1";
623 sqlite3_prepare_v2(
dbconn, sql, -1, &stmt, &tail);
624 sqlite3_bind_int(stmt, 1, shipnum);
626 auto result = sqlite3_step(stmt);
627 if (result != SQLITE_ROW) {
628 int err = sqlite3_finalize(stmt);
629 if (err != SQLITE_OK) {
630 fprintf(stderr,
"SQLite Error: %s\n", sqlite3_errmsg(
dbconn));
635 (*s)->number = sqlite3_column_int(stmt, 0);
636 (*s)->owner = sqlite3_column_int(stmt, 1);
637 (*s)->governor = sqlite3_column_int(stmt, 2);
639 reinterpret_cast<
const char *>(sqlite3_column_text(stmt, 3)));
640 strcpy((*s)->shipclass,
641 reinterpret_cast<
const char *>(sqlite3_column_text(stmt, 4)));
642 (*s)->race = sqlite3_column_int(stmt, 5);
643 (*s)->xpos = sqlite3_column_double(stmt, 6);
644 (*s)->ypos = sqlite3_column_double(stmt, 7);
645 (*s)->mass = sqlite3_column_double(stmt, 8);
646 (*s)->land_x = sqlite3_column_int(stmt, 9);
647 (*s)->land_y = sqlite3_column_int(stmt, 10);
648 (*s)->destshipno = sqlite3_column_int(stmt, 11);
649 (*s)->nextship = sqlite3_column_int(stmt, 12);
650 (*s)->ships = sqlite3_column_int(stmt, 13);
651 (*s)->armor = sqlite3_column_int(stmt, 14);
652 (*s)->size = sqlite3_column_int(stmt, 15);
653 (*s)->max_crew = sqlite3_column_int(stmt, 16);
654 (*s)->max_resource = sqlite3_column_int(stmt, 17);
655 (*s)->max_destruct = sqlite3_column_int(stmt, 18);
656 (*s)->max_fuel = sqlite3_column_int(stmt, 19);
657 (*s)->max_speed = sqlite3_column_int(stmt, 20);
658 (*s)->build_type =
static_cast<ShipType>(sqlite3_column_int(stmt, 21));
659 (*s)->build_cost = sqlite3_column_int(stmt, 22);
660 (*s)->base_mass = sqlite3_column_int(stmt, 23);
661 (*s)->tech = sqlite3_column_int(stmt, 24);
662 (*s)->complexity = sqlite3_column_int(stmt, 25);
663 (*s)->destruct = sqlite3_column_int(stmt, 26);
664 (*s)->resource = sqlite3_column_int(stmt, 27);
665 (*s)->popn = sqlite3_column_int(stmt, 28);
666 (*s)->troops = sqlite3_column_int(stmt, 29);
667 (*s)->crystals = sqlite3_column_int(stmt, 30);
668 (*s)->who_killed = sqlite3_column_int(stmt, 31);
669 (*s)->navigate.on = sqlite3_column_int(stmt, 32);
670 (*s)->navigate.speed = sqlite3_column_int(stmt, 33);
671 (*s)->navigate.turns = sqlite3_column_int(stmt, 34);
672 (*s)->navigate.bearing = sqlite3_column_int(stmt, 35);
673 (*s)->protect.maxrng = sqlite3_column_int(stmt, 36);
674 (*s)->protect.on = sqlite3_column_int(stmt, 37);
675 (*s)->protect.planet = sqlite3_column_int(stmt, 38);
676 (*s)->protect.self = sqlite3_column_int(stmt, 39);
677 (*s)->protect.evade = sqlite3_column_int(stmt, 40);
678 (*s)->protect.ship = sqlite3_column_int(stmt, 41);
679 (*s)->hyper_drive.charge = sqlite3_column_int(stmt, 42);
680 (*s)->hyper_drive.ready = sqlite3_column_int(stmt, 43);
681 (*s)->hyper_drive.on = sqlite3_column_int(stmt, 44);
682 (*s)->hyper_drive.has = sqlite3_column_int(stmt, 45);
683 (*s)->cew = sqlite3_column_int(stmt, 46);
684 (*s)->cew_range = sqlite3_column_int(stmt, 47);
685 (*s)->cloak = sqlite3_column_int(stmt, 48);
686 (*s)->laser = sqlite3_column_int(stmt, 49);
687 (*s)->focus = sqlite3_column_int(stmt, 50);
688 (*s)->fire_laser = sqlite3_column_int(stmt, 51);
689 (*s)->storbits = sqlite3_column_int(stmt, 52);
690 (*s)->deststar = sqlite3_column_int(stmt, 53);
691 (*s)->destpnum = sqlite3_column_int(stmt, 54);
692 (*s)->pnumorbits = sqlite3_column_int(stmt, 55);
693 (*s)->whatdest =
static_cast<ScopeLevel>(sqlite3_column_int(stmt, 56));
694 (*s)->whatorbits =
static_cast<ScopeLevel>(sqlite3_column_int(stmt, 57));
695 (*s)->damage = sqlite3_column_int(stmt, 58);
696 (*s)->rad = sqlite3_column_int(stmt, 59);
697 (*s)->retaliate = sqlite3_column_int(stmt, 60);
698 (*s)->target = sqlite3_column_int(stmt, 61);
699 (*s)->type =
static_cast<ShipType>(sqlite3_column_int(stmt, 62));
700 (*s)->speed = sqlite3_column_int(stmt, 63);
701 (*s)->active = sqlite3_column_int(stmt, 64);
702 (*s)->alive = sqlite3_column_int(stmt, 65);
703 (*s)->mode = sqlite3_column_int(stmt, 66);
704 (*s)->bombard = sqlite3_column_int(stmt, 67);
705 (*s)->mounted = sqlite3_column_int(stmt, 68);
706 (*s)->cloaked = sqlite3_column_int(stmt, 69);
707 (*s)->sheep = sqlite3_column_int(stmt, 70);
708 (*s)->docked = sqlite3_column_int(stmt, 71);
709 (*s)->notified = sqlite3_column_int(stmt, 72);
710 (*s)->examined = sqlite3_column_int(stmt, 73);
711 (*s)->on = sqlite3_column_int(stmt, 74);
712 (*s)->merchant = sqlite3_column_int(stmt, 75);
713 (*s)->guns = sqlite3_column_int(stmt, 76);
714 (*s)->primary = sqlite3_column_int(stmt, 77);
715 (*s)->primtype = sqlite3_column_int(stmt, 78);
716 (*s)->secondary = sqlite3_column_int(stmt, 79);
717 (*s)->sectype = sqlite3_column_int(stmt, 80);
718 (*s)->hanger = sqlite3_column_int(stmt, 81);
719 (*s)->max_hanger = sqlite3_column_int(stmt, 82);
720 (*s)->mount = sqlite3_column_int(stmt, 83);
722 int err = sqlite3_finalize(stmt);
723 if (err != SQLITE_OK) {
724 fprintf(stderr,
"SQLite Error: %s\n", sqlite3_errmsg(
dbconn));
733 if (commodnum <= 0)
return 0;
736 if (buffer.st_size /
sizeof(commodtype) < commodnum)
return 0;
738 if ((*c = (commodtype *)malloc(
sizeof(commodtype))) ==
nullptr) {
739 printf(
"getcommod:malloc() error \n");
743 Fileread(
commoddata, (
char *)*c,
sizeof(commodtype),
744 (commodnum - 1) *
sizeof(commodtype));
758 perror(
"getdeadship");
765 if (buffer.st_size && (abort == 1)) {
767 Fileread(fd, (
char *)&shnum,
sizeof(
short), buffer.st_size -
sizeof(
short));
769 ftruncate(fd, (
long)(buffer.st_size -
sizeof(
short)));
784 perror(
"getdeadcommod");
791 if (buffer.st_size && (abort == 1)) {
793 Fileread(fd, (
char *)&commodnum,
sizeof(
short),
794 buffer.st_size -
sizeof(
short));
796 ftruncate(fd, (
long)(buffer.st_size -
sizeof(
short)));
798 return (
int)commodnum;
805 Filewrite(
stdata, (
char *)S,
sizeof(
struct stardata), 0);
809 Filewrite(
racedata, (
char *)r,
sizeof(Race),
810 (r->Playernum - 1) *
sizeof(Race));
814 Filewrite(
stdata, (
char *)s,
sizeof(startype),
815 (
int)(
sizeof(Sdata) + snum *
sizeof(startype)));
820 const char *tail =
nullptr;
824 "REPLACE INTO tbl_star (star_id, ships, name, xpos, ypos, " 825 "numplanets, stability, nova_stage, temperature, gravity) " 826 "VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10)";
827 sqlite3_prepare_v2(
dbconn, sql, -1, &stmt, &tail);
829 sqlite3_bind_int(stmt, 1, snum);
830 sqlite3_bind_int(stmt, 2, s->ships);
831 sqlite3_bind_text(stmt, 3, s->name, -1, SQLITE_TRANSIENT);
832 sqlite3_bind_double(stmt, 4, s->xpos);
833 sqlite3_bind_double(stmt, 5, s->ypos);
834 sqlite3_bind_int(stmt, 6, s->numplanets);
835 sqlite3_bind_int(stmt, 7, s->stability);
836 sqlite3_bind_int(stmt, 8, s->nova_stage);
837 sqlite3_bind_int(stmt, 9, s->temperature);
838 sqlite3_bind_double(stmt, 10, s->gravity);
846 const char *tail =
nullptr;
849 "REPLACE INTO tbl_star_governor (star_id, player_id, governor_id) " 850 "VALUES (?1, ?2, ?3)";
852 sqlite3_prepare_v2(
dbconn, sql, -1, &stmt, &tail);
854 sqlite3_bind_int(stmt, 1, snum);
855 sqlite3_bind_int(stmt, 2, i);
856 sqlite3_bind_int(stmt, 3, s->governor[i - 1]);
865 const char *tail =
nullptr;
868 "REPLACE INTO tbl_star_playerap (star_id, player_id, ap) " 869 "VALUES (?1, ?2, ?3)";
871 sqlite3_prepare_v2(
dbconn, sql, -1, &stmt, &tail);
873 sqlite3_bind_int(stmt, 1, snum);
874 sqlite3_bind_int(stmt, 2, i);
875 sqlite3_bind_int(stmt, 3, s->AP[i - 1]);
884 const char *tail =
nullptr;
887 "REPLACE INTO tbl_star_explored (star_id, player_id, explored) " 888 "VALUES (?1, ?2, ?3)";
890 sqlite3_prepare_v2(
dbconn, sql, -1, &stmt, &tail);
892 sqlite3_bind_int(stmt, 1, snum);
893 sqlite3_bind_int(stmt, 2, i);
894 sqlite3_bind_int(stmt, 3,
isset(s->explored, i - 1) ? 1 : 0);
903 const char *tail =
nullptr;
906 "REPLACE INTO tbl_star_inhabited (star_id, player_id, explored) " 907 "VALUES (?1, ?2, ?3)";
909 sqlite3_prepare_v2(
dbconn, sql, -1, &stmt, &tail);
911 sqlite3_bind_int(stmt, 1, snum);
912 sqlite3_bind_int(stmt, 2, i);
913 sqlite3_bind_int(stmt, 3,
isset(s->inhabited, i - 1) ? 1 : 0);
925 char *err_msg =
nullptr;
926 sqlite3_exec(
dbconn,
"BEGIN TRANSACTION",
nullptr,
nullptr, &err_msg);
930 char *err_msg =
nullptr;
931 sqlite3_exec(
dbconn,
"END TRANSACTION",
nullptr,
nullptr, &err_msg);
934 void putplanet(
const Planet &p, startype *star,
const int pnum) {
937 const char *tail =
nullptr;
938 const char *plinfo_tail =
nullptr;
939 const char *plinfo_route_tail =
nullptr;
941 sqlite3_stmt *plinfo_stmt;
942 sqlite3_stmt *plinfo_route_stmt;
944 "REPLACE INTO tbl_planet (planet_id, star_id, planet_order, name, " 945 "xpos, ypos, ships, maxx, maxy, popn, troops, maxpopn, total_resources, " 946 "slaved_to, type, expltimer, condition_rtemp, condition_temp, " 947 "condition_methane, condition_oxygen, condition_co2, " 948 "condition_hydrogen, condition_nitrogen, condition_sulfur, " 949 "condition_helium, condition_other, condition_toxic, " 951 "VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, " 952 "?11, ?12, ?13, ?14, ?15, ?16, ?17, ?18, ?19, ?20, " 953 "?21, ?22, ?23, ?24, ?25, ?26, ?27, ?28)";
954 sqlite3_prepare_v2(
dbconn, sql, -1, &stmt, &tail);
956 const char *plinfo_sql =
957 "REPLACE INTO tbl_plinfo (planet_id, player_id, fuel, destruct, " 958 "resource, popn, troops, crystals, prod_res, " 959 "prod_fuel, prod_dest, prod_crystals, prod_money, " 960 "prod_tech, tech_invest, numsectsowned, comread, " 961 "mob_set, tox_thresh, explored, autorep, tax, " 962 "newtax, guns, mob_points, est_production) VALUES " 963 "(?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, " 964 "?11, ?12, ?13, ?14, ?15, ?16, ?17, ?18, ?19, ?20, " 965 "?21, ?22, ?23, ?24, ?25, ?26)";
966 if (sqlite3_prepare_v2(
dbconn, plinfo_sql, -1, &plinfo_stmt, &plinfo_tail) !=
968 fprintf(stderr,
"PLINFO %s\n", sqlite3_errmsg(
dbconn));
971 const char *plinfo_route_sql =
972 "REPLACE INTO tbl_plinfo_routes (planet_id, player_id, routenum, " 973 "order_set, dest_star, dest_planet, " 974 "load, unload, x, y) VALUES " 975 "(?1, ?2, ?3, ?4, 5, ?6, ?7, ?8, ?9, ?10)";
976 sqlite3_prepare_v2(
dbconn, plinfo_route_sql, -1, &plinfo_route_stmt,
979 sqlite3_bind_int(stmt, 1, p.planet_id);
980 sqlite3_bind_int(stmt, 2, star->star_id);
981 sqlite3_bind_int(stmt, 3, pnum);
982 sqlite3_bind_text(stmt, 4, star->pnames[pnum], strlen(star->pnames[pnum]),
984 sqlite3_bind_double(stmt, 5, p.xpos);
985 sqlite3_bind_double(stmt, 6, p.ypos);
986 sqlite3_bind_int(stmt, 7, p.ships);
987 sqlite3_bind_int(stmt, 8, p.Maxx);
988 sqlite3_bind_int(stmt, 9, p.Maxy);
989 sqlite3_bind_int(stmt, 10, p.popn);
990 sqlite3_bind_int(stmt, 11, p.troops);
991 sqlite3_bind_int(stmt, 12, p.maxpopn);
992 sqlite3_bind_int(stmt, 13, p.total_resources);
993 sqlite3_bind_int(stmt, 14, p.slaved_to);
994 sqlite3_bind_int(stmt, 15, p.type);
995 sqlite3_bind_int(stmt, 16, p.expltimer);
996 sqlite3_bind_int(stmt, 17, p.conditions[
RTEMP]);
997 sqlite3_bind_int(stmt, 18, p.conditions[
TEMP]);
998 sqlite3_bind_int(stmt, 19, p.conditions[
METHANE]);
999 sqlite3_bind_int(stmt, 20, p.conditions[
OXYGEN]);
1000 sqlite3_bind_int(stmt, 21, p.conditions[
CO2]);
1001 sqlite3_bind_int(stmt, 22, p.conditions[
HYDROGEN]);
1002 sqlite3_bind_int(stmt, 23, p.conditions[
NITROGEN]);
1003 sqlite3_bind_int(stmt, 24, p.conditions[
SULFUR]);
1004 sqlite3_bind_int(stmt, 25, p.conditions[
HELIUM]);
1005 sqlite3_bind_int(stmt, 26, p.conditions[
OTHER]);
1006 sqlite3_bind_int(stmt, 27, p.conditions[
TOXIC]);
1007 sqlite3_bind_int(stmt, 28, p.explored);
1009 if (sqlite3_step(stmt) != SQLITE_DONE) {
1010 fprintf(stderr,
"XXX %s\n", sqlite3_errmsg(
dbconn));
1015 sqlite3_bind_int(plinfo_stmt, 1, p.planet_id);
1016 sqlite3_bind_int(plinfo_stmt, 2, i);
1017 sqlite3_bind_int(plinfo_stmt, 3, p.info[i].fuel);
1018 sqlite3_bind_int(plinfo_stmt, 4, p.info[i].destruct);
1019 sqlite3_bind_int(plinfo_stmt, 5, p.info[i].resource);
1020 sqlite3_bind_int(plinfo_stmt, 6, p.info[i].popn);
1021 sqlite3_bind_int(plinfo_stmt, 7, p.info[i].troops);
1022 sqlite3_bind_int(plinfo_stmt, 8, p.info[i].crystals);
1023 sqlite3_bind_int(plinfo_stmt, 9, p.info[i].prod_res);
1024 sqlite3_bind_int(plinfo_stmt, 10, p.info[i].prod_fuel);
1025 sqlite3_bind_int(plinfo_stmt, 11, p.info[i].prod_dest);
1026 sqlite3_bind_int(plinfo_stmt, 12, p.info[i].prod_crystals);
1027 sqlite3_bind_int(plinfo_stmt, 13, p.info[i].prod_money);
1028 sqlite3_bind_double(plinfo_stmt, 14, p.info[i].prod_tech);
1029 sqlite3_bind_int(plinfo_stmt, 15, p.info[i].tech_invest);
1030 sqlite3_bind_int(plinfo_stmt, 16, p.info[i].numsectsowned);
1031 sqlite3_bind_int(plinfo_stmt, 17, p.info[i].comread);
1032 sqlite3_bind_int(plinfo_stmt, 18, p.info[i].mob_set);
1033 sqlite3_bind_int(plinfo_stmt, 19, p.info[i].tox_thresh);
1034 sqlite3_bind_int(plinfo_stmt, 20, p.info[i].explored);
1035 sqlite3_bind_int(plinfo_stmt, 21, p.info[i].autorep);
1036 sqlite3_bind_int(plinfo_stmt, 22, p.info[i].tax);
1037 sqlite3_bind_int(plinfo_stmt, 23, p.info[i].newtax);
1038 sqlite3_bind_int(plinfo_stmt, 24, p.info[i].guns);
1039 sqlite3_bind_int(plinfo_stmt, 25, p.info[i].mob_points);
1040 sqlite3_bind_double(plinfo_stmt, 26, p.info[i].est_production);
1042 if (sqlite3_step(plinfo_stmt) != SQLITE_DONE) {
1043 fprintf(stderr,
"YYY %s\n", sqlite3_errmsg(
dbconn));
1045 sqlite3_reset(plinfo_stmt);
1048 for (
int j = 0; j < MAX_ROUTES; j++) {
1049 sqlite3_bind_int(plinfo_route_stmt, 1, p.planet_id);
1050 sqlite3_bind_int(plinfo_route_stmt, 2, i);
1051 sqlite3_bind_int(plinfo_route_stmt, 3, j);
1052 sqlite3_bind_int(plinfo_route_stmt, 4, p.info[i].route[j].set);
1053 sqlite3_bind_int(plinfo_route_stmt, 5, p.info[i].route[j].dest_star);
1054 sqlite3_bind_int(plinfo_route_stmt, 6,
1055 p.info[i].route[j].dest_planet);
1056 sqlite3_bind_int(plinfo_route_stmt, 7, p.info[i].route[j].load);
1057 sqlite3_bind_int(plinfo_route_stmt, 8, p.info[i].route[j].unload);
1058 sqlite3_bind_int(plinfo_route_stmt, 9, p.info[i].route[j].x);
1059 sqlite3_bind_int(plinfo_route_stmt, 10, p.info[i].route[j].y);
1061 if (sqlite3_step(plinfo_route_stmt) != SQLITE_DONE) {
1062 fprintf(stderr,
"ZZZ %s\n", sqlite3_errmsg(
dbconn));
1064 sqlite3_reset(plinfo_route_stmt);
1069 sqlite3_finalize(stmt);
1070 sqlite3_finalize(plinfo_stmt);
1071 sqlite3_finalize(plinfo_route_stmt);
1076 void putsector(
const Sector &s,
const Planet &p,
const int x,
const int y) {
1077 const char *tail =
nullptr;
1080 "REPLACE INTO tbl_sector (planet_id, xpos, ypos, eff, fert, " 1081 "mobilization, crystals, resource, popn, troops, owner, " 1082 "race, type, condition) " 1083 "VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12, ?13, ?14)";
1085 sqlite3_prepare_v2(
dbconn, sql, -1, &stmt, &tail);
1086 sqlite3_bind_int(stmt, 1, p.planet_id);
1087 sqlite3_bind_int(stmt, 2, x);
1088 sqlite3_bind_int(stmt, 3, y);
1089 sqlite3_bind_int(stmt, 4, s.eff);
1090 sqlite3_bind_int(stmt, 5, s.fert);
1091 sqlite3_bind_int(stmt, 6, s.mobilization);
1092 sqlite3_bind_int(stmt, 7, s.crystals);
1093 sqlite3_bind_int(stmt, 8, s.resource);
1094 sqlite3_bind_int(stmt, 9, s.popn);
1095 sqlite3_bind_int(stmt, 10, s.troops);
1096 sqlite3_bind_int(stmt, 11, s.owner);
1097 sqlite3_bind_int(stmt, 12, s.race);
1098 sqlite3_bind_int(stmt, 13, s.type);
1099 sqlite3_bind_int(stmt, 14, s.condition);
1101 if (sqlite3_step(stmt) != SQLITE_DONE) {
1102 fprintf(stderr,
"000 %s\n", sqlite3_errmsg(
dbconn));
1105 sqlite3_reset(stmt);
1111 for (
int y = 0; y < p.Maxy; y++) {
1112 for (
int x = 0; x < p.Maxx; x++) {
1113 auto &sec = map.get(x, y);
1125 "REPLACE INTO tbl_ship (ship_id, aimed_shipno, aimed_snum, " 1126 "aimed_intensity, aimed_pnum, aimed_level)" 1127 "VALUES (?1, ?2, ?3, ?4, ?5, ?6);";
1129 sqlite3_prepare_v2(
dbconn, sql, -1, &stmt, &tail);
1130 sqlite3_bind_int(stmt, 1, s.number);
1131 sqlite3_bind_int(stmt, 2, s.special.aimed_at.shipno);
1132 sqlite3_bind_int(stmt, 3, s.special.aimed_at.snum);
1133 sqlite3_bind_int(stmt, 4, s.special.aimed_at.intensity);
1134 sqlite3_bind_int(stmt, 5, s.special.aimed_at.pnum);
1135 sqlite3_bind_int(stmt, 6, s.special.aimed_at.level);
1137 if (sqlite3_step(stmt) != SQLITE_DONE) {
1138 fprintf(stderr,
"XXX %s\n", sqlite3_errmsg(
dbconn));
1141 int err = sqlite3_finalize(stmt);
1142 if (err != SQLITE_OK) {
1143 fprintf(stderr,
"SQLite Error: %s\n", sqlite3_errmsg(
dbconn));
1150 "REPLACE INTO tbl_ship (ship_id, mind_progenitor, mind_target, " 1151 "mind_generation, mind_busy, mind_tampered," 1153 "VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7);";
1155 sqlite3_prepare_v2(
dbconn, sql, -1, &stmt, &tail);
1156 sqlite3_bind_int(stmt, 1, s.number);
1157 sqlite3_bind_int(stmt, 2, s.special.mind.progenitor);
1158 sqlite3_bind_int(stmt, 3, s.special.mind.target);
1159 sqlite3_bind_int(stmt, 4, s.special.mind.generation);
1160 sqlite3_bind_int(stmt, 5, s.special.mind.busy);
1161 sqlite3_bind_int(stmt, 6, s.special.mind.tampered);
1162 sqlite3_bind_int(stmt, 7, s.special.mind.who_killed);
1164 if (sqlite3_step(stmt) != SQLITE_DONE) {
1165 fprintf(stderr,
"XXX %s\n", sqlite3_errmsg(
dbconn));
1168 int err = sqlite3_finalize(stmt);
1169 if (err != SQLITE_OK) {
1170 fprintf(stderr,
"SQLite Error: %s\n", sqlite3_errmsg(
dbconn));
1177 "REPLACE INTO tbl_ship (ship_id, pod_decay, pod_temperature)" 1178 "VALUES (?1, ?2, ?3);";
1180 sqlite3_prepare_v2(
dbconn, sql, -1, &stmt, &tail);
1181 sqlite3_bind_int(stmt, 1, s.number);
1182 sqlite3_bind_int(stmt, 2, s.special.pod.decay);
1183 sqlite3_bind_int(stmt, 3, s.special.pod.temperature);
1185 if (sqlite3_step(stmt) != SQLITE_DONE) {
1186 fprintf(stderr,
"XXX %s\n", sqlite3_errmsg(
dbconn));
1189 int err = sqlite3_finalize(stmt);
1190 if (err != SQLITE_OK) {
1191 fprintf(stderr,
"SQLite Error: %s\n", sqlite3_errmsg(
dbconn));
1198 "REPLACE INTO tbl_ship (ship_id, timer_count)" 1201 sqlite3_prepare_v2(
dbconn, sql, -1, &stmt, &tail);
1202 sqlite3_bind_int(stmt, 1, s.number);
1203 sqlite3_bind_int(stmt, 2, s.special.timer.count);
1205 if (sqlite3_step(stmt) != SQLITE_DONE) {
1206 fprintf(stderr,
"XXX %s\n", sqlite3_errmsg(
dbconn));
1209 int err = sqlite3_finalize(stmt);
1210 if (err != SQLITE_OK) {
1211 fprintf(stderr,
"SQLite Error: %s\n", sqlite3_errmsg(
dbconn));
1218 "REPLACE INTO tbl_ship (ship_id, impact_x, impact_y, impact_scatter)" 1219 "VALUES (?1, ?2, ?3, ?4);";
1221 sqlite3_prepare_v2(
dbconn, sql, -1, &stmt, &tail);
1222 sqlite3_bind_int(stmt, 1, s.number);
1223 sqlite3_bind_int(stmt, 2, s.special.impact.x);
1224 sqlite3_bind_int(stmt, 3, s.special.impact.y);
1225 sqlite3_bind_int(stmt, 4, s.special.impact.scatter);
1227 if (sqlite3_step(stmt) != SQLITE_DONE) {
1228 fprintf(stderr,
"XXX %s\n", sqlite3_errmsg(
dbconn));
1231 int err = sqlite3_finalize(stmt);
1232 if (err != SQLITE_OK) {
1233 fprintf(stderr,
"SQLite Error: %s\n", sqlite3_errmsg(
dbconn));
1240 "REPLACE INTO tbl_ship (ship_id, trigger_radius)" 1243 sqlite3_prepare_v2(
dbconn, sql, -1, &stmt, &tail);
1244 sqlite3_bind_int(stmt, 1, s.number);
1245 sqlite3_bind_int(stmt, 2, s.special.trigger.radius);
1247 if (sqlite3_step(stmt) != SQLITE_DONE) {
1248 fprintf(stderr,
"XXX %s\n", sqlite3_errmsg(
dbconn));
1251 int err = sqlite3_finalize(stmt);
1252 if (err != SQLITE_OK) {
1253 fprintf(stderr,
"SQLite Error: %s\n", sqlite3_errmsg(
dbconn));
1260 "REPLACE INTO tbl_ship (ship_id, terraform_index)" 1263 sqlite3_prepare_v2(
dbconn, sql, -1, &stmt, &tail);
1264 sqlite3_bind_int(stmt, 1, s.number);
1265 sqlite3_bind_int(stmt, 2, s.special.terraform.index);
1267 if (sqlite3_step(stmt) != SQLITE_DONE) {
1268 fprintf(stderr,
"XXX %s\n", sqlite3_errmsg(
dbconn));
1271 int err = sqlite3_finalize(stmt);
1272 if (err != SQLITE_OK) {
1273 fprintf(stderr,
"SQLite Error: %s\n", sqlite3_errmsg(
dbconn));
1280 "REPLACE INTO tbl_ship (ship_id, transport_target)" 1283 sqlite3_prepare_v2(
dbconn, sql, -1, &stmt, &tail);
1284 sqlite3_bind_int(stmt, 1, s.number);
1285 sqlite3_bind_int(stmt, 2, s.special.transport.target);
1287 if (sqlite3_step(stmt) != SQLITE_DONE) {
1288 fprintf(stderr,
"XXX %s\n", sqlite3_errmsg(
dbconn));
1291 int err = sqlite3_finalize(stmt);
1292 if (err != SQLITE_OK) {
1293 fprintf(stderr,
"SQLite Error: %s\n", sqlite3_errmsg(
dbconn));
1300 "REPLACE INTO tbl_ship (ship_id, waste_toxic)" 1303 sqlite3_prepare_v2(
dbconn, sql, -1, &stmt, &tail);
1304 sqlite3_bind_int(stmt, 1, s.number);
1305 sqlite3_bind_int(stmt, 2, s.special.waste.toxic);
1307 if (sqlite3_step(stmt) != SQLITE_DONE) {
1308 fprintf(stderr,
"XXX %s\n", sqlite3_errmsg(
dbconn));
1311 int err = sqlite3_finalize(stmt);
1312 if (err != SQLITE_OK) {
1313 fprintf(stderr,
"SQLite Error: %s\n", sqlite3_errmsg(
dbconn));
1319 Filewrite(
shdata, (
char *)s,
sizeof(Ship), (s->number - 1) *
sizeof(Ship));
1324 "REPLACE INTO tbl_ship (ship_id, player_id, governor_id, name, " 1325 "shipclass, race, xpos, ypos, mass," 1326 "land_x, land_y, destshipno, nextship, ships, armor, size," 1327 "max_crew, max_resource, max_destruct, max_fuel, max_speed, build_type," 1328 "build_cost, base_mass, tech, complexity," 1329 "destruct, resource, population, troops, crystals," 1331 "navigate_on, navigate_speed, navigate_turns, navigate_bearing," 1332 "protect_maxrng, protect_on, protect_planet, protect_self," 1333 "protect_evade, protect_ship," 1334 "hyper_drive_charge, hyper_drive_ready, hyper_drive_on," 1336 "cew, cew_range, cloak, laser, focus, fire_laser," 1337 "storbits, deststar, destpnum, pnumorbits, whatdest," 1339 "damage, rad, retaliate, target," 1341 "active, alive, mode, bombard, mounted, cloaked," 1342 "sheep, docked, notified, examined, on_off," 1343 "merchant, guns, primary_gun, primtype," 1344 "secondary_gun, sectype," 1345 "hanger, max_hanger, mount)" 1346 "VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9," 1347 "?10, ?11, ?12, ?13, ?14, ?15, ?16," 1348 "?17, ?18, ?19, ?20, ?21, ?22, ?23, ?24, ?25, ?26," 1349 "?27, ?28, ?29, ?30, ?31," 1351 "?33, ?34, ?35, ?36," 1352 "?37, ?38, ?39, ?40," 1356 "?47, ?48, ?49, ?50, ?51, ?52," 1357 "?53, ?54, ?55, ?56, ?57," 1359 "?59, ?60, ?61, ?62," 1361 "?65, ?66, ?67, ?68, ?69, ?70," 1362 "?71, ?72, ?73, ?74, ?75," 1363 "?76, ?77, ?78, ?79," 1367 sqlite3_prepare_v2(
dbconn, sql, -1, &stmt, &tail);
1368 sqlite3_bind_int(stmt, 1, s->number);
1369 sqlite3_bind_int(stmt, 2, s->owner);
1370 sqlite3_bind_int(stmt, 3, s->governor);
1371 sqlite3_bind_text(stmt, 4, s->name, strlen(s->name), SQLITE_TRANSIENT);
1372 sqlite3_bind_text(stmt, 5, s->shipclass, strlen(s->shipclass),
1374 sqlite3_bind_int(stmt, 6, s->race);
1375 sqlite3_bind_double(stmt, 7, s->xpos);
1376 sqlite3_bind_double(stmt, 8, s->ypos);
1377 sqlite3_bind_double(stmt, 9, s->mass);
1378 sqlite3_bind_int(stmt, 10, s->land_x);
1379 sqlite3_bind_int(stmt, 11, s->land_y);
1380 sqlite3_bind_int(stmt, 12, s->destshipno);
1381 sqlite3_bind_int(stmt, 13, s->nextship);
1382 sqlite3_bind_int(stmt, 14, s->ships);
1383 sqlite3_bind_int(stmt, 15, s->armor);
1384 sqlite3_bind_int(stmt, 16, s->size);
1385 sqlite3_bind_int(stmt, 17, s->max_crew);
1386 sqlite3_bind_int(stmt, 18, s->max_resource);
1387 sqlite3_bind_int(stmt, 19, s->max_destruct);
1388 sqlite3_bind_int(stmt, 20, s->max_fuel);
1389 sqlite3_bind_int(stmt, 21, s->max_speed);
1390 sqlite3_bind_int(stmt, 22, s->build_type);
1391 sqlite3_bind_int(stmt, 23, s->build_cost);
1392 sqlite3_bind_double(stmt, 24, s->base_mass);
1393 sqlite3_bind_double(stmt, 25, s->tech);
1394 sqlite3_bind_double(stmt, 26, s->complexity);
1395 sqlite3_bind_int(stmt, 27, s->destruct);
1396 sqlite3_bind_int(stmt, 28, s->resource);
1397 sqlite3_bind_int(stmt, 29, s->popn);
1398 sqlite3_bind_int(stmt, 30, s->troops);
1399 sqlite3_bind_int(stmt, 31, s->crystals);
1400 sqlite3_bind_int(stmt, 32, s->who_killed);
1401 sqlite3_bind_int(stmt, 33, s->navigate.on);
1402 sqlite3_bind_int(stmt, 34, s->navigate.speed);
1403 sqlite3_bind_int(stmt, 35, s->navigate.turns);
1404 sqlite3_bind_int(stmt, 36, s->navigate.bearing);
1405 sqlite3_bind_double(stmt, 37, s->protect.maxrng);
1406 sqlite3_bind_int(stmt, 38, s->protect.on);
1407 sqlite3_bind_int(stmt, 39, s->protect.planet);
1408 sqlite3_bind_int(stmt, 40, s->protect.self);
1409 sqlite3_bind_int(stmt, 41, s->protect.evade);
1410 sqlite3_bind_int(stmt, 42, s->protect.ship);
1411 sqlite3_bind_int(stmt, 43, s->hyper_drive.charge);
1412 sqlite3_bind_int(stmt, 44, s->hyper_drive.ready);
1413 sqlite3_bind_int(stmt, 45, s->hyper_drive.on);
1414 sqlite3_bind_int(stmt, 46, s->hyper_drive.has);
1415 sqlite3_bind_int(stmt, 47, s->cew);
1416 sqlite3_bind_int(stmt, 48, s->cew_range);
1417 sqlite3_bind_int(stmt, 49, s->cloak);
1418 sqlite3_bind_int(stmt, 50, s->laser);
1419 sqlite3_bind_int(stmt, 51, s->focus);
1420 sqlite3_bind_int(stmt, 52, s->fire_laser);
1421 sqlite3_bind_int(stmt, 53, s->storbits);
1422 sqlite3_bind_int(stmt, 54, s->deststar);
1423 sqlite3_bind_int(stmt, 55, s->destpnum);
1424 sqlite3_bind_int(stmt, 56, s->pnumorbits);
1425 sqlite3_bind_int(stmt, 57, s->whatdest);
1426 sqlite3_bind_int(stmt, 58, s->whatorbits);
1427 sqlite3_bind_int(stmt, 59, s->damage);
1428 sqlite3_bind_int(stmt, 60, s->rad);
1429 sqlite3_bind_int(stmt, 61, s->retaliate);
1430 sqlite3_bind_int(stmt, 62, s->target);
1431 sqlite3_bind_int(stmt, 63, s->type);
1432 sqlite3_bind_int(stmt, 64, s->speed);
1433 sqlite3_bind_int(stmt, 65, s->active);
1434 sqlite3_bind_int(stmt, 66, s->alive);
1435 sqlite3_bind_int(stmt, 67, s->mode);
1436 sqlite3_bind_int(stmt, 68, s->bombard);
1437 sqlite3_bind_int(stmt, 69, s->mounted);
1438 sqlite3_bind_int(stmt, 70, s->cloaked);
1439 sqlite3_bind_int(stmt, 71, s->sheep);
1440 sqlite3_bind_int(stmt, 72, s->docked);
1441 sqlite3_bind_int(stmt, 73, s->notified);
1442 sqlite3_bind_int(stmt, 74, s->examined);
1443 sqlite3_bind_int(stmt, 75, s->on);
1444 sqlite3_bind_int(stmt, 76, s->merchant);
1445 sqlite3_bind_int(stmt, 77, s->guns);
1446 sqlite3_bind_int(stmt, 78, s->primary);
1447 sqlite3_bind_int(stmt, 79, s->primtype);
1448 sqlite3_bind_int(stmt, 80, s->secondary);
1449 sqlite3_bind_int(stmt, 81, s->sectype);
1450 sqlite3_bind_int(stmt, 82, s->hanger);
1451 sqlite3_bind_int(stmt, 83, s->max_hanger);
1452 sqlite3_bind_int(stmt, 84, s->mount);
1454 if (sqlite3_step(stmt) != SQLITE_DONE) {
1455 fprintf(stderr,
"XXX %s\n", sqlite3_errmsg(
dbconn));
1458 int err = sqlite3_finalize(stmt);
1459 if (err != SQLITE_OK) {
1460 fprintf(stderr,
"SQLite Error: %s\n", sqlite3_errmsg(
dbconn));
1464 case ShipType::STYPE_MIRROR:
1467 case ShipType::OTYPE_BERS:
1469 case ShipType::OTYPE_VN:
1472 case ShipType::STYPE_POD:
1475 case ShipType::OTYPE_CANIST:
1477 case ShipType::OTYPE_GREEN:
1480 case ShipType::STYPE_MISSILE:
1483 case ShipType::STYPE_MINE:
1486 case ShipType::OTYPE_TERRA:
1488 case ShipType::OTYPE_PLOW:
1491 case ShipType::OTYPE_TRANSDEV:
1494 case ShipType::OTYPE_TOXWC:
1505 Filewrite(
commoddata, (
char *)c,
sizeof(commodtype),
1506 (commodnum - 1) *
sizeof(commodtype));
1513 return ((
int)(buffer.st_size /
sizeof(Race)));
1518 const char *tail =
nullptr;
1521 const auto sql =
"SELECT COUNT(*) FROM tbl_ship;";
1522 sqlite3_prepare_v2(
dbconn, sql, -1, &stmt, &tail);
1524 auto result = sqlite3_step(stmt);
1525 if (result != SQLITE_ROW) {
1526 throw std::runtime_error(
"Database unable to return the requested planet");
1529 return sqlite3_column_int(stmt, 0);
1537 return ((
int)(buffer.st_size /
sizeof(commodtype)));
1551 if ((fp = fopen(
TRANSFERFL,
"r")) ==
nullptr)
1558 if ((fp = fopen(
ANNOUNCEFL,
"r")) ==
nullptr)
1564 fstat(fileno(fp), &buffer);
1566 return ((
int)buffer.st_size);
1579 unsigned short shipno;
1584 if (shipno == 0)
return;
1587 printf(
"fd = %d \n", fd);
1588 printf(
"errno = %d \n", errno);
1589 perror(
"openshfdata");
1597 Filewrite(fd, (
char *)&shipno,
sizeof(shipno), buffer.st_size);
1603 unsigned short commodno;
1606 commodno = commodnum;
1608 if (commodno == 0)
return;
1611 printf(
"fd = %d \n", fd);
1612 printf(
"errno = %d \n", errno);
1613 perror(
"opencommodfdata");
1621 Filewrite(fd, (
char *)&commodno,
sizeof(commodno), buffer.st_size);
1628 if ((power_fd = open(
POWFL, O_RDWR, 0777)) < 0) {
1629 perror(
"open power data");
1630 printf(
"unable to open %s\n",
POWFL);
1633 write(power_fd, (
char *)p,
sizeof(*p) *
MAXPLAYERS);
1640 if ((power_fd = open(
POWFL, O_RDONLY, 0777)) < 0) {
1641 perror(
"open power data");
1642 printf(
"unable to open %s\n",
POWFL);
1645 read(power_fd, (
char *)p,
sizeof(*p) *
MAXPLAYERS);
1652 if ((block_fd = open(
BLOCKDATAFL, O_RDWR, 0777)) < 0) {
1653 perror(
"open block data");
1657 write(block_fd, (
char *)b,
sizeof(*b) *
MAXPLAYERS);
1664 if ((block_fd = open(
BLOCKDATAFL, O_RDONLY, 0777)) < 0) {
1665 perror(
"open block data");
1669 read(block_fd, (
char *)b,
sizeof(*b) *
MAXPLAYERS);
static void putship_pod(const Ship &s)
Planet getplanet(const starnum_t star, const planetnum_t pnum)
void makecommoddead(int commodnum)
std::optional< Ship > getship(const shipnum_t shipnum)
void putsector(const Sector &s, const Planet &p, const int x, const int y)
static void putship_trigger(const Ship &s)
void openstardata(int *fd)
static void putship_timer(const Ship &s)
static void putship_waste(const Ship &s)
void makeshipdead(int shipnum)
void putsmap(SectorMap &map, Planet &p)
void putcommod(commodtype *c, int commodnum)
static void putship_mind(const Ship &s)
void openracedata(int *fd)
void Getpower(struct power p[MAXPLAYERS])
void Getblock(struct block b[MAXPLAYERS])
void Putblock(struct block b[MAXPLAYERS])
void putstar(startype *s, starnum_t snum)
static void start_bulk_insert()
void getsdata(struct stardata *S)
static void putship_impact(const Ship &s)
static void putship_terraform(const Ship &s)
void putplanet(const Planet &p, startype *star, const int pnum)
void getstar(startype **s, int star)
static void putship_aimed(const Ship &s)
static void end_bulk_insert()
SectorMap getsmap(const Planet &p)
void opencommoddata(int *fd)
int getcommod(commodtype **c, commodnum_t commodnum)
void putsdata(struct stardata *S)
void getrace(Race **r, int rnum)
std::optional< Ship > getship(Ship **s, const shipnum_t shipnum)
void Putpower(struct power p[MAXPLAYERS])
Sector getsector(const Planet &p, const int x, const int y)
static void putship_transport(const Ship &s)