summaryrefslogtreecommitdiffhomepage
path: root/Stars45/CombatZone.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Stars45/CombatZone.cpp')
-rw-r--r--Stars45/CombatZone.cpp302
1 files changed, 151 insertions, 151 deletions
diff --git a/Stars45/CombatZone.cpp b/Stars45/CombatZone.cpp
index d829074..4018e41 100644
--- a/Stars45/CombatZone.cpp
+++ b/Stars45/CombatZone.cpp
@@ -1,19 +1,19 @@
/* Project Starshatter 4.5
- Destroyer Studios LLC
- Copyright © 1997-2004. All Rights Reserved.
+ Destroyer Studios LLC
+ Copyright © 1997-2004. All Rights Reserved.
- SUBSYSTEM: Stars.exe
- FILE: CombatZone.cpp
- AUTHOR: John DiCamillo
+ SUBSYSTEM: Stars.exe
+ FILE: CombatZone.cpp
+ AUTHOR: John DiCamillo
- OVERVIEW
- ========
- CombatZone is used by the dynamic campaign strategy
- and logistics algorithms to assign forces to locations
- within the campaign. A CombatZone is a collection of
- closely related sectors, and the assets contained
- within them.
+ OVERVIEW
+ ========
+ CombatZone is used by the dynamic campaign strategy
+ and logistics algorithms to assign forces to locations
+ within the campaign. A CombatZone is a collection of
+ closely related sectors, and the assets contained
+ within them.
*/
#include "MemDebug.h"
@@ -36,8 +36,8 @@ CombatZone::CombatZone()
CombatZone::~CombatZone()
{
- regions.destroy();
- forces.destroy();
+ regions.destroy();
+ forces.destroy();
}
// +--------------------------------------------------------------------+
@@ -45,7 +45,7 @@ CombatZone::~CombatZone()
void
CombatZone::Clear()
{
- forces.destroy();
+ forces.destroy();
}
// +--------------------------------------------------------------------+
@@ -53,35 +53,35 @@ CombatZone::Clear()
void
CombatZone::AddGroup(CombatGroup* group)
{
- if (group) {
- int iff = group->GetIFF();
- ZoneForce* f = FindForce(iff);
- f->AddGroup(group);
- group->SetCurrentZone(this);
- }
+ if (group) {
+ int iff = group->GetIFF();
+ ZoneForce* f = FindForce(iff);
+ f->AddGroup(group);
+ group->SetCurrentZone(this);
+ }
}
void
CombatZone::RemoveGroup(CombatGroup* group)
{
- if (group) {
- int iff = group->GetIFF();
- ZoneForce* f = FindForce(iff);
- f->RemoveGroup(group);
- group->SetCurrentZone(0);
- }
+ if (group) {
+ int iff = group->GetIFF();
+ ZoneForce* f = FindForce(iff);
+ f->RemoveGroup(group);
+ group->SetCurrentZone(0);
+ }
}
bool
CombatZone::HasGroup(CombatGroup* group)
{
- if (group) {
- int iff = group->GetIFF();
- ZoneForce* f = FindForce(iff);
- return f->HasGroup(group);
- }
+ if (group) {
+ int iff = group->GetIFF();
+ ZoneForce* f = FindForce(iff);
+ return f->HasGroup(group);
+ }
- return false;
+ return false;
}
// +--------------------------------------------------------------------+
@@ -89,12 +89,12 @@ CombatZone::HasGroup(CombatGroup* group)
void
CombatZone::AddRegion(const char* rgn)
{
- if (rgn && *rgn) {
- regions.append(new (__FILE__,__LINE__) Text(rgn));
+ if (rgn && *rgn) {
+ regions.append(new (__FILE__,__LINE__) Text(rgn));
- if (name.length() < 1)
- name = rgn;
- }
+ if (name.length() < 1)
+ name = rgn;
+ }
}
// +--------------------------------------------------------------------+
@@ -102,12 +102,12 @@ CombatZone::AddRegion(const char* rgn)
bool
CombatZone::HasRegion(const char* rgn)
{
- if (rgn && *rgn && regions.size()) {
- Text test(rgn);
- return regions.contains(&test);
- }
+ if (rgn && *rgn && regions.size()) {
+ Text test(rgn);
+ return regions.contains(&test);
+ }
- return false;
+ return false;
}
// +--------------------------------------------------------------------+
@@ -115,13 +115,13 @@ CombatZone::HasRegion(const char* rgn)
ZoneForce*
CombatZone::FindForce(int iff)
{
- ListIter<ZoneForce> f = forces;
- while (++f) {
- if (f->GetIFF() == iff)
- return f.value();
- }
+ ListIter<ZoneForce> f = forces;
+ while (++f) {
+ if (f->GetIFF() == iff)
+ return f.value();
+ }
- return MakeForce(iff);
+ return MakeForce(iff);
}
// +--------------------------------------------------------------------+
@@ -129,9 +129,9 @@ CombatZone::FindForce(int iff)
ZoneForce*
CombatZone::MakeForce(int iff)
{
- ZoneForce* f = new(__FILE__,__LINE__) ZoneForce(iff);
- forces.append(f);
- return f;
+ ZoneForce* f = new(__FILE__,__LINE__) ZoneForce(iff);
+ forces.append(f);
+ return f;
}
// +--------------------------------------------------------------------+
@@ -141,142 +141,142 @@ static List<CombatZone> zonelist;
List<CombatZone>&
CombatZone::Load(const char* filename)
{
- zonelist.clear();
-
- DataLoader* loader = DataLoader::GetLoader();
- BYTE* block = 0;
-
- loader->LoadBuffer(filename, block, true);
- Parser parser(new(__FILE__,__LINE__) BlockReader((const char*) block));
-
- Term* term = parser.ParseTerm();
-
- if (!term) {
- return zonelist;
- }
- else {
- TermText* file_type = term->isText();
- if (!file_type || file_type->value() != "ZONES") {
- return zonelist;
- }
- }
-
- do {
- delete term; term = 0;
- term = parser.ParseTerm();
-
- if (term) {
- TermDef* def = term->isDef();
- if (def) {
- if (def->name()->value() == "zone") {
- if (!def->term() || !def->term()->isStruct()) {
- ::Print("WARNING: zone struct missing in '%s%s'\n", loader->GetDataPath(), filename);
- }
- else {
- TermStruct* val = def->term()->isStruct();
-
- CombatZone* zone = new(__FILE__,__LINE__) CombatZone();
- char rgn[64];
- ZeroMemory(rgn, sizeof(rgn));
-
- for (int i = 0; i < val->elements()->size(); i++) {
- TermDef* pdef = val->elements()->at(i)->isDef();
- if (pdef) {
- if (pdef->name()->value() == "region") {
- GetDefText(rgn, pdef, filename);
- zone->AddRegion(rgn);
- }
- else if (pdef->name()->value() == "system") {
- GetDefText(rgn, pdef, filename);
- zone->system = rgn;
- }
- }
- }
-
- zonelist.append(zone);
- }
- }
- }
- }
- }
- while (term);
-
- loader->ReleaseBuffer(block);
-
- return zonelist;
+ zonelist.clear();
+
+ DataLoader* loader = DataLoader::GetLoader();
+ BYTE* block = 0;
+
+ loader->LoadBuffer(filename, block, true);
+ Parser parser(new(__FILE__,__LINE__) BlockReader((const char*) block));
+
+ Term* term = parser.ParseTerm();
+
+ if (!term) {
+ return zonelist;
+ }
+ else {
+ TermText* file_type = term->isText();
+ if (!file_type || file_type->value() != "ZONES") {
+ return zonelist;
+ }
+ }
+
+ do {
+ delete term; term = 0;
+ term = parser.ParseTerm();
+
+ if (term) {
+ TermDef* def = term->isDef();
+ if (def) {
+ if (def->name()->value() == "zone") {
+ if (!def->term() || !def->term()->isStruct()) {
+ ::Print("WARNING: zone struct missing in '%s%s'\n", loader->GetDataPath(), filename);
+ }
+ else {
+ TermStruct* val = def->term()->isStruct();
+
+ CombatZone* zone = new(__FILE__,__LINE__) CombatZone();
+ char rgn[64];
+ ZeroMemory(rgn, sizeof(rgn));
+
+ for (int i = 0; i < val->elements()->size(); i++) {
+ TermDef* pdef = val->elements()->at(i)->isDef();
+ if (pdef) {
+ if (pdef->name()->value() == "region") {
+ GetDefText(rgn, pdef, filename);
+ zone->AddRegion(rgn);
+ }
+ else if (pdef->name()->value() == "system") {
+ GetDefText(rgn, pdef, filename);
+ zone->system = rgn;
+ }
+ }
+ }
+
+ zonelist.append(zone);
+ }
+ }
+ }
+ }
+ }
+ while (term);
+
+ loader->ReleaseBuffer(block);
+
+ return zonelist;
}
// +--------------------------------------------------------------------+
ZoneForce::ZoneForce(int i)
{
- iff = i;
+ iff = i;
- for (int n = 0; n < 8; n++)
- need[n] = 0;
+ for (int n = 0; n < 8; n++)
+ need[n] = 0;
}
void
ZoneForce::AddGroup(CombatGroup* group)
{
- if (group)
- groups.append(group);
+ if (group)
+ groups.append(group);
}
void
ZoneForce::RemoveGroup(CombatGroup* group)
{
- if (group)
- groups.remove(group);
+ if (group)
+ groups.remove(group);
}
bool
ZoneForce::HasGroup(CombatGroup* group)
{
- if (group)
- return groups.contains(group);
+ if (group)
+ return groups.contains(group);
- return false;
+ return false;
}
int
ZoneForce::GetNeed(int group_type) const
{
- switch (group_type) {
- case CombatGroup::CARRIER_GROUP: return need[0];
- case CombatGroup::BATTLE_GROUP: return need[1];
- case CombatGroup::DESTROYER_SQUADRON: return need[2];
- case CombatGroup::ATTACK_SQUADRON: return need[3];
- case CombatGroup::FIGHTER_SQUADRON: return need[4];
- case CombatGroup::INTERCEPT_SQUADRON: return need[5];
- }
-
- return 0;
+ switch (group_type) {
+ case CombatGroup::CARRIER_GROUP: return need[0];
+ case CombatGroup::BATTLE_GROUP: return need[1];
+ case CombatGroup::DESTROYER_SQUADRON: return need[2];
+ case CombatGroup::ATTACK_SQUADRON: return need[3];
+ case CombatGroup::FIGHTER_SQUADRON: return need[4];
+ case CombatGroup::INTERCEPT_SQUADRON: return need[5];
+ }
+
+ return 0;
}
void
ZoneForce::SetNeed(int group_type, int needed)
{
- switch (group_type) {
- case CombatGroup::CARRIER_GROUP: need[0] = needed; break;
- case CombatGroup::BATTLE_GROUP: need[1] = needed; break;
- case CombatGroup::DESTROYER_SQUADRON: need[2] = needed; break;
- case CombatGroup::ATTACK_SQUADRON: need[3] = needed; break;
- case CombatGroup::FIGHTER_SQUADRON: need[4] = needed; break;
- case CombatGroup::INTERCEPT_SQUADRON: need[5] = needed; break;
- }
+ switch (group_type) {
+ case CombatGroup::CARRIER_GROUP: need[0] = needed; break;
+ case CombatGroup::BATTLE_GROUP: need[1] = needed; break;
+ case CombatGroup::DESTROYER_SQUADRON: need[2] = needed; break;
+ case CombatGroup::ATTACK_SQUADRON: need[3] = needed; break;
+ case CombatGroup::FIGHTER_SQUADRON: need[4] = needed; break;
+ case CombatGroup::INTERCEPT_SQUADRON: need[5] = needed; break;
+ }
}
void
ZoneForce::AddNeed(int group_type, int needed)
{
- switch (group_type) {
- case CombatGroup::CARRIER_GROUP: need[0] += needed; break;
- case CombatGroup::BATTLE_GROUP: need[1] += needed; break;
- case CombatGroup::DESTROYER_SQUADRON: need[2] += needed; break;
- case CombatGroup::ATTACK_SQUADRON: need[3] += needed; break;
- case CombatGroup::FIGHTER_SQUADRON: need[4] += needed; break;
- case CombatGroup::INTERCEPT_SQUADRON: need[5] += needed; break;
- }
+ switch (group_type) {
+ case CombatGroup::CARRIER_GROUP: need[0] += needed; break;
+ case CombatGroup::BATTLE_GROUP: need[1] += needed; break;
+ case CombatGroup::DESTROYER_SQUADRON: need[2] += needed; break;
+ case CombatGroup::ATTACK_SQUADRON: need[3] += needed; break;
+ case CombatGroup::FIGHTER_SQUADRON: need[4] += needed; break;
+ case CombatGroup::INTERCEPT_SQUADRON: need[5] += needed; break;
+ }
}