summaryrefslogtreecommitdiffhomepage
path: root/StarsEx/CombatEvent.cpp
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2022-04-01 21:23:39 +0200
committerAki <please@ignore.pl>2022-04-01 21:23:39 +0200
commit3c487c5cd69c53d6fea948643c0a76df03516605 (patch)
tree72730c7b8b26a5ef8fc9a987ec4c16129efd5aac /StarsEx/CombatEvent.cpp
parent8f353abd0bfe18baddd8a8250ab7c4f2d1c83a6e (diff)
downloadstarshatter-3c487c5cd69c53d6fea948643c0a76df03516605.zip
starshatter-3c487c5cd69c53d6fea948643c0a76df03516605.tar.gz
starshatter-3c487c5cd69c53d6fea948643c0a76df03516605.tar.bz2
Moved Stars45 to StarsEx
Diffstat (limited to 'StarsEx/CombatEvent.cpp')
-rw-r--r--StarsEx/CombatEvent.cpp151
1 files changed, 151 insertions, 0 deletions
diff --git a/StarsEx/CombatEvent.cpp b/StarsEx/CombatEvent.cpp
new file mode 100644
index 0000000..8c02142
--- /dev/null
+++ b/StarsEx/CombatEvent.cpp
@@ -0,0 +1,151 @@
+/* Starshatter: The Open Source Project
+ Copyright (c) 2021-2022, Starshatter: The Open Source Project Contributors
+ Copyright (c) 2011-2012, Starshatter OpenSource Distribution Contributors
+ Copyright (c) 1997-2006, Destroyer Studios LLC.
+
+ AUTHOR: John DiCamillo
+
+
+ OVERVIEW
+ ========
+ A significant (newsworthy) event in the dynamic campaign.
+*/
+
+#include "CombatEvent.h"
+#include "CombatGroup.h"
+#include "Campaign.h"
+#include "Player.h"
+#include "ShipDesign.h"
+#include "Ship.h"
+
+#include "Term.h"
+#include "ParseUtil.h"
+#include "FormatUtil.h"
+#include "DataLoader.h"
+
+// +----------------------------------------------------------------------+
+
+CombatEvent::CombatEvent(Campaign* c, int typ, int tim, int tem,
+int src, const char* rgn)
+: campaign(c), type(typ), time(tim), team(tem), source(src),
+region(rgn), points(0), visited(false)
+{ }
+
+// +----------------------------------------------------------------------+
+
+const char*
+CombatEvent::SourceName() const
+{
+ return SourceName(source);
+}
+
+// +----------------------------------------------------------------------+
+
+const char*
+CombatEvent::TypeName() const
+{
+ return TypeName(type);
+}
+
+// +----------------------------------------------------------------------+
+
+const char*
+CombatEvent::SourceName(int n)
+{
+ switch (n) {
+ case FORCOM: return "FORCOM";
+ case TACNET: return "TACNET";
+ case INTEL: return "SECURE";
+ case MAIL: return "Mail";
+ case NEWS: return "News";
+ }
+
+ return "Unknown";
+}
+
+int
+CombatEvent::SourceFromName(const char* n)
+{
+ for (int i = FORCOM; i <= NEWS; i++)
+ if (!_stricmp(n, SourceName(i)))
+ return i;
+
+ return -1;
+}
+
+// +----------------------------------------------------------------------+
+
+const char*
+CombatEvent::TypeName(int n)
+{
+ switch (n) {
+ case ATTACK: return "ATTACK";
+ case DEFEND: return "DEFEND";
+ case MOVE_TO: return "MOVE_TO";
+ case CAPTURE: return "CAPTURE";
+ case STRATEGY: return "STRATEGY";
+ case STORY: return "STORY";
+ case CAMPAIGN_START: return "CAMPAIGN_START";
+ case CAMPAIGN_END: return "CAMPAIGN_END";
+ case CAMPAIGN_FAIL: return "CAMPAIGN_FAIL";
+ }
+
+ return "Unknown";
+}
+
+int
+CombatEvent::TypeFromName(const char* n)
+{
+ for (int i = ATTACK; i <= CAMPAIGN_FAIL; i++)
+ if (!_stricmp(n, TypeName(i)))
+ return i;
+
+ return -1;
+}
+
+// +----------------------------------------------------------------------+
+
+void
+CombatEvent::Load()
+{
+ DataLoader* loader = DataLoader::GetLoader();
+
+ if (!campaign || !loader)
+ return;
+
+ loader->SetDataPath(campaign->Path());
+
+ if (file.length() > 0) {
+ const char* filename = file.data();
+ BYTE* block = 0;
+
+ loader->LoadBuffer(filename, block, true);
+ info = (const char*) block;
+ loader->ReleaseBuffer(block);
+
+ if (info.contains('$')) {
+ Player* player = Player::GetCurrentPlayer();
+ CombatGroup* group = campaign->GetPlayerGroup();
+
+ if (player) {
+ info = FormatTextReplace(info, "$NAME", player->Name().data());
+ info = FormatTextReplace(info, "$RANK", Player::RankName(player->Rank()));
+ }
+
+ if (group) {
+ info = FormatTextReplace(info, "$GROUP", group->GetDescription());
+ }
+
+ char timestr[32];
+ FormatDayTime(timestr, campaign->GetTime(), true);
+ info = FormatTextReplace(info, "$TIME", timestr);
+ }
+ }
+
+ if (type < CAMPAIGN_END && image_file.length() > 0) {
+ loader->LoadBitmap(image_file, image);
+ }
+
+ loader->SetDataPath(0);
+}
+