51 : mission(0), start(0), type(0), id(0), min_rank(0), max_rank(0),
52 action_id(0), action_status(0), exec_once(0),
95 : mission_type(0), group_type(0), index(0)
106 static Campaign* current_campaign = 0;
111 : campaign_id(id), name(n), mission_id(-1), mission(0), net_mission(0),
112 scripted(false), sequential(false), time(0), startTime(0), loadTime(0),
113 player_group(0), player_unit(0), status(CAMPAIGN_INIT), lockout(0),
114 loaded_from_savegame(false)
121 : campaign_id(id), name(n), mission_id(-1), mission(0), net_mission(0),
122 scripted(false), sequential(false), time(0), startTime(0), loadTime(0),
123 player_group(0), player_unit(0), status(CAMPAIGN_INIT), lockout(0),
124 loaded_from_savegame(false)
136 image[i].ClearImage();
157 for (
int i = 1; i < 100; i++) {
159 sprintf_s(path,
"Campaigns/%02d/", i);
164 if (loader->
FindFile(
"campaign.def")) {
166 sprintf_s(txt,
"Dynamic Campaign %02d", i);
167 c =
new(__FILE__,__LINE__)
Campaign(i, txt);
178 current_campaign = c;
195 Print(
"Campaign::Close() - destroying all campaigns\n");
196 current_campaign = 0;
203 return current_campaign;
212 while (++iter && !c) {
218 Print(
"Campaign: Selected '%s'\n", c->
Name());
219 current_campaign = c;
222 Print(
"Campaign: could not find '%s'\n", name);
233 if (name && *name && path && *path) {
242 Print(
"Campaign: custom campaign '%s' already exists.\n", name);
252 Print(
"Campaign: created custom campaign %d '%s'\n",
id, name);
269 for (
int i = 0; i < campaigns.
size(); i++) {
301 if ( !
events[i]->Visited())
354 for (
int n = 0; !found && n <
systems.
size(); n++) {
365 if (loader->
FindFile(
"campaign.def"))
375 if (loader->
FindFile(
"missions.def")) {
381 if (loader->
FindFile(
"templates.def")) {
396 if (loader->
FindFile(
"image.pcx")) {
420 image[i].ClearImage();
431 const char*
filename =
"campaign.def";
445 if (!file_type || file_type->
value() !=
"CAMPAIGN") {
451 delete term; term = 0;
466 else if (def->
name()->
value() ==
"desc") {
475 else if (def->
name()->
value() ==
"situation") {
484 else if (def->
name()->
value() ==
"orders") {
493 else if (def->
name()->
value() ==
"scripted") {
498 else if (def->
name()->
value() ==
"sequential") {
503 else if (full && def->
name()->
value() ==
"combatant") {
515 ZeroMemory(name,
sizeof(name));
526 clone = force->
Clone(
false);
529 else if (pdef->
name()->
value() ==
"group") {
546 else if (full && def->
name()->
value() ==
"action") {
569 const char* filename)
588 else if (pdef->
name()->
value() ==
"id") {
621 Vec3 loc(0.0f, 0.0f, 0.0f);
634 int probability = 100;
650 else if (pdef->
name()->
value() ==
"type") {
655 else if (pdef->
name()->
value() ==
"subtype") {
675 else if (pdef->
name()->
value() ==
"opp_type") {
689 else if (pdef->
name()->
value() ==
"source") {
694 else if (pdef->
name()->
value() ==
"team") {
697 else if (pdef->
name()->
value() ==
"iff") {
700 else if (pdef->
name()->
value() ==
"count") {
721 else if (pdef->
name()->
value() ==
"min_rank") {
731 else if (pdef->
name()->
value() ==
"max_rank") {
741 else if (pdef->
name()->
value() ==
"delay") {
744 else if (pdef->
name()->
value() ==
"probability") {
747 else if (pdef->
name()->
value() ==
"asset_type") {
752 else if (pdef->
name()->
value() ==
"target_type") {
757 else if (pdef->
name()->
value() ==
"location" ||
761 else if (pdef->
name()->
value() ==
"system" ||
765 else if (pdef->
name()->
value() ==
"region" ||
770 else if (pdef->
name()->
value() ==
"file") {
773 else if (pdef->
name()->
value() ==
"image") {
776 else if (pdef->
name()->
value() ==
"scene") {
779 else if (pdef->
name()->
value() ==
"text") {
783 else if (pdef->
name()->
value() ==
"asset_id") {
786 else if (pdef->
name()->
value() ==
"target_id") {
789 else if (pdef->
name()->
value() ==
"target_iff") {
793 else if (pdef->
name()->
value() ==
"asset_kill") {
795 action =
new(__FILE__,__LINE__)
CombatAction(
id, type, subtype, team);
804 else if (pdef->
name()->
value() ==
"target_kill") {
806 action =
new(__FILE__,__LINE__)
CombatAction(
id, type, subtype, team);
815 else if (pdef->
name()->
value() ==
"req") {
817 action =
new(__FILE__,__LINE__)
CombatAction(
id, type, subtype, team);
820 ::Print(
"WARNING: action req struct missing in '%s'\n", filename);
840 if (pdef2->
name()->
value() ==
"action") {
843 else if (pdef2->
name()->
value() ==
"status") {
848 else if (pdef2->
name()->
value() ==
"not") {
852 else if (pdef2->
name()->
value() ==
"c1") {
857 else if (pdef2->
name()->
value() ==
"c2") {
862 else if (pdef2->
name()->
value() ==
"comp") {
867 else if (pdef2->
name()->
value() ==
"score") {
870 else if (pdef2->
name()->
value() ==
"intel") {
880 else if (pdef2->
name()->
value() ==
"group_type") {
885 else if (pdef2->
name()->
value() ==
"group_id") {
905 action =
new(__FILE__,__LINE__)
CombatAction(
id, type, subtype, team);
946 clone_parent =
CloneOver(force, clone, orig_parent);
951 new_clone = group->
Clone(
false);
969 const char*
filename =
"Missions.def";
983 if (!file_type || file_type->
value() !=
"MISSIONLIST") {
984 ::Print(
"WARNING: invalid mission list file '%s'\n", filename);
991 delete term; term = 0;
999 ::Print(
"WARNING: mission struct missing in '%s'\n", filename);
1013 ZeroMemory(script,
sizeof(script));
1015 strcpy_s(system,
"Unknown");
1016 strcpy_s(region,
"Unknown");
1024 else if (pdef->
name()->
value() ==
"name") {
1029 else if (pdef->
name()->
value() ==
"desc") {
1035 else if (pdef->
name()->
value() ==
"start")
1038 else if (pdef->
name()->
value() ==
"system")
1041 else if (pdef->
name()->
value() ==
"region")
1044 else if (pdef->
name()->
value() ==
"script")
1047 else if (pdef->
name()->
value() ==
"type") {
1063 info->
start = start;
1095 for (
int i = 0; i < files.
size(); i++) {
1096 Text file = *files[i];
1107 if (strstr((
const char*) block,
"MISSION") == (
const char*) block) {
1110 Text system =
"Unknown";
1111 Text region =
"Unknown";
1120 Print(
"ERROR: could not parse '%s'\n", filename);
1125 if (!file_type || file_type->
value() !=
"MISSION") {
1126 Print(
"ERROR: invalid mission file '%s'\n", filename);
1133 delete term; term = 0;
1144 else if (def->
name()->
value() ==
"type") {
1153 else if (def->
name()->
value() ==
"desc") {
1159 else if (def->
name()->
value() ==
"system")
1162 else if (def->
name()->
value() ==
"region")
1165 else if (def->
name()->
value() ==
"start")
1174 if (strstr(filename,
"custom") == filename) {
1175 sscanf_s(filename+6,
"%d", &msn_id);
1180 else if (msn_id < 1) {
1193 info->
start = start;
1205 Print(
"Invalid Custom Mission File: '%s'\n", filename);
1224 const char*
filename =
"Templates.def";
1238 if (!file_type || file_type->
value() !=
"TEMPLATELIST") {
1239 ::Print(
"WARNING: invalid template list file '%s'\n", filename);
1246 delete term; term = 0;
1252 if (def->
name()->
value() ==
"mission") {
1254 ::Print(
"WARNING: mission struct missing in '%s'\n", filename);
1269 int action_status = 0;
1272 int start_after = 0;
1284 else if (pdef->
name()->
value() ==
"name")
1287 else if (pdef->
name()->
value() ==
"script")
1293 else if (pdef->
name()->
value() ==
"type") {
1299 else if (pdef->
name()->
value() ==
"group") {
1305 else if (pdef->
name()->
value() ==
"min_rank")
1308 else if (pdef->
name()->
value() ==
"max_rank")
1311 else if (pdef->
name()->
value() ==
"action_id")
1314 else if (pdef->
name()->
value() ==
"action_status")
1317 else if (pdef->
name()->
value() ==
"exec_once")
1347 info->
type = msn_type;
1434 ::Print(
"Campaign::SetPlayerGroup(%s)\n", pg ? pg->
Name().
data() :
"0");
1445 ::Print(
" destroying mission list...\n");
1455 ::Print(
"Campaign::SetPlayerUnit(%s)\n", unit ? unit->
Name().
data() :
"0");
1468 ::Print(
" destroying mission list...\n");
1500 if (!strcmp(c->
Name(), cname))
1519 ::Print(
"ERROR - Campaign::GetMission(%d) invalid mission id\n",
id);
1534 ::Print(
"Campaign::GetMission(%d) loading mission...\n",
id);
1543 ::Print(
"Campaign::GetMission(%d) generating sitrep...\n",
id);
1549 ::Print(
"Campaign::GetMission(%d) could not find/load mission.\n",
id);
1562 if (!filename || !*filename) {
1563 ::Print(
"ERROR - Campaign::GetMissionByFile() invalid filename\n");
1577 if (m->
script == filename)
1585 ::Print(
"Campaign::GetMission(%d) loading mission...\n",
id);
1594 ::Print(
"Campaign::GetMission(%d) generating sitrep...\n",
id);
1600 ::Print(
"Campaign::GetMission(%d) could not find/load mission.\n",
id);
1609 info->
name =
"New Custom Mission";
1641 sprintf_s(filename,
"custom%03d.def", maxid+1);
1646 info->
name =
"New Custom Mission";
1663 ::Print(
"ERROR - Campaign::DeleteMission(%d) invalid mission id\n",
id);
1678 char full_path[256];
1685 DeleteFile(full_path);
1690 ::Print(
"ERROR - Campaign::DeleteMission(%d) could not find mission\n",
id);
1698 ::Print(
"ERROR - Campaign::GetMissionInfo(%d) invalid mission id\n",
id);
1718 ::Print(
"ERROR - Campaign::GetMissionInfo(%d) could not find mission\n",
id);
1792 while (!info && tries < msize) {
1794 int index = templates->
index;
1800 templates->
index = index + 1;
1827 if (
templates[i]->mission_type == msn_type &&
1840 ::Print(
"Campaign::SetMissionId(%d)\n",
id);
1906 ::Print(
"Campaign::Start()\n");
1927 bool completed =
false;
1931 ::Print(
"Campaign::ExecFrame() completed mission %d '%s'\n", m->
id, m->
name.
data());
1937 ::Print(
"Campaign::ExecFrame() destroying mission list after completion...\n");
1955 ::Print(
"Campaign::ExecFrame() deleting expired mission %d start: %d current: %d\n",
2060 ::Print(
" current time: %s\n", buffer);
2063 ::Print(
" mission start: %s\n", buffer);
2072 ::Print(
"Campaign::RollbackMission()\n");
2087 ::Print(
" current time: %d\n", (
int) current_time);
2133 if (g->
Type() == type && g->
GetID() == id)
2139 while (++subgroup && !result)
2140 result = FindGroup(subgroup.
value(), type, id);
2151 while (++combatant && !result) {
2152 if (combatant->
GetIFF() == iff) {
2172 FindGroups(subgroup.
value(), type, near_group, groups);
2182 while (++combatant) {
2183 if (combatant->
GetIFF() == iff) {
2184 FindGroups(combatant->
GetForce(), type, near_group, groups);
2188 if (groups.
size() > 0) {
2190 if (index >= groups.
size()) index = groups.
size() - 1;
2191 result = groups[index];
2212 FindStrikeTargets(subgroup.
value(), strike_group, groups);
2223 while (++combatant) {
2224 if (combatant->
GetIFF() != 0 && combatant->
GetIFF() != iff) {
2225 FindStrikeTargets(combatant->
GetForce(), strike_group, groups);
2229 if (groups.
size() > 0) {
2230 int index = rand() % groups.
size();
2231 result = groups[index];
2270 score_us += c->
Score();
2272 score_them += c->
Score();
2277 score_them += c->
Score();
2279 score_us += c->
Score();
2284 return score_us - score_them;
2303 ::Print(
"Campaign::SetStatus() destroying mission list at campaign end\n");
2326 GetCombatUnits(g2, units);
2340 if (iff < 0 || c->GetIFF() == iff) {
2341 GetCombatUnits(c->
GetForce(), units);
2345 return units.
size();