2019-06-20 13:22:44 +02:00
|
|
|
#include "common.h"
|
2020-04-17 15:31:11 +02:00
|
|
|
|
2019-06-21 20:16:51 +02:00
|
|
|
#include "main.h"
|
|
|
|
#include "FileMgr.h"
|
2019-06-20 13:22:44 +02:00
|
|
|
#include "WeaponInfo.h"
|
2020-03-28 15:47:52 +01:00
|
|
|
#include "AnimManager.h"
|
2019-06-21 20:16:51 +02:00
|
|
|
#include "AnimBlendAssociation.h"
|
2020-03-28 15:47:52 +01:00
|
|
|
#include "Weapon.h"
|
2019-06-20 13:22:44 +02:00
|
|
|
|
2021-01-19 13:35:48 +01:00
|
|
|
static CWeaponInfo aWeaponInfo[WEAPONTYPE_TOTALWEAPONS];
|
2019-06-21 20:16:51 +02:00
|
|
|
|
|
|
|
static char ms_aWeaponNames[][32] = {
|
|
|
|
"Unarmed",
|
|
|
|
"BaseballBat",
|
|
|
|
"Colt45",
|
|
|
|
"Uzi",
|
|
|
|
"Shotgun",
|
|
|
|
"AK47",
|
|
|
|
"M16",
|
|
|
|
"SniperRifle",
|
|
|
|
"RocketLauncher",
|
|
|
|
"FlameThrower",
|
|
|
|
"Molotov",
|
|
|
|
"Grenade",
|
|
|
|
"Detonator",
|
|
|
|
"HeliCannon"
|
|
|
|
};
|
2019-06-20 13:22:44 +02:00
|
|
|
|
|
|
|
CWeaponInfo*
|
|
|
|
CWeaponInfo::GetWeaponInfo(eWeaponType weaponType) {
|
2021-01-19 13:35:48 +01:00
|
|
|
return &aWeaponInfo[weaponType];
|
2019-06-20 13:22:44 +02:00
|
|
|
}
|
|
|
|
|
2019-06-21 20:16:51 +02:00
|
|
|
void
|
|
|
|
CWeaponInfo::Initialise(void)
|
|
|
|
{
|
|
|
|
debug("Initialising CWeaponInfo...\n");
|
2019-07-04 22:31:21 +02:00
|
|
|
for (int i = 0; i < WEAPONTYPE_TOTALWEAPONS; i++) {
|
2021-01-19 13:35:48 +01:00
|
|
|
aWeaponInfo[i].m_eWeaponFire = WEAPON_FIRE_INSTANT_HIT;
|
2021-01-26 18:35:40 +01:00
|
|
|
aWeaponInfo[i].m_AnimToPlay = ANIM_STD_PUNCH;
|
|
|
|
aWeaponInfo[i].m_Anim2ToPlay = ANIM_STD_NUM;
|
2021-01-19 13:35:48 +01:00
|
|
|
aWeaponInfo[i].m_Flags = WEAPONFLAG_USE_GRAVITY | WEAPONFLAG_SLOWS_DOWN | WEAPONFLAG_RAND_SPEED | WEAPONFLAG_EXPANDS | WEAPONFLAG_EXPLODES;
|
2019-06-21 20:16:51 +02:00
|
|
|
}
|
|
|
|
debug("Loading weapon data...\n");
|
|
|
|
LoadWeaponData();
|
|
|
|
debug("CWeaponInfo ready\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CWeaponInfo::LoadWeaponData(void)
|
|
|
|
{
|
|
|
|
float spread, speed, lifeSpan, radius;
|
|
|
|
float range, fireOffsetX, fireOffsetY, fireOffsetZ;
|
|
|
|
float delayBetweenAnimAndFire, delayBetweenAnim2AndFire, animLoopStart, animLoopEnd;
|
|
|
|
int flags, ammoAmount, damage, reload, weaponType;
|
|
|
|
int firingRate, modelId;
|
|
|
|
char line[256], weaponName[32], fireType[32];
|
|
|
|
char animToPlay[32], anim2ToPlay[32];
|
|
|
|
|
|
|
|
CAnimBlendAssociation *animAssoc;
|
2019-07-01 21:46:44 +02:00
|
|
|
AnimationId animId;
|
2019-06-21 20:16:51 +02:00
|
|
|
|
2020-07-22 13:56:28 +02:00
|
|
|
size_t bp, buflen;
|
2019-06-21 20:16:51 +02:00
|
|
|
int lp, linelen;
|
|
|
|
|
|
|
|
CFileMgr::SetDir("DATA");
|
|
|
|
buflen = CFileMgr::LoadFile("WEAPON.DAT", work_buff, sizeof(work_buff), "r");
|
|
|
|
CFileMgr::SetDir("");
|
|
|
|
|
|
|
|
for (bp = 0; bp < buflen; ) {
|
|
|
|
// read file line by line
|
|
|
|
for (linelen = 0; work_buff[bp] != '\n' && bp < buflen; bp++) {
|
|
|
|
line[linelen++] = work_buff[bp];
|
|
|
|
}
|
|
|
|
bp++;
|
|
|
|
line[linelen] = '\0';
|
|
|
|
|
|
|
|
// skip white space
|
2020-12-28 01:25:26 +01:00
|
|
|
for (lp = 0; line[lp] <= ' ' && line[lp] != '\0'; lp++);
|
2019-06-21 20:16:51 +02:00
|
|
|
|
2020-12-28 01:25:26 +01:00
|
|
|
if (line[lp] == '\0' || line[lp] == '#')
|
2019-06-21 20:16:51 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
spread = 0.0f;
|
|
|
|
flags = 0;
|
|
|
|
speed = 0.0f;
|
|
|
|
ammoAmount = 0;
|
|
|
|
lifeSpan = 0.0f;
|
|
|
|
radius = 0.0f;
|
|
|
|
range = 0.0f;
|
|
|
|
damage = 0;
|
|
|
|
reload = 0;
|
|
|
|
firingRate = 0;
|
|
|
|
fireOffsetX = 0.0f;
|
|
|
|
weaponName[0] = '\0';
|
|
|
|
fireType[0] = '\0';
|
|
|
|
fireOffsetY = 0.0f;
|
|
|
|
fireOffsetZ = 0.0f;
|
2021-01-26 18:35:40 +01:00
|
|
|
animId = ANIM_STD_WALK;
|
2019-06-21 20:16:51 +02:00
|
|
|
sscanf(
|
|
|
|
&line[lp],
|
|
|
|
"%s %s %f %d %d %d %d %f %f %f %f %f %f %f %s %s %f %f %f %f %d %d",
|
2020-05-12 01:24:57 +02:00
|
|
|
weaponName,
|
|
|
|
fireType,
|
2019-06-21 20:16:51 +02:00
|
|
|
&range,
|
|
|
|
&firingRate,
|
|
|
|
&reload,
|
|
|
|
&ammoAmount,
|
|
|
|
&damage,
|
|
|
|
&speed,
|
|
|
|
&radius,
|
|
|
|
&lifeSpan,
|
|
|
|
&spread,
|
|
|
|
&fireOffsetX,
|
|
|
|
&fireOffsetY,
|
|
|
|
&fireOffsetZ,
|
2020-05-12 01:24:57 +02:00
|
|
|
animToPlay,
|
|
|
|
anim2ToPlay,
|
2019-06-21 20:16:51 +02:00
|
|
|
&animLoopStart,
|
|
|
|
&animLoopEnd,
|
|
|
|
&delayBetweenAnimAndFire,
|
|
|
|
&delayBetweenAnim2AndFire,
|
|
|
|
&modelId,
|
|
|
|
&flags);
|
|
|
|
|
|
|
|
if (strncmp(weaponName, "ENDWEAPONDATA", 13) == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
weaponType = FindWeaponType(weaponName);
|
|
|
|
|
|
|
|
animAssoc = CAnimManager::GetAnimAssociation(ASSOCGRP_STD, animToPlay);
|
|
|
|
animId = static_cast<AnimationId>(animAssoc->animId);
|
|
|
|
|
2020-12-25 14:18:13 +01:00
|
|
|
if (strcmp(anim2ToPlay, "null") != 0) {
|
2019-06-21 20:16:51 +02:00
|
|
|
animAssoc = CAnimManager::GetAnimAssociation(ASSOCGRP_STD, anim2ToPlay);
|
2021-01-19 13:35:48 +01:00
|
|
|
aWeaponInfo[weaponType].m_Anim2ToPlay = (AnimationId) animAssoc->animId;
|
2019-06-21 20:16:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CVector vecFireOffset(fireOffsetX, fireOffsetY, fireOffsetZ);
|
|
|
|
|
2021-01-19 13:35:48 +01:00
|
|
|
aWeaponInfo[weaponType].m_eWeaponFire = FindWeaponFireType(fireType);
|
|
|
|
aWeaponInfo[weaponType].m_fRange = range;
|
|
|
|
aWeaponInfo[weaponType].m_nFiringRate = firingRate;
|
|
|
|
aWeaponInfo[weaponType].m_nReload = reload;
|
|
|
|
aWeaponInfo[weaponType].m_nAmountofAmmunition = ammoAmount;
|
|
|
|
aWeaponInfo[weaponType].m_nDamage = damage;
|
|
|
|
aWeaponInfo[weaponType].m_fSpeed = speed;
|
|
|
|
aWeaponInfo[weaponType].m_fRadius = radius;
|
|
|
|
aWeaponInfo[weaponType].m_fLifespan = lifeSpan;
|
|
|
|
aWeaponInfo[weaponType].m_fSpread = spread;
|
|
|
|
aWeaponInfo[weaponType].m_vecFireOffset = vecFireOffset;
|
|
|
|
aWeaponInfo[weaponType].m_AnimToPlay = animId;
|
|
|
|
aWeaponInfo[weaponType].m_fAnimLoopStart = animLoopStart / 30.0f;
|
|
|
|
aWeaponInfo[weaponType].m_fAnimLoopEnd = animLoopEnd / 30.0f;
|
|
|
|
aWeaponInfo[weaponType].m_fAnimFrameFire = delayBetweenAnimAndFire / 30.0f;
|
|
|
|
aWeaponInfo[weaponType].m_fAnim2FrameFire = delayBetweenAnim2AndFire / 30.0f;
|
|
|
|
aWeaponInfo[weaponType].m_nModelId = modelId;
|
|
|
|
aWeaponInfo[weaponType].m_Flags = flags;
|
2019-06-21 20:16:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
eWeaponType
|
|
|
|
CWeaponInfo::FindWeaponType(char *name)
|
|
|
|
{
|
2019-07-04 22:31:21 +02:00
|
|
|
for (int i = 0; i < WEAPONTYPE_TOTALWEAPONS; i++) {
|
2019-06-21 20:16:51 +02:00
|
|
|
if (strcmp(ms_aWeaponNames[i], name) == 0) {
|
|
|
|
return static_cast<eWeaponType>(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return WEAPONTYPE_UNARMED;
|
|
|
|
}
|
|
|
|
|
|
|
|
eWeaponFire
|
|
|
|
CWeaponInfo::FindWeaponFireType(char *name)
|
|
|
|
{
|
|
|
|
if (strcmp(name, "MELEE") == 0) return WEAPON_FIRE_MELEE;
|
|
|
|
if (strcmp(name, "INSTANT_HIT") == 0) return WEAPON_FIRE_INSTANT_HIT;
|
|
|
|
if (strcmp(name, "PROJECTILE") == 0) return WEAPON_FIRE_PROJECTILE;
|
|
|
|
if (strcmp(name, "AREA_EFFECT") == 0) return WEAPON_FIRE_AREA_EFFECT;
|
|
|
|
Error("Unknown weapon fire type, WeaponInfo.cpp");
|
|
|
|
return WEAPON_FIRE_INSTANT_HIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CWeaponInfo::Shutdown(void)
|
|
|
|
{
|
|
|
|
debug("Shutting down CWeaponInfo...\n");
|
|
|
|
debug("CWeaponInfo shut down\n");
|
2020-05-12 01:24:57 +02:00
|
|
|
}
|