Skip to content

Commit 085b54c

Browse files
authored
Some Weapon stuff (#804)
1 parent 3e39884 commit 085b54c

File tree

11 files changed

+744
-63
lines changed

11 files changed

+744
-63
lines changed

.github/workflows/windows.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
4646
- name: Build Thyme
4747
run: |
48-
cmake -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_TESTS=ON -DBUILD_TOOLS=ON -DLOGGING=ON -DSTANDALONE=ON -DUSE_CRASHPAD=ON -B build
48+
cmake -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_IGNORE_PATH=C:/Strawberry/c/lib -DBUILD_TESTS=ON -DBUILD_TOOLS=ON -DLOGGING=ON -DSTANDALONE=ON -DUSE_CRASHPAD=ON -B build
4949
cmake --build build --config RelWithDebInfo
5050
5151
- name: Test Thyme

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ set(GAMEENGINE_SRC
248248
game/logic/object/objectcreationlist.cpp
249249
game/logic/object/objecttypes.cpp
250250
game/logic/object/weapon.cpp
251+
game/logic/object/weaponset.cpp
251252
game/logic/object/weapontemplateset.cpp
252253
game/logic/object/update/aiupdate.cpp
253254
game/logic/object/update/laserupdate.cpp

src/game/common/thing/thingtemplate.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -970,7 +970,7 @@ void ThingTemplate::Parse_Overrideable_By_Like_Kind(INI *ini, void *instance, vo
970970
bool ThingTemplate::Can_Possibly_Have_Any_Weapon() const
971971
{
972972
for (auto &set : m_weaponTemplateSets) {
973-
if (set.Has_Valid()) {
973+
if (set.Has_Any_Weapons()) {
974974
return true;
975975
}
976976
}

src/game/logic/object/object.h

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -106,31 +106,6 @@ enum ObjectScriptStatusBit
106106
STATUS_TARGETABLE = 1 << 4,
107107
};
108108

109-
enum DeathType
110-
{
111-
DEATH_NORMAL,
112-
DEATH_NONE,
113-
DEATH_CRUSHED,
114-
DEATH_BURNED,
115-
DEATH_EXPLODED,
116-
DEATH_POISONED,
117-
DEATH_TOPPLED,
118-
DEATH_FLOODED,
119-
DEATH_SUICIDED,
120-
DEATH_LASERED,
121-
DEATH_DETONATED,
122-
DEATH_SPLATTED,
123-
DEATH_POISONED_BETA,
124-
DEATH_EXTRA_2,
125-
DEATH_EXTRA_3,
126-
DEATH_EXTRA_4,
127-
DEATH_EXTRA_5,
128-
DEATH_EXTRA_6,
129-
DEATH_EXTRA_7,
130-
DEATH_EXTRA_8,
131-
DEATH_POISONED_GAMMA,
132-
};
133-
134109
enum SpecialPowerType
135110
{
136111
SPECIAL_INVALID,
@@ -289,7 +264,7 @@ class Object : public Thing, public SnapShot
289264
bool Is_Effectively_Dead() const { return (m_privateStatus & STATUS_EFFECTIVELY_DEAD) != 0; }
290265
bool Is_Undetected_Defector() const { return (m_privateStatus & STATUS_UNDETECTED_DEFECTOR) != 0; }
291266
bool Is_Airborne_Target() const { return m_status.Test(OBJECT_STATUS_AIRBORNE_TARGET); }
292-
bool Is_Shared_Reload_Time() const { return m_weaponSet.Is_Shared_Reload_Time(); }
267+
bool Is_Share_Weapon_Reload_Time() const { return m_weaponSet.Is_Share_Weapon_Reload_Time(); }
293268
bool Is_Destroyed() const { return m_status.Test(OBJECT_STATUS_DESTROYED); }
294269
bool Is_Outside_Map() const { return (m_privateStatus & STATUS_OUTSIDE_MAP) != 0; }
295270
bool Is_Disabled() const { return m_disabledStates.Any(); }

src/game/logic/object/weapon.cpp

Lines changed: 245 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* LICENSE
1414
*/
1515
#include "weapon.h"
16+
#include "gamelogic.h"
1617
#include "ini.h"
1718
#include "weaponset.h"
1819

@@ -101,10 +102,253 @@ void WeaponStore::Parse_Weapon_Template(INI *ini, void *, void *store, const voi
101102
{
102103
const char *name = ini->Get_Next_Token();
103104
const WeaponTemplate *w = g_theWeaponStore->Find_Weapon_Template(name);
104-
captainslog_dbgassert(w != nullptr && !strcasecmp(name, "None"), "WeaponTemplate %s not found!", name);
105+
captainslog_dbgassert(w != nullptr || strcasecmp(name, "None") == 0, "WeaponTemplate %s not found!", name);
105106
*static_cast<const WeaponTemplate **>(store) = w;
106107
}
107108

109+
Weapon *WeaponStore::Allocate_New_Weapon(const WeaponTemplate *tmpl, WeaponSlotType wslot) const
110+
{
111+
return new Weapon(tmpl, wslot);
112+
}
113+
114+
Weapon::Weapon(const WeaponTemplate *tmpl, WeaponSlotType wslot) :
115+
m_template(tmpl),
116+
m_wslot(wslot),
117+
m_status(OUT_OF_AMMO),
118+
m_ammoInClip(0),
119+
m_whenWeCanFireAgain(0),
120+
m_whenPreAttackFinished(0),
121+
m_whenLastReloadStarted(0),
122+
m_lastFireFrame(0),
123+
m_projectileStreamID(OBJECT_UNK),
124+
m_maxShotCount(0x7FFFFFFF),
125+
m_curBarrel(0),
126+
m_leechWeaponRangeActive(false)
127+
{
128+
m_pitchLimited = m_template->Get_Min_Target_Pitch() > -GAMEMATH_PI || m_template->Get_Max_Target_Pitch() < GAMEMATH_PI;
129+
m_numShotsForCurBarrel = m_template->Get_Shots_Per_Barrel();
130+
m_suspendFXDelay = m_template->Get_Suspend_FX_Delay() + g_theGameLogic->Get_Frame();
131+
}
132+
133+
Weapon::Weapon(const Weapon &that) :
134+
m_template(that.m_template),
135+
m_wslot(that.m_wslot),
136+
m_status(OUT_OF_AMMO),
137+
m_ammoInClip(0),
138+
m_whenWeCanFireAgain(0),
139+
m_whenPreAttackFinished(0),
140+
m_whenLastReloadStarted(0),
141+
m_lastFireFrame(0),
142+
m_projectileStreamID(OBJECT_UNK),
143+
m_maxShotCount(0x7FFFFFFF),
144+
m_curBarrel(0),
145+
m_leechWeaponRangeActive(false)
146+
{
147+
m_pitchLimited = m_template->Get_Min_Target_Pitch() > -GAMEMATH_PI || m_template->Get_Max_Target_Pitch() < GAMEMATH_PI;
148+
m_numShotsForCurBarrel = m_template->Get_Shots_Per_Barrel();
149+
m_suspendFXDelay = that.Get_Suspend_FX_Delay();
150+
}
151+
152+
Weapon &Weapon::operator=(const Weapon &that)
153+
{
154+
if (this != &that) {
155+
m_template = that.m_template;
156+
m_wslot = that.m_wslot;
157+
m_status = OUT_OF_AMMO;
158+
m_ammoInClip = 0;
159+
m_whenPreAttackFinished = 0;
160+
m_whenLastReloadStarted = 0;
161+
m_whenWeCanFireAgain = 0;
162+
m_leechWeaponRangeActive = 0;
163+
m_pitchLimited =
164+
m_template->Get_Min_Target_Pitch() > -GAMEMATH_PI || m_template->Get_Max_Target_Pitch() < GAMEMATH_PI;
165+
m_maxShotCount = 0x7FFFFFFF;
166+
m_curBarrel = 0;
167+
m_lastFireFrame = 0;
168+
m_suspendFXDelay = that.Get_Suspend_FX_Delay();
169+
m_numShotsForCurBarrel = m_template->Get_Shots_Per_Barrel();
170+
m_projectileStreamID = OBJECT_UNK;
171+
}
172+
173+
return *this;
174+
}
175+
176+
void Weapon::CRC_Snapshot(Xfer *xfer)
177+
{
178+
#ifdef GAME_DEBUG_STRUCTS
179+
Utf8String str1;
180+
Utf8String str2;
181+
// todo
182+
#endif
183+
184+
Utf8String name = m_template->Get_Name();
185+
xfer->xferAsciiString(&name);
186+
xfer->xferUser(&m_wslot, sizeof(m_wslot));
187+
188+
#ifdef GAME_DEBUG_STRUCTS
189+
// todo
190+
#endif
191+
192+
xfer->xferUnsignedInt(&m_ammoInClip);
193+
194+
#ifdef GAME_DEBUG_STRUCTS
195+
// todo
196+
#endif
197+
198+
xfer->xferUnsignedInt(&m_whenWeCanFireAgain);
199+
200+
#ifdef GAME_DEBUG_STRUCTS
201+
// todo
202+
#endif
203+
204+
xfer->xferUnsignedInt(&m_whenPreAttackFinished);
205+
206+
#ifdef GAME_DEBUG_STRUCTS
207+
// todo
208+
#endif
209+
210+
xfer->xferUnsignedInt(&m_whenLastReloadStarted);
211+
212+
#ifdef GAME_DEBUG_STRUCTS
213+
// todo
214+
#endif
215+
216+
xfer->xferUnsignedInt(&m_lastFireFrame);
217+
218+
#ifdef GAME_DEBUG_STRUCTS
219+
// todo
220+
#endif
221+
222+
xfer->xferObjectID(&m_projectileStreamID);
223+
224+
#ifdef GAME_DEBUG_STRUCTS
225+
// todo
226+
#endif
227+
228+
ObjectID laser = OBJECT_UNK;
229+
xfer->xferObjectID(&laser);
230+
231+
#ifdef GAME_DEBUG_STRUCTS
232+
// todo
233+
#endif
234+
235+
xfer->xferInt(&m_maxShotCount);
236+
237+
#ifdef GAME_DEBUG_STRUCTS
238+
// todo
239+
#endif
240+
241+
xfer->xferInt(&m_curBarrel);
242+
243+
#ifdef GAME_DEBUG_STRUCTS
244+
// todo
245+
#endif
246+
247+
xfer->xferInt(&m_numShotsForCurBarrel);
248+
249+
#ifdef GAME_DEBUG_STRUCTS
250+
// todo
251+
#endif
252+
253+
unsigned short scatter_count = static_cast<unsigned short>(m_scatterTargetIndexes.size());
254+
xfer->xferUnsignedShort(&scatter_count);
255+
256+
#ifdef GAME_DEBUG_STRUCTS
257+
// todo
258+
#endif
259+
260+
for (auto i = m_scatterTargetIndexes.begin(); i != m_scatterTargetIndexes.end(); i++) {
261+
int index = *i;
262+
xfer->xferInt(&index);
263+
264+
#ifdef GAME_DEBUG_STRUCTS
265+
// todo
266+
#endif
267+
}
268+
269+
xfer->xferBool(&m_pitchLimited);
270+
271+
#ifdef GAME_DEBUG_STRUCTS
272+
// todo
273+
#endif
274+
275+
xfer->xferBool(&m_leechWeaponRangeActive);
276+
277+
#ifdef GAME_DEBUG_STRUCTS
278+
// todo
279+
#endif
280+
}
281+
282+
void Weapon::Xfer_Snapshot(Xfer *xfer)
283+
{
284+
unsigned char version = 3;
285+
xfer->xferVersion(&version, 3);
286+
287+
if (version >= 2) {
288+
Utf8String name;
289+
name = m_template->Get_Name();
290+
xfer->xferAsciiString(&name);
291+
292+
if (xfer->Get_Mode() == XFER_LOAD) {
293+
m_template = g_theWeaponStore->Find_Weapon_Template(name);
294+
295+
if (m_template == nullptr) {
296+
throw CODE_06;
297+
}
298+
}
299+
}
300+
301+
xfer->xferUser(&m_wslot, sizeof(m_wslot));
302+
xfer->xferUser(&m_status, sizeof(m_status));
303+
xfer->xferUnsignedInt(&m_ammoInClip);
304+
xfer->xferUnsignedInt(&m_whenWeCanFireAgain);
305+
xfer->xferUnsignedInt(&m_whenPreAttackFinished);
306+
xfer->xferUnsignedInt(&m_whenLastReloadStarted);
307+
xfer->xferUnsignedInt(&m_lastFireFrame);
308+
309+
if (version < 3) {
310+
m_suspendFXDelay = 0;
311+
} else {
312+
xfer->xferUnsignedInt(&m_suspendFXDelay);
313+
}
314+
315+
xfer->xferObjectID(&m_projectileStreamID);
316+
ObjectID laser = OBJECT_UNK;
317+
xfer->xferObjectID(&laser);
318+
xfer->xferInt(&m_maxShotCount);
319+
xfer->xferInt(&m_curBarrel);
320+
xfer->xferInt(&m_numShotsForCurBarrel);
321+
322+
unsigned short size = static_cast<unsigned short>(m_scatterTargetIndexes.size());
323+
xfer->xferUnsignedShort(&size);
324+
325+
if (xfer->Get_Mode() == XFER_SAVE) {
326+
for (auto i = m_scatterTargetIndexes.begin(); i != m_scatterTargetIndexes.end(); i++) {
327+
int index = *i;
328+
xfer->xferInt(&index);
329+
}
330+
} else {
331+
m_scatterTargetIndexes.clear();
332+
for (unsigned short i = 0; i < size; i++) {
333+
int index;
334+
xfer->xferInt(&index);
335+
m_scatterTargetIndexes.push_back(index);
336+
}
337+
}
338+
339+
xfer->xferBool(&m_pitchLimited);
340+
xfer->xferBool(&m_leechWeaponRangeActive);
341+
}
342+
343+
void Weapon::Load_Post_Process()
344+
{
345+
if (m_projectileStreamID != OBJECT_UNK) {
346+
if (g_theGameLogic->Find_Object_By_ID(m_projectileStreamID) == nullptr) {
347+
m_projectileStreamID = OBJECT_UNK;
348+
}
349+
}
350+
}
351+
108352
bool Weapon::Is_Within_Attack_Range(const Object *source, const Object *target) const
109353
{
110354
#ifdef GAME_DLL
@@ -133,8 +377,3 @@ float Weapon::Get_Attack_Range(const Object *source) const
133377
return 0;
134378
#endif
135379
}
136-
137-
Weapon *WeaponSet::Get_Weapon_In_Weapon_Slot(WeaponSlotType slot) const
138-
{
139-
return m_weapons[slot];
140-
}

0 commit comments

Comments
 (0)