SAGA2: Eliminate global objects in weapons.cpp

This commit is contained in:
Eugene Sandulenko 2021-06-13 15:30:55 +02:00
parent 24eb580ea3
commit ffc0ed5fd2
No known key found for this signature in database
GPG key ID: 014D387312D34F08
9 changed files with 60 additions and 87 deletions

View file

@ -39,7 +39,6 @@ enum weaponHitType {
//-----------------------------------------------------------------------
typedef uint16 weaponID;
#define nullWeapon 0
enum combatSound {

View file

@ -72,60 +72,10 @@ enum effectTypes {
effectTAG, // mana drain, money drain
effectLocation, // mana drain, money drain
effectSpecial,
effectStrike, // weapon strike effect
effectStrike // weapon strike effect
};
//
// Attribute effects - look familiar ?
//
/* all the skill* are now in the spellid enum
enum effectAttribTypes {
skillArchery = 0,
skillSwordcraft = 1,
skillShieldcraft = 2,
skillBludgeon = 3,
skillThrowing = 4,
skillSpellcraft = 5,
skillStealth = 6,
skillAgility = 7,
skillBrawn = 8,
skillLockpick = 9,
skillPilfer = 10,
skillFirstAid = 11,
skillSpotHidden = 12,
};
*/
//
// Damage effects - these are the types of damage in the world
// Damage being defined as a change in effective vitality
// Note that healing is negative damage.
//
enum effectDamageTypes {
// Generic
damageOther = 0, // Healing, cause wounds
// Combat damage
damageImpact = 1, // hammers, maces
damageSlash = 2, // swords
damageProjectile = 3, // arrows, poin-ted sticks
// Magic damage
damageFire = 4, // Yellow
damageAcid = 5, // Violet
damageHeat = 6, // Red
damageCold = 7, // Blue
damageLightning = 8, // Orange
damagePoison = 9, // Green
// Other magic damage
damageMental = 10, // dain bramage
damageToUndead = 11, // undead take this damage
damageDirMagic = 12, // the plusses on swords etc.
// Physiological Damage
damageStarve = 13, // You must eat!
// other
damageEnergy = 14, // Generally hard to resist - god damage
};
//
// Resistance Effects - these correspond exactly to the Damage types
// A separate enum is defined to permit differentiation between

View file

@ -230,6 +230,38 @@ typedef uint8 ColorTable[256];
// number of containers
const int kNumViews = 3;
enum {
kMaxWeapons = 256
};
//
// Damage effects - these are the types of damage in the world
// Damage being defined as a change in effective vitality
// Note that healing is negative damage.
//
enum effectDamageTypes {
// Generic
damageOther = 0, // Healing, cause wounds
// Combat damage
damageImpact = 1, // hammers, maces
damageSlash = 2, // swords
damageProjectile = 3, // arrows, poin-ted sticks
// Magic damage
damageFire = 4, // Yellow
damageAcid = 5, // Violet
damageHeat = 6, // Red
damageCold = 7, // Blue
damageLightning = 8, // Orange
damagePoison = 9, // Green
// Other magic damage
damageMental = 10, // dain bramage
damageToUndead = 11, // undead take this damage
damageDirMagic = 12, // the plusses on swords etc.
// Physiological Damage
damageStarve = 13, // You must eat!
// other
damageEnergy = 14 // Generally hard to resist - god damage
};
} // end of namespace Saga2

View file

@ -37,6 +37,7 @@
#include "saga2/weapons.h"
#include "saga2/spellbuk.h"
#include "saga2/combat.h"
#include "saga2/tile.h"
#include "saga2/methods.r"
#include "saga2/pclass.r"

View file

@ -63,7 +63,7 @@ Saga2Engine::Saga2Engine(OSystem *syst)
SearchMan.addSubDirectoryMatching(gameDataDir, "res");
debug("Saga2Engine::Saga2Engine");
_loadedWeapons = 0;
}
Saga2Engine::~Saga2Engine() {

View file

@ -28,6 +28,9 @@
#include "common/system.h"
#include "engines/engine.h"
#include "saga2/idtypes.h"
#include "saga2/weapons.h"
namespace Video {
class SmackerDecoder;
};
@ -74,6 +77,9 @@ public:
// We need random numbers
Common::RandomSource *_rnd;
WeaponStuff _weaponRack[kMaxWeapons];
weaponID _loadedWeapons = 0;
private:
Video::SmackerDecoder *_smkDecoder;
int _videoX, _videoY;

View file

@ -39,6 +39,7 @@
#include "saga2/weapons.h"
#include "saga2/loadsave.h"
#include "saga2/display.h"
#include "saga2/tile.h"
namespace Saga2 {

View file

@ -26,6 +26,7 @@
#include "saga2/std.h"
#include "saga2/weapons.h"
#include "saga2/spelshow.h"
#include "saga2/spellbuk.h"
#include "saga2/actor.h"
#include "saga2/spellio.h"
@ -45,28 +46,8 @@ namespace Saga2 {
// which relate to spell casting
//
/* ===================================================================== *
Constants
* ===================================================================== */
const int32 maxWeapons = 256;
const int32 maxWeaponPrototypes = 256;
/* ===================================================================== *
Global data
* ===================================================================== */
WeaponStuff weaponRack[maxWeapons];
weaponID loadedWeapons = 0;
//-----------------------------------------------------------------------
// prototypes
static void loadWeaponData(void);
//-----------------------------------------------------------------------
ProtoEffect *createNewProtoEffect(ResourceItemEffect *rie) {
ProtoEffect *pe = NULL;
@ -157,16 +138,16 @@ void initWeapons(void) {
//-----------------------------------------------------------------------
void cleanupWeapons(void) {
for (int i = 0; i < maxWeapons; i++)
weaponRack[i].killEffects();
for (int i = 0; i < kMaxWeapons; i++)
g_vm->_weaponRack[i].killEffects();
}
//-----------------------------------------------------------------------
WeaponStuff &getWeapon(weaponID i) {
if (i < loadedWeapons)
return weaponRack[i];
return weaponRack[nullWeapon];
if (i < g_vm->_loadedWeapons)
return g_vm->_weaponRack[i];
return g_vm->_weaponRack[nullWeapon];
}
//-----------------------------------------------------------------------
@ -184,7 +165,10 @@ GameObject *getShieldItem(GameObject *defender) {
WeaponProtoEffect member functions
* ===================================================================== */
//-----------------------------------------------------------------------
WeaponProtoEffect::~WeaponProtoEffect(void) {
if (effect != NULL)
delete effect;
}
void WeaponProtoEffect::implement(
Actor *enactor,
@ -338,14 +322,14 @@ static void loadWeaponData(void) {
error("Unable to load weapon effect %d", i);
if (rie->item) {
weaponRack[rie->item].setID(rie->item);
weaponRack[rie->item].addEffect(rie);
g_vm->_weaponRack[rie->item].setID(rie->item);
g_vm->_weaponRack[rie->item].addEffect(rie);
}
RDisposePtr(rie);
i++;
}
loadedWeapons = i;
g_vm->_loadedWeapons = i;
assert(i > 1);
auxResFile->disposeContext(spellRes);

View file

@ -27,12 +27,14 @@
#ifndef SAGA2_WEAPONS_H
#define SAGA2_WEAPONS_H
#include "saga2/spelshow.h"
namespace Saga2 {
struct ResourceItemEffect;
class Actor;
class GameObject;
class ProtoEffect;
ProtoEffect *createNewProtoEffect(ResourceItemEffect *rie);
//-----------------------------------------------------------------------
@ -59,9 +61,7 @@ public:
WeaponProtoEffect(ResourceItemEffect *rie) :
effect(createNewProtoEffect(rie)) {
}
~WeaponProtoEffect(void) {
if (effect != NULL) delete effect;
}
~WeaponProtoEffect(void);
void implement(
Actor *enactor,