|
13 | 13 | * LICENSE |
14 | 14 | */ |
15 | 15 | #include "weapon.h" |
| 16 | +#include "gamelogic.h" |
16 | 17 | #include "ini.h" |
17 | 18 | #include "weaponset.h" |
18 | 19 |
|
@@ -101,10 +102,253 @@ void WeaponStore::Parse_Weapon_Template(INI *ini, void *, void *store, const voi |
101 | 102 | { |
102 | 103 | const char *name = ini->Get_Next_Token(); |
103 | 104 | 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); |
105 | 106 | *static_cast<const WeaponTemplate **>(store) = w; |
106 | 107 | } |
107 | 108 |
|
| 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 | + |
108 | 352 | bool Weapon::Is_Within_Attack_Range(const Object *source, const Object *target) const |
109 | 353 | { |
110 | 354 | #ifdef GAME_DLL |
@@ -133,8 +377,3 @@ float Weapon::Get_Attack_Range(const Object *source) const |
133 | 377 | return 0; |
134 | 378 | #endif |
135 | 379 | } |
136 | | - |
137 | | -Weapon *WeaponSet::Get_Weapon_In_Weapon_Slot(WeaponSlotType slot) const |
138 | | -{ |
139 | | - return m_weapons[slot]; |
140 | | -} |
|
0 commit comments