Starshatter_Open
Open source Starshatter engine
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
CombatEvent.cpp
Go to the documentation of this file.
1 /* Project Starshatter 4.5
2  Destroyer Studios LLC
3  Copyright © 1997-2004. All Rights Reserved.
4 
5  SUBSYSTEM: Stars.exe
6  FILE: CombatEvent.cpp
7  AUTHOR: John DiCamillo
8 
9 
10  OVERVIEW
11  ========
12  A significant (newsworthy) event in the dynamic campaign.
13 */
14 
15 #include "MemDebug.h"
16 #include "CombatEvent.h"
17 #include "CombatGroup.h"
18 #include "Campaign.h"
19 #include "Player.h"
20 #include "ShipDesign.h"
21 #include "Ship.h"
22 
23 #include "Term.h"
24 #include "ParseUtil.h"
25 #include "FormatUtil.h"
26 #include "DataLoader.h"
27 
28 // +----------------------------------------------------------------------+
29 
30 CombatEvent::CombatEvent(Campaign* c, int typ, int tim, int tem,
31 int src, const char* rgn)
32 : campaign(c), type(typ), time(tim), team(tem), source(src),
33 region(rgn), points(0), visited(false)
34 { }
35 
36 // +----------------------------------------------------------------------+
37 
38 const char*
40 {
41  return SourceName(source);
42 }
43 
44 // +----------------------------------------------------------------------+
45 
46 const char*
48 {
49  return TypeName(type);
50 }
51 
52 // +----------------------------------------------------------------------+
53 
54 const char*
56 {
57  switch (n) {
58  case FORCOM: return "FORCOM";
59  case TACNET: return "TACNET";
60  case INTEL: return "SECURE";
61  case MAIL: return "Mail";
62  case NEWS: return "News";
63  }
64 
65  return "Unknown";
66 }
67 
68 int
70 {
71  for (int i = FORCOM; i <= NEWS; i++)
72  if (!_stricmp(n, SourceName(i)))
73  return i;
74 
75  return -1;
76 }
77 
78 // +----------------------------------------------------------------------+
79 
80 const char*
82 {
83  switch (n) {
84  case ATTACK: return "ATTACK";
85  case DEFEND: return "DEFEND";
86  case MOVE_TO: return "MOVE_TO";
87  case CAPTURE: return "CAPTURE";
88  case STRATEGY: return "STRATEGY";
89  case STORY: return "STORY";
90  case CAMPAIGN_START: return "CAMPAIGN_START";
91  case CAMPAIGN_END: return "CAMPAIGN_END";
92  case CAMPAIGN_FAIL: return "CAMPAIGN_FAIL";
93  }
94 
95  return "Unknown";
96 }
97 
98 int
100 {
101  for (int i = ATTACK; i <= CAMPAIGN_FAIL; i++)
102  if (!_stricmp(n, TypeName(i)))
103  return i;
104 
105  return -1;
106 }
107 
108 // +----------------------------------------------------------------------+
109 
110 void
112 {
113  DataLoader* loader = DataLoader::GetLoader();
114 
115  if (!campaign || !loader)
116  return;
117 
118  loader->SetDataPath(campaign->Path());
119 
120  if (file.length() > 0) {
121  const char* filename = file.data();
122  BYTE* block = 0;
123 
124  loader->LoadBuffer(filename, block, true);
125  info = (const char*) block;
126  loader->ReleaseBuffer(block);
127 
128  if (info.contains('$')) {
129  Player* player = Player::GetCurrentPlayer();
130  CombatGroup* group = campaign->GetPlayerGroup();
131 
132  if (player) {
133  info = FormatTextReplace(info, "$NAME", player->Name().data());
134  info = FormatTextReplace(info, "$RANK", Player::RankName(player->Rank()));
135  }
136 
137  if (group) {
138  info = FormatTextReplace(info, "$GROUP", group->GetDescription());
139  }
140 
141  char timestr[32];
142  FormatDayTime(timestr, campaign->GetTime(), true);
143  info = FormatTextReplace(info, "$TIME", timestr);
144  }
145  }
146 
147  if (type < CAMPAIGN_END && image_file.length() > 0) {
148  loader->LoadBitmap(image_file, image);
149  }
150 
151  loader->SetDataPath(0);
152 }
153