120 static bool first_frame =
true;
124 : ctrl(c), test_mode(false), grid_shown(false), dust(0),
125 star_system(0), active_region(0), mission(0), netgame(0),
166 Print(
"Name Kill1 Kill2 Died Colls Points Cmd Pts\n");
167 Print(
"---------------- ----- ----- ----- ----- ------ ------\n");
178 Print(
"%-16s %5d %5d %5d %5d %6d %6d\n",
219 Print(
"--------------------------------------------\n");
220 Print(
"TOTAL %5d %5d %5d %5d\n\n", tk1, tk2, td, tc);
305 if (preload_textures) {
311 while (++elem_iter) {
316 for (
int i = 0; i < 4; i++) {
320 while (++model_iter) {
321 Model* model = model_iter.value();
327 while (++surf_iter) {
357 Print(
"Sim::ExecMission() - No mission to execute.\n");
362 Print(
"Sim::ExecMission(%s) mission is already executing.\n",
mission->
Name());
408 const char* active_region_name = 0;
428 if (!strcmp(active_region_name, sim_region->
Name())) {
438 if (!strcmp(active_region_name, sim_region->
Name())) {
448 if (!strcmp(active_region_name, sim_region->
Name())) {
642 bool alertPrep =
false;
648 if (hangar && element && msn_elem->
Count() > 0 && msn_elem->
IsAlert()) {
686 for (
int i = 0; i < msn_elem->
Count(); i++) {
691 alertPrep = alertPrep &&
706 if (msn_elem->
Player() == i+1) {
711 ::Print(
"WARNING: alert ship '%s' region is null\n", alertShip->
Name());
722 for (
int i = 0; i < msn_elem->
Count(); i++) {
729 msn_ship = msn_elem->
Ships()[i];
730 sname = msn_ship->
Name();
731 rnum = msn_ship->
RegNum();
732 rgn_name = msn_ship->
Region();
737 if (msn_ship && fabs(msn_ship->
Location().
x) < 1e9) {
744 if (msn_elem->
Count() < 5)
778 double heading = msn_elem->
Heading();
825 if (msn_ship->
Ammo()[0] > -10) {
826 for (
int i = 0; i < 64; i++) {
835 if (msn_ship->
Fuel()[0] > -10) {
836 for (
int i = 0; i < 4; i++) {
844 if (msn_ship->
Decoys() > -10) {
850 if (msn_ship->
Probes() > -10) {
921 const char* call =
"Unidentified";
923 for (
int i = 0; i < 32; i++) {
936 Element* elem =
new(__FILE__,__LINE__)
Element(callsign, IFF, type);
981 return assigned.
size();
990 Print(
"WARNING: CreateShip(%s): invalid design\n", name);
1000 Ship* ship =
new(__FILE__,__LINE__)
Ship(name, reg_num, design, IFF, cmd_ai, loadout);
1027 while (++rgn && !ship)
1056 while (++rgn && !ship)
1068 while (++rgn && !shot)
1083 while (++iter && !body) {
1101 shot =
new(__FILE__,__LINE__)
Drone(pos, shot_cam, design, ship);
1103 shot =
new(__FILE__,__LINE__)
Shot( pos, shot_cam, design, ship);
1123 Explosion* exp =
new(__FILE__,__LINE__)
Explosion(type, pos, vel, exp_scale, part_scale, rgn, source);
1139 Debris* debris =
new(__FILE__,__LINE__)
Debris(model, pos, vel, mass);
1172 SimSplash* splash =
new(__FILE__,__LINE__)
1189 double damage = shot->
Damage();
1190 if (damage < shot->Design()->damage)
1193 SimSplash* splash =
new(__FILE__,__LINE__)
1216 if (player && player->
GridMode() == 0) {
1244 return dummy_system_list;
1267 while (++rgn && !player) {
1354 if (rgn->
name == name)
1388 if (!
object)
return 0;
1391 double distance = 1.0e40;
1392 Point objloc =
object->Location();
1401 if (rgn->
Type() == type) {
1404 double test = fabs((orgn->
Location() - objloc).length());
1405 if (test < distance) {
1406 result = rgn.
value();
1425 while (++rgn && !result) {
1431 if (iter.
value() == orgn)
1432 result = rgn.
value();
1463 ::Print(
"WARNING: Sim::ActivateRegion() No star system found for rgn '%s'", rgn->
Name());
1479 bool hyperdrive =
false;
1493 first_frame =
false;
1614 for (
int i = 0; i < deck->
NumSlots(); i++) {
1633 while (++neighbor) {
1636 if (s == jumpship)
continue;
1640 if (delta.
length() < 5e3) {
1647 for (
int i = 0; i < riders.
size(); i++) {
1648 Ship* s = riders[i];
1677 ::Print(
"Ship '%s' farcast to '%s'\n", jumpship->
Name(), dest->
Name());
1695 ::Print(
"Ship '%s' broke orbit to '%s'\n", jumpship->
Name(), dest->
Name());
1702 ::Print(
"Ship '%s' achieved orbit '%s'\n", jumpship->
Name(), dest->
Name());
1709 ::Print(
"Ship '%s' quantum to '%s'\n", jumpship->
Name(), dest->
Name());
1724 ::Print(
"Warning: Unusual jump request for ship '%s'\n", jumpship->
Name());
1725 regions[1]->InsertObject(jumpship);
1760 double distance = (ship->
Location() - splash->
loc).length();
1762 if (distance > 1 && distance < splash->range) {
1763 double damage = splash->
damage * (1 - distance/splash->
range);
1771 if (ship_destroyed) {
1787 killer->AddPoints(ship->
Value());
1828 while (++drone_iter) {
1831 double distance = (drone->
Location() - splash->
loc).length();
1833 if (distance > 1 && distance < splash->range) {
1834 double damage = splash->
damage * (1 - distance/splash->
range);
1837 int destroyed = (drone->
Integrity() < 1.0f);
1858 Text ship_name = ship;
1864 if (event->IsPending() &&
event->Trigger() == type) {
1872 if (event->TriggerParam() <= param) {
1873 if (ship_name.
indexOf(event->TriggerShip()) == 0)
1879 if (event->TriggerParam() == param) {
1880 if (ship_name.
indexOf(event->TriggerShip()) == 0)
1887 if (event->TriggerParam() == event_id)
1910 double end_time = 0;
1912 while (++iter && !end) {
1915 if (event->IsPending() ||
event->IsActive()) {
1919 end_time =
event->
Time();
1928 event->Execute(
true);
1934 if (skip_time > 0) {
1954 double total_skip = seconds;
1955 double frame_skip = 10;
1958 while (total_skip > frame_skip) {
1961 total_skip -= frame_skip;
1962 skipped += frame_skip;
1972 skipped += total_skip;
2004 int num_live_ships = 0;
2006 for (
int i = 0; i < elem->
NumShips(); i++) {
2013 if (elem->
IsSquadron() || num_live_ships > 0) {
2051 int squadron_index = 0;
2064 if (design_path.
indexOf(
"/Mods/Ships") == 0) {
2065 design_path = design_path.
substring(11, 1000);
2066 msn_elem->
SetPath(design_path);
2103 if (design_path.
indexOf(
"/Mods/Ships") == 0) {
2104 design_path = design_path.
substring(11, 1000);
2105 msn_elem->
SetPath(design_path);
2117 for (
int i = 0; i < num_obj; i++) {
2127 for (
int i = 0; i < num_inst; i++) {
2133 while (++nav_iter) {
2148 for (
int i = 0; i < elem->
NumShips(); i++) {
2174 for (n = 0; n < 16; n++) {
2178 ammo[n] = w->
Ammo();
2183 for (n = 0; n < 4; n++) {
2185 fuel[n] = ship->
Reactors()[n]->Charge();
2207 while (++iter && !hangar) {
2211 while (++s_iter && !hangar) {
2215 for (
int i = 0; i < h->
NumSquadrons() && !hangar; i++) {
2230 : sim(s), name(n), type(t), orbital_region(0), star_system(0)
2231 , player_ship(0), grid(0), active(false), current_view(0), sim_time(0)
2232 , ai_index(0), terrain(0)
2240 : sim(s), orbital_region(r), type(REAL_SPACE), star_system(0)
2241 , player_ship(0), grid(0), active(false), current_view(0), sim_time(0)
2242 , ai_index(0), terrain(0)
2265 Point init_loc((rand()-16384.0f) * 30,
2266 (rand()-16384.0f) * 3,
2267 (rand()-16384.0f) * 30);
2288 for (
int i = 0; i < 5; i++)
2313 if (player_index >= 0) {
2321 Print(
"SimRegion %s could not set player ship '%s' - not in region\n",
2498 for (
int i = 0; i < 5; i++)
2509 double seconds = secs;
2515 double delta = new_time -
sim_time;
2516 seconds = delta / 1000.0;
2518 if (seconds > max_frame)
2519 seconds = max_frame;
2615 while (++ship_iter) {
2616 ship = ship_iter.
value();
2636 while (++shot_iter) {
2643 if (shot->
Life() < 0.02 || seeker && seeker->
Overshot()) {
2649 if (shot->
Life() < 0.01) {
2668 while (++exp_iter) {
2672 if (exp->
Life() < 0.01) {
2679 while (++debris_iter) {
2683 if (d->
Life() < 0.01) {
2704 while (++shot_iter) {
2707 const char* owner_name;
2710 owner_name = owner->
Name();
2712 owner_name =
"[KIA]";
2716 while (shot && ++ship_iter) {
2718 int hit = ship->
HitBy(shot, impact);
2722 if (shot->
Damage() < 0) {
2730 else if (shot->
Damage() > 0) {
2734 if (ship_destroyed) {
2804 else if (shot->
Damage() > 0)
2832 while (shot && ++drone_iter) {
2835 if (d == shot || d->
Owner() == owner)
2838 int hit = d->
HitBy(shot, impact);
2840 int destroyed = (d->
Integrity() < 1.0f);
2874 while (shot && ++debris_iter) {
2880 int hit = d->
HitBy(shot, impact);
2882 int destroyed = (d->
Integrity() < 1.0f);
2906 while (shot && ++a_iter) {
2909 int hit = a->
HitBy(shot, impact);
2937 while (++ship_iter) {
2948 while (++targ_iter) {
2951 if (t_index++ <= s_index)
continue;
2953 if (targ == ship)
continue;
2984 double dvs = (sv2-sv1).length();
2985 double dvt = (tv2-tv1).length();
2987 if (dvs > 20) dvs *= dvs;
2988 if (dvt > 20) dvt *= dvt;
2991 double old_integrity = ship->
Integrity();
2993 double hull_damage = old_integrity - ship->
Integrity();
2998 hull_damage = old_integrity - targ->
Integrity();
3038 while (++debris_iter) {
3120 while (++ship_iter) {
3142 while (++shot_iter) {
3169 while (++ship_iter) {
3202 strcpy_s(ship_name, ship->
Name());
3203 strcpy_s(ship_reg, ship->
Registry());
3206 int ship_iff = ship->
GetIFF();
3209 bool observe =
false;
3216 observe = player_destroyed;
3219 if (respawn || observe) {
3226 spawn_loc.
z =
Random(8e3, 10e3);
3228 spawn =
sim->
CreateShip(ship_name, ship_reg, ship_design, rgn_name, spawn_loc, ship_iff, cmd_ai, observe ? 0 : ship->
GetLoadout());
3235 int n = strlen(ship_name);
3236 if (ship_name[n-2] ==
' ' && isdigit(ship_name[n-1]))
3243 Print(
"Warning: No Element found for '%s' on respawn.\n", ship_name);
3245 if (player_destroyed)
3250 if (player_destroyed) {
3268 if (!ship || !carrier || !deck)
return;
3280 if (ship_name && *ship_name) {
3281 int name_len = strlen(ship_name);
3284 while (++ship_iter && !ship) {
3286 if (!strncmp(test->
Name(), ship_name, name_len)) {
3287 int test_len = strlen(test->
Name());
3293 if (test_len > name_len && test->
Name()[name_len] !=
' ')
3310 while (++ship_iter && !ship) {
3325 while (++shot_iter && !shot) {
3333 while (++drone_iter && !shot) {
3352 while (++ship_iter) {
3378 strcpy_s(ship_name, ship->
Name());
3384 if (player_docked) {
3392 Print(
" %s Docked with %s\n", ship_name, carrier->
Name());
3525 object->TranslateBy(delta);
3535 if (iff >= 0 && iff < 5)
3545 for (
int i = 0; i < 5; i++) {
3548 while (++track_iter) {
3555 c_life = c_ship->
Life();
3563 c_life = c_shot->
Life();
3565 if (t->
Age() < 0 || c_life == 0) {
3587 for (
int i = 0; ok && i <
ships.
size(); i++) {
3609 for (
int i = 0; i <
ships.
size(); i++) {
3647 for (
int n = 0; n < flight_decks.
size(); n++)
3666 speed = navpt->
Speed();
3673 if (delta.
length() > 25e3) {
3675 dest = ward->
Location() + delta * 25e3;
3687 double etr = dist / speed;
3692 Point trans = unit * (speed * etr);
3728 if (dist > 1 || ward) {
3729 for (
int j = 0; j <
ships.
size(); j++) {
3732 if (ship != test && test->
Mass() >= ship->
Mass()) {
3758 for (
int i = 0; i <
ships.
size(); i++) {
3766 else if (u_loc.
z < -20e3)
3798 static char txt[64];
3802 int h = ( t / 3600000);
3803 int m = ((t - h*3600000) / 60000);
3804 int s = ((t - h*3600000 - m*60000) / 1000);
3805 int e = ( t - h*3600000 - m*60000 - s*1000);
3808 sprintf_s(txt,
"%02d:%02d:%02d.%03d", h,m,s,e);
3810 sprintf_s(txt,
"%02d:%02d.%03d", m,s,e);