38 : id(identity), type(0), team(1), ok(false), active(false), complete(false),
39 star_system(0), start(33 * 3600), stardate(0), target(0), ward(0),
40 current(0), degrees(false)
51 strcpy_s(
path, pname);
53 strcpy_s(
path,
"Missions/");
113 if (elem_index >= 0 && elem_index <
elements.
size()-1) {
127 if (event_index > 0 && event_index <
events.
size()) {
139 if (event_index >= 0 && event_index <
events.
size()-1) {
176 if (element == player_element)
207 if (event->Event() == event_type)
232 strcpy_s(
path, pname);
235 Print(
"\nCan't Load Mission, script unspecified.\n");
258 Print(
"Mission Loaded.\n\n");
276 sprintf_s(err,
"ERROR: could not parse '%s'\n",
filename);
282 if (!file_type || file_type->
value() !=
"MISSION") {
283 sprintf_s(err,
"ERROR: invalid mission file '%s'\n",
filename);
292 char target_name[256];
299 delete term; term = 0;
308 if (defname ==
"name") {
313 else if (defname ==
"desc") {
319 else if (defname ==
"type") {
325 else if (defname ==
"system") {
336 else if (defname ==
"degrees")
339 else if (defname ==
"region")
342 else if (defname ==
"objective") {
348 else if (defname ==
"sitrep") {
354 else if (defname ==
"subtitles") {
361 loader->
LoadBuffer(subtitles_path, block,
true);
368 else if (defname ==
"start")
371 else if (defname ==
"stardate")
374 else if (defname ==
"team")
377 else if (defname ==
"target")
380 else if (defname ==
"ward")
383 else if ((defname ==
"element") ||
384 (defname ==
"ship") ||
385 (defname ==
"station")) {
388 sprintf_s(err,
"ERROR: element struct missing in '%s'\n",
filename);
398 else if (defname ==
"event") {
400 sprintf_s(err,
"ERROR: event struct missing in '%s'\n",
filename);
439 if (content.
length() < 8) {
444 if (!_stricmp(
path,
"mods/missions/")) {
445 CreateDirectory(
"Mods", 0);
446 CreateDirectory(
"Mods/Missions", 0);
449 else if (!_stricmp(
path,
"multiplayer/")) {
450 CreateDirectory(
"Multiplayer", 0);
456 fopen_s(&f, fname,
"w");
458 fwrite(content.
data(), content.
length(), 1, f);
479 bool found_player =
false;
494 sprintf_s(err,
Game::GetText(
"Mission.error.wrong-sector").data(),
501 sprintf_s(err,
Game::GetText(
"Mission.error.extra-player").data(),
527 #define MSN_CHECK(x) if (!_stricmp(n, #x)) result = Mission::x;
572 static int elem_id = 351;
595 if (defname ==
"name")
598 else if (defname ==
"carrier")
601 else if (defname ==
"commander")
604 else if (defname ==
"squadron")
607 else if (defname ==
"path")
610 else if (defname ==
"design") {
620 else if (defname ==
"skin") {
637 else if (defname ==
"mission") {
642 else if (defname ==
"intel") {
647 else if (defname ==
"loc") {
653 else if (defname ==
"rloc") {
661 else if (defname.
indexOf(
"head") == 0) {
676 else if (defname ==
"region" || defname ==
"rgn")
679 else if (defname ==
"iff")
682 else if (defname ==
"count")
685 else if (defname ==
"maint_count")
688 else if (defname ==
"dead_count")
691 else if (defname ==
"player")
694 else if (defname ==
"alert")
697 else if (defname ==
"playable")
700 else if (defname ==
"rogue")
703 else if (defname ==
"invulnerable")
706 else if (defname ==
"command_ai")
709 else if (defname.
indexOf(
"respawn") == 0)
712 else if (defname.
indexOf(
"hold") == 0)
715 else if (defname.
indexOf(
"zone") == 0) {
726 else if (defname ==
"objective") {
738 else if (defname ==
"instr") {
739 Text* obj =
new(__FILE__,__LINE__)
Text;
746 else if (defname ==
"ship") {
761 else if (defname ==
"order" || defname ==
"navpt") {
773 else if (defname ==
"loadout") {
791 else if (element->
design == 0) {
807 static int event_id = 1;
808 static double event_time = 0;
816 if (defname ==
"event") {
821 else if (defname ==
"trigger") {
826 else if (defname ==
"id")
829 else if (defname ==
"time")
832 else if (defname ==
"delay")
835 else if (defname ==
"event_param" || defname ==
"param" || defname ==
"color") {
836 ZeroMemory(event->event_param,
sizeof(event->event_param));
840 event->event_nparams = 1;
844 std::vector<float> plist;
847 for (
int i = 0; i < 10 && i < (int)plist.size(); i++) {
849 event->event_param[i] = (int) f;
850 event->event_nparams = i + 1;
855 else if (defname ==
"trigger_param") {
856 ZeroMemory(event->trigger_param,
sizeof(event->trigger_param));
860 event->trigger_nparams = 1;
864 std::vector<float> plist;
867 for (
int i = 0; i < 10 && i < (int)plist.size(); i++) {
869 event->trigger_param[i] = (int) f;
870 event->trigger_nparams = i + 1;
875 else if (defname ==
"event_ship" || defname ==
"ship")
878 else if (defname ==
"event_source" || defname ==
"source" || defname ==
"font")
881 else if (defname ==
"event_target" || defname ==
"target" || defname ==
"image")
884 else if (defname ==
"event_message" || defname ==
"message") {
891 else if (defname ==
"event_chance" || defname ==
"chance")
894 else if (defname ==
"event_sound" || defname ==
"sound")
897 else if (defname ==
"loc" || defname ==
"vec" || defname ==
"fade")
900 else if (defname ==
"rect")
903 else if (defname ==
"trigger_ship")
906 else if (defname ==
"trigger_target")
911 event->id = event_id++;
912 event->time = event_time;
926 Vec3 loc(-1.0e9f, -1.0e9f, -1.0e9f);
927 Vec3 vel(-1.0e9f, -1.0e9f, -1.0e9f);
929 double heading = -1e9;
930 double integrity = -1;
935 for (i = 0; i < 16; i++)
938 for (i = 0; i < 4; i++)
947 if (defname ==
"name")
950 else if (defname ==
"skin") {
951 if (!element || !element->
design) {
967 else if (defname ==
"regnum")
970 else if (defname ==
"region")
973 else if (defname ==
"loc")
976 else if (defname ==
"velocity")
979 else if (defname ==
"respawns")
982 else if (defname ==
"heading") {
997 else if (defname ==
"integrity")
1000 else if (defname ==
"ammo")
1003 else if (defname ==
"fuel")
1049 Text order_rgn_name;
1059 if (defname ==
"cmd") {
1067 else if (defname ==
"status") {
1075 else if (defname ==
"loc") {
1079 else if (defname ==
"rloc") {
1084 else if (defname ==
"rgn") {
1087 else if (defname ==
"speed") {
1090 else if (defname ==
"formation") {
1093 else if (defname ==
"emcon") {
1096 else if (defname ==
"priority") {
1099 else if (defname ==
"farcast") {
1109 else if (defname ==
"tgt") {
1112 else if (defname ==
"tgt_desc") {
1115 else if (defname.
indexOf(
"hold") == 0) {
1123 if (order_rgn_name.
length() > 0)
1124 rgn = order_rgn_name;
1133 tgt_desc = tgt_desc +
" " + tgt_name;
1162 ZeroMemory(stations,
sizeof(stations));
1170 if (defname ==
"ship") {
1173 else if (defname ==
"name") {
1176 else if (defname ==
"stations") {
1187 for (
int i = 0; i < 16; i++)
1197 RLoc* rloc =
new(__FILE__,__LINE__)
RLoc;
1201 double dex_var = 5e3;
1203 double az_var = 3.1415;
1205 double el_var = 0.1;
1213 if (defname ==
"dex") {
1217 else if (defname ==
"dex_var") {
1221 else if (defname ==
"az") {
1226 else if (defname ==
"az_var") {
1231 else if (defname ==
"el") {
1236 else if (defname ==
"el_var") {
1241 else if (defname ==
"loc") {
1246 else if (defname ==
"ref") {
1250 int sep = refstr.
indexOf(
':');
1257 if (elem_name ==
"this")
1263 int index = atoi(nav_name)-1;
1269 ref = &elem->
NavList()[index]->GetRLoc();
1280 if (refstr ==
"this")
1305 case PATROL:
return "Patrol";
1306 case SWEEP:
return "Sweep";
1309 case AIR_SWEEP:
return "Airborne Sweep";
1311 case STRIKE:
return "Strike";
1312 case ASSAULT:
return "Assault";
1313 case DEFEND:
return "Defend";
1314 case ESCORT:
return "Escort";
1318 case INTEL:
return "Intel";
1319 case SCOUT:
return "Scout";
1320 case RECON:
return "Recon";
1322 case FLEET:
return "Fleet";
1326 case CARGO:
return "Cargo";
1329 case OTHER:
return "Misc";
1338 Text s =
"MISSION\n\nname: \"";
1342 s +=
"\"\ndesc: \"";
1346 s +=
"\"\ntype: \"";
1350 while (++sys_iter) {
1354 s +=
"\"\nsystem: \"";
1359 s +=
"\"\nsystem: \"";
1373 bool region_set =
false;
1374 if (player_elem && *player_elem) {
1378 if (e->
Name() == player_elem) {
1380 sprintf_s(buf,
"team: %d\n", e->
GetIFF());
1402 s +=
"objective: \"";
1419 s +=
"degrees: true\n\n";
1424 s +=
"element: {\n";
1448 s +=
" squadron: \"";
1454 s +=
" carrier: \"";
1460 s +=
" commander: \"";
1465 s +=
" mission: \"";
1475 sprintf_s(buffer,
" count: %d\n", elem->
Count());
1479 sprintf_s(buffer,
" maint_count: %d\n", elem->
MaintCount());
1484 sprintf_s(buffer,
" dead_count: %d\n", elem->
DeadCount());
1489 sprintf_s(buffer,
" respawn_count: %d\n", elem->
RespawnCount());
1494 sprintf_s(buffer,
" hold_time: %d\n", elem->
HoldTime());
1499 sprintf_s(buffer,
" zone_lock: %d\n", elem->
ZoneLock());
1504 s +=
" alert: true\n";
1508 sprintf_s(buffer,
" command_ai:%d\n", elem->
CommandAI());
1512 sprintf_s(buffer,
" iff: %d\n", elem->
GetIFF());
1516 if (elem->
Name() == player_elem) {
1517 if (player_index < 1)
1520 sprintf_s(buffer,
" player: %d\n", player_index);
1527 sprintf_s(buffer,
" player: %d\n", elem->
Player());
1534 s +=
" playable: true\n";
1536 s +=
" playable: false\n";
1544 sprintf_s(buffer,
" loc: (%.0f, %.0f, %.0f)\n",
1551 sprintf_s(buffer,
" head: %d\n", (
int) (elem->
Heading()/
DEGREES));
1559 while (++load_iter) {
1562 sprintf_s(buffer,
" loadout: { ship: %d, ", load->
GetShip());
1573 for (
int i = 0; i < 16; i++) {
1574 sprintf_s(buffer,
"%d", load->
GetStation(i));
1590 while (++obj_iter) {
1593 s +=
" objective: { cmd: ";
1605 while (++nav_iter) {
1608 s +=
" navpt: { cmd: ";
1619 sprintf_s(buffer,
", loc: (%.0f, %.0f, %.0f), speed: %d",
1633 sprintf_s(buffer,
", hold: %d", (
int) inst->
HoldTime());
1638 s +=
", farcast: true";
1642 sprintf_s(buffer,
", formation: %d", (
int) inst->
Formation());
1647 sprintf_s(buffer,
", priority: %d", (
int) inst->
Priority());
1671 s +=
"\n ship: {\n";
1692 sprintf_s(buffer,
" loc: (%.0f, %.0f, %.0f),\n",
1700 sprintf_s(buffer,
" velocity: (%.1f, %.1f, %.1f),\n",
1708 sprintf_s(buffer,
" respawns: %d,\n", ship->
Respawns());
1713 sprintf_s(buffer,
" heading: %d,\n", (
int) (ship->
Heading()/
DEGREES));
1718 sprintf_s(buffer,
" integrity: %d,\n", (
int) ship->
Integrity());
1722 if (ship->
Decoys() > -1) {
1723 sprintf_s(buffer,
" decoys: %d,\n", ship->
Decoys());
1727 if (ship->
Probes() > -1) {
1728 sprintf_s(buffer,
" probes: %d,\n", ship->
Probes());
1732 if (ship->
Ammo()[0] > -10) {
1735 for (
int i = 0; i < 16; i++) {
1736 sprintf_s(buffer,
"%d", ship->
Ammo()[i]);
1746 if (ship->
Fuel()[0] > -10) {
1749 for (
int i = 0; i < 4; i++) {
1750 sprintf_s(buffer,
"%d", ship->
Fuel()[i]);
1774 sprintf_s(buffer,
"%d", event->EventID());
1777 sprintf_s(buffer,
"%.1f", event->Time());
1780 sprintf_s(buffer,
"%.1f", event->Delay());
1783 s +=
event->EventName();
1786 if (event->EventShip().length()) {
1787 s +=
" event_ship: \"";
1792 if (event->EventSource().length()) {
1793 s +=
" event_source: \"";
1798 if (event->EventTarget().length()) {
1799 s +=
" event_target: \"";
1804 if (event->EventSound().length()) {
1805 s +=
" event_sound: \"";
1810 if (event->EventMessage().length()) {
1811 s +=
" event_message: \"";
1816 if (event->EventParam()) {
1817 sprintf_s(buffer,
"%d", event->EventParam());
1818 s +=
" event_param: ";
1823 if (event->EventChance()) {
1824 sprintf_s(buffer,
"%d", event->EventChance());
1825 s +=
" event_chance: ";
1830 s +=
" trigger: \"";
1831 s +=
event->TriggerName();
1834 if (event->TriggerShip().length()) {
1835 s +=
" trigger_ship: \"";
1840 if (event->TriggerTarget().length()) {
1841 s +=
" trigger_target: \"";
1846 Text param_str =
event->TriggerParamStr();
1848 if (param_str.
length()) {
1849 s +=
" trigger_param: ";
1864 static int elem_idkey = 1;
1867 : id (elem_idkey++),
1868 elem_id(0), design(0), skin(0), count(1), maint_count(0), dead_count(0),
1869 IFF_code(0), player(0), alert(false), playable(false), rogue(false), invulnerable(false),
1870 respawns(0), hold_time(0), zone_lock(0), heading(0), mission_role(
Mission::OTHER),
1871 intel(
Intel::SECRET), command_ai(1), combat_group(0), combat_unit(0)
1896 if (index < 0 || index >=
ships.
size()) {
1899 sprintf_s(sname,
"%s %d", (
const char*)
name, index+1);
1913 if (index < 0 || index >=
ships.
size()) {
1935 int design_type = 0;
1945 int design_type = 0;
1955 int design_type = 0;
1965 int design_type = 0;
2059 if (navpt.
value() == n)
2072 for (
int i = 0; i < 16; i++)
2118 if (index >= 0 && index < 16)
2127 if (index >= 0 && index < 16)
2128 load[index] = selection;
2135 : loc(-1e9, -1e9, -1e9), respawns(0), heading(0), integrity(100),
2136 decoys(-10), probes(-10), skin(0)
2138 for (
int i = 0; i < 16; i++)
2141 for (
int i = 0; i < 4; i++)
2149 for (
int i = 0; i < 16; i++)
2158 for (
int i = 0; i < 4; i++)