SAGA2: Move global variables in beegee.cpp to Deejay class

This commit is contained in:
a/ 2021-08-26 04:07:30 +09:00
parent 00eab347c1
commit db33d0ccac
5 changed files with 102 additions and 120 deletions

View File

@ -3557,8 +3557,8 @@ void cleanupActors(void) {
int16 AddFactionTally(int faction, enum factionTallyTypes act, int amt) { int16 AddFactionTally(int faction, enum factionTallyTypes act, int amt) {
#if DEBUG #if DEBUG
if (faction >= maxFactions) if (faction >= kMaxFactions)
error("Scripter: Tell Talin to increase maxFactions!\n"); error("Scripter: Tell Talin to increase kMaxFactions!\n");
assert(faction >= 0); assert(faction >= 0);
assert(act >= 0); assert(act >= 0);
assert(act < factionNumColumns); assert(act < factionNumColumns);
@ -3588,8 +3588,8 @@ int16 AddFactionTally(int faction, enum factionTallyTypes act, int amt) {
// Get the attitude a particular faction has for a char. // Get the attitude a particular faction has for a char.
int16 GetFactionTally(int faction, enum factionTallyTypes act) { int16 GetFactionTally(int faction, enum factionTallyTypes act) {
#if DEBUG #if DEBUG
if (faction >= maxFactions) if (faction >= kMaxFactions)
error("Scripter: Tell Talin to increase maxFactions!\n"); error("Scripter: Tell Talin to increase kMaxFactions!\n");
assert(faction >= 0); assert(faction >= 0);
assert(act >= 0); assert(act >= 0);
assert(act < factionNumColumns); assert(act < factionNumColumns);
@ -3610,7 +3610,7 @@ void saveFactionTallies(Common::OutSaveFile *outS) {
outS->write("FACT", 4); outS->write("FACT", 4);
CHUNK_BEGIN; CHUNK_BEGIN;
for (int i = 0; i < maxFactions; ++i) { for (int i = 0; i < kMaxFactions; ++i) {
for (int j = 0; j < factionNumColumns; ++j) for (int j = 0; j < factionNumColumns; ++j)
out->writeSint16LE(g_vm->_act->_factionTable[i][j]); out->writeSint16LE(g_vm->_act->_factionTable[i][j]);
} }
@ -3620,7 +3620,7 @@ void saveFactionTallies(Common::OutSaveFile *outS) {
void loadFactionTallies(Common::InSaveFile *in) { void loadFactionTallies(Common::InSaveFile *in) {
debugC(2, kDebugSaveload, "Loading Faction Tallies"); debugC(2, kDebugSaveload, "Loading Faction Tallies");
for (int i = 0; i < maxFactions; ++i) { for (int i = 0; i < kMaxFactions; ++i) {
for (int j = 0; j < factionNumColumns; ++j) for (int j = 0; j < factionNumColumns; ++j)
g_vm->_act->_factionTable[i][j] = in->readSint16LE(); g_vm->_act->_factionTable[i][j] = in->readSint16LE();
} }

View File

@ -1097,9 +1097,6 @@ void addEnchantment(Actor *a, uint16 enchantmentID);
Actor factions table Actor factions table
* ============================================================================ */ * ============================================================================ */
// Let's assume 64 factions maximum for now
const int maxFactions = 64;
enum factionTallyTypes { enum factionTallyTypes {
factionNumKills = 0, // # of times faction member killed by PC factionNumKills = 0, // # of times faction member killed by PC
factionNumThefts, // # of times PC steals from faction member factionNumThefts, // # of times PC steals from faction member
@ -1142,7 +1139,7 @@ public:
int32 _updatesViaScript; int32 _updatesViaScript;
int32 _baseActorIndex; int32 _baseActorIndex;
int16 _factionTable[maxFactions][factionNumColumns]; int16 _factionTable[kMaxFactions][factionNumColumns];
bool _actorStatesPaused; bool _actorStatesPaused;
bool _combatBehaviorEnabled; bool _combatBehaviorEnabled;

View File

@ -35,19 +35,6 @@ namespace Saga2 {
#define AUXTHEMES 2 #define AUXTHEMES 2
#define USEAUXTHEME 0xe0 #define USEAUXTHEME 0xe0
struct auxAudioTheme {
bool active;
StaticLocation l;
uint32 loopID;
};
static const StaticTilePoint NullTile = {(int16)minint16, (int16)minint16, (int16)minint16};
static auxAudioTheme aats[AUXTHEMES] = {
{false, {NullTile, 0}, 0},
{false, {NullTile, 0}, 0}
};
void addAuxTheme(Location loc, uint32 lid); void addAuxTheme(Location loc, uint32 lid);
void killAuxTheme(uint32 lid); void killAuxTheme(uint32 lid);
void killAllAuxThemes(void); void killAllAuxThemes(void);
@ -138,45 +125,6 @@ extern GameObject *getViewCenterObject(void);
extern bool debugAudioThemes; extern bool debugAudioThemes;
#endif #endif
/* ===================================================================== *
Locals
* ===================================================================== */
static uint32 currentTheme = 0;
static uint32 auxTheme = 0;
static StaticPoint32 themeAt = {0, 0};
static int32 lastGameTime = 0;
static int32 elapsedGameTime = 0;
static bool playingExternalLoop = false;
int activeFactions[maxFactions];
static StaticTilePoint themeVectors[kMaxThemes] = {
{0, 0, 0},
{0, 0, 0},
{0, 0, 0},
{0, 0, 0},
{0, 0, 0},
{0, 0, 0},
{0, 0, 0},
{0, 0, 0},
{0, 0, 0},
{0, 0, 0},
{0, 0, 0},
{0, 0, 0},
{0, 0, 0},
{0, 0, 0},
{0, 0, 0},
{0, 0, 0}
};
int16 themeCount[kMaxThemes];
/* ===================================================================== * /* ===================================================================== *
Prototypes Prototypes
* ===================================================================== */ * ===================================================================== */
@ -210,10 +158,10 @@ void initAudioEnvirons(void) {
void addAuxTheme(Location loc, uint32 lid) { void addAuxTheme(Location loc, uint32 lid) {
for (int i = 0; i < AUXTHEMES; i++) { for (int i = 0; i < AUXTHEMES; i++) {
if (!aats[i].active) { if (!g_vm->_grandMasterFTA->_aats[i].active) {
aats[i].l.set(loc, loc.context); g_vm->_grandMasterFTA->_aats[i].l = loc;
aats[i].loopID = lid; g_vm->_grandMasterFTA->_aats[i].loopID = lid;
aats[i].active = true; g_vm->_grandMasterFTA->_aats[i].active = true;
return; return;
} }
} }
@ -221,15 +169,15 @@ void addAuxTheme(Location loc, uint32 lid) {
void killAuxTheme(uint32 lid) { void killAuxTheme(uint32 lid) {
for (int i = 0; i < AUXTHEMES; i++) { for (int i = 0; i < AUXTHEMES; i++) {
if (aats[i].active && aats[i].loopID == lid) { if (g_vm->_grandMasterFTA->_aats[i].active && g_vm->_grandMasterFTA->_aats[i].loopID == lid) {
aats[i].active = false; g_vm->_grandMasterFTA->_aats[i].active = false;
} }
} }
} }
void killAllAuxThemes(void) { void killAllAuxThemes(void) {
for (int i = 0; i < AUXTHEMES; i++) { for (int i = 0; i < AUXTHEMES; i++) {
aats[i].active = false; g_vm->_grandMasterFTA->_aats[i].active = false;
} }
} }
@ -237,24 +185,23 @@ void killAllAuxThemes(void) {
// Hooks to allow other loops to play // Hooks to allow other loops to play
void disableBGLoop(bool s) { void disableBGLoop(bool s) {
playingExternalLoop = s; g_vm->_grandMasterFTA->_playingExternalLoop = s;
} }
void enableBGLoop(void) { void enableBGLoop(void) {
uint32 cr = currentTheme; uint32 cr = g_vm->_grandMasterFTA->_currentTheme;
playingExternalLoop = false; g_vm->_grandMasterFTA->_playingExternalLoop = false;
currentTheme = 0; g_vm->_grandMasterFTA->_currentTheme = 0;
audioEnvironmentUseSet(cr, auxTheme, themeAt); audioEnvironmentUseSet(cr, g_vm->_grandMasterFTA->_auxTheme, g_vm->_grandMasterFTA->_themeAt);
} }
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// Main loop selection routine - called from Tile.cpp // Main loop selection routine - called from Tile.cpp
static int32 pct = 0;
void setAreaSound(const TilePoint &) { void setAreaSound(const TilePoint &) {
pct = (pct + 1) % 8; g_vm->_grandMasterFTA->_pct = (g_vm->_grandMasterFTA->_pct + 1) % 8;
if (pct == 0) { if (g_vm->_grandMasterFTA->_pct == 0) {
if (!playingExternalLoop) { if (!g_vm->_grandMasterFTA->_playingExternalLoop) {
TilePoint baseCoords = centerActorCoords() >> kTileUVShift; TilePoint baseCoords = centerActorCoords() >> kTileUVShift;
TilePoint mtPos; TilePoint mtPos;
metaTileNoise loopID = 0; metaTileNoise loopID = 0;
@ -274,16 +221,11 @@ void setAreaSound(const TilePoint &) {
themePos.x = dist.u; themePos.x = dist.u;
themePos.y = dist.v; themePos.y = dist.v;
MetaTilePtr mt = mIter.first(&mtPos); MetaTilePtr mt = mIter.first(&mtPos);
for (i = 0; i < 16; i++) {
themeVectors[i].set(0, 0, 0);
}
while (mt) { while (mt) {
i++; i++;
if (getSound(mt)) { if (getSound(mt)) {
j++; j++;
TilePoint thisDist = mtPos - baseCoords; TilePoint thisDist = mtPos - baseCoords;
int theme = getSound(mt);
themeCount[theme]++;
if (thisDist.magnitude() < dist.magnitude()) { if (thisDist.magnitude() < dist.magnitude()) {
dist = thisDist; dist = thisDist;
loopID = getSound(mt); loopID = getSound(mt);
@ -294,14 +236,14 @@ void setAreaSound(const TilePoint &) {
mt = mIter.next(&mtPos); mt = mIter.next(&mtPos);
} }
for (i = 0; i < AUXTHEMES; i++) { for (i = 0; i < AUXTHEMES; i++) {
if (aats[i].active) { if (g_vm->_grandMasterFTA->_aats[i].active) {
Location loc = getCenterActor()->notGetWorldLocation(); Location loc = getCenterActor()->notGetWorldLocation();
if (aats[i].l.context == Nothing || loc.context == aats[i].l.context) { if (g_vm->_grandMasterFTA->_aats[i].l.context == Nothing || loc.context == g_vm->_grandMasterFTA->_aats[i].l.context) {
TilePoint tp = (aats[i].l.tile >> kTileUVShift) - baseCoords; TilePoint tp = (g_vm->_grandMasterFTA->_aats[i].l >> kTileUVShift) - baseCoords;
if (tp.magnitude() < dist.magnitude()) { if (tp.magnitude() < dist.magnitude()) {
dist = tp; dist = tp;
loopID = USEAUXTHEME; loopID = USEAUXTHEME;
ss = aats[i].loopID; ss = g_vm->_grandMasterFTA->_aats[i].loopID;
themePos.x = tp.u; themePos.x = tp.u;
themePos.y = tp.v; themePos.y = tp.v;
} }
@ -313,8 +255,8 @@ void setAreaSound(const TilePoint &) {
loopID = 0; loopID = 0;
} }
audioEnvironmentUseSet(loopID, ss, themePos << kPlatShift); audioEnvironmentUseSet(loopID, ss, themePos << kPlatShift);
} else if (playingExternalLoop) { } else if (g_vm->_grandMasterFTA->_playingExternalLoop) {
audioEnvironmentUseSet(playingExternalLoop, 0, Point16(0, 0)); //themePos << kPlatShift); audioEnvironmentUseSet(g_vm->_grandMasterFTA->_playingExternalLoop, 0, Point16(0, 0)); //themePos << kPlatShift);
} }
} }
} }
@ -330,24 +272,24 @@ void audioEnvironmentUseSet(int16 audioSet, int32 auxID, Point32 relPos) {
res = metaNoiseID(audioSet); res = metaNoiseID(audioSet);
else else
res = 0; res = 0;
if (currentTheme != (uint16)audioSet || auxTheme != (uint32)auxID) { if (g_vm->_grandMasterFTA->_currentTheme != (uint16)audioSet || g_vm->_grandMasterFTA->_auxTheme != (uint32)auxID) {
currentTheme = audioSet; g_vm->_grandMasterFTA->_currentTheme = audioSet;
auxTheme = auxID; g_vm->_grandMasterFTA->_auxTheme = auxID;
themeAt.x = relPos.x; g_vm->_grandMasterFTA->_themeAt.x = relPos.x;
themeAt.y = relPos.y; g_vm->_grandMasterFTA->_themeAt.y = relPos.y;
_playLoop(0); _playLoop(0);
if (currentTheme) if (g_vm->_grandMasterFTA->_currentTheme)
playLoopAt(res, themeAt); playLoopAt(res, g_vm->_grandMasterFTA->_themeAt);
} else if (currentTheme && themeAt != relPos) { } else if (g_vm->_grandMasterFTA->_currentTheme && g_vm->_grandMasterFTA->_themeAt != relPos) {
#if DEBUG #if DEBUG
if (debugAudioThemes) { if (debugAudioThemes) {
WriteStatusF(9, "Thm: %2.2d (%d,%d) was (%d,%d) ", audioSet, relPos.x, relPos.y, themeAt.x, themeAt.y); WriteStatusF(9, "Thm: %2.2d (%d,%d) was (%d,%d) ", audioSet, relPos.x, relPos.y, g_vm->_grandMasterFTA->_themeAt.x, g_vm->_grandMasterFTA->_themeAt.y);
} }
#endif #endif
themeAt.x = relPos.x; g_vm->_grandMasterFTA->_themeAt.x = relPos.x;
themeAt.y = relPos.y; g_vm->_grandMasterFTA->_themeAt.y = relPos.y;
moveLoop(themeAt); moveLoop(g_vm->_grandMasterFTA->_themeAt);
} }
} }
@ -356,14 +298,14 @@ void audioEnvironmentUseSet(int16 audioSet, int32 auxID, Point32 relPos) {
void audioEnvironmentCheck(void) { void audioEnvironmentCheck(void) {
uint32 delta = gameTime - lastGameTime; uint32 delta = gameTime - g_vm->_grandMasterFTA->_lastGameTime;
lastGameTime = gameTime; g_vm->_grandMasterFTA->_lastGameTime = gameTime;
if (currentTheme > 0 && currentTheme <= kAudioTerrainLIMIT) { if (g_vm->_grandMasterFTA->_currentTheme > 0 && g_vm->_grandMasterFTA->_currentTheme <= kAudioTerrainLIMIT) {
elapsedGameTime += delta; g_vm->_grandMasterFTA->_elapsedGameTime += delta;
if (elapsedGameTime > kCheckGameTime) { if (g_vm->_grandMasterFTA->_elapsedGameTime > kCheckGameTime) {
int i; int i;
elapsedGameTime = 0; g_vm->_grandMasterFTA->_elapsedGameTime = 0;
const IntermittentAudioRecord &iar = intermittentAudioRecords[currentTheme]; const IntermittentAudioRecord &iar = intermittentAudioRecords[g_vm->_grandMasterFTA->_currentTheme];
int16 totalProb = iar.noSoundOdds; int16 totalProb = iar.noSoundOdds;
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++)
totalProb += iar.soundOdds[i]; totalProb += iar.soundOdds[i];
@ -376,17 +318,17 @@ void audioEnvironmentCheck(void) {
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++) {
if (pval < iar.soundOdds[i]) { if (pval < iar.soundOdds[i]) {
//GameObject *go=getViewCenterObject(); //GameObject *go=getViewCenterObject();
//Location cal=Location(TilePoint(themeAt.x,themeAt.y,0),go->IDParent()); //Location cal=Location(TilePoint(g_vm->_grandMasterFTA->_themeAt.x,g_vm->_grandMasterFTA->_themeAt.y,0),go->IDParent());
//playSound(metaNoiseID((currentTheme*10)+i)); //playSound(metaNoiseID((g_vm->_grandMasterFTA->_currentTheme*10)+i));
playSoundAt(metaNoiseID((currentTheme * 10) + i), themeAt); playSoundAt(metaNoiseID((g_vm->_grandMasterFTA->_currentTheme * 10) + i), g_vm->_grandMasterFTA->_themeAt);
return; return;
} else } else
pval -= iar.soundOdds[i]; pval -= iar.soundOdds[i];
} }
} }
} else if (currentTheme) } else if (g_vm->_grandMasterFTA->_currentTheme)
warning("currentTheme out of range: %d", currentTheme); warning("currentTheme out of range: %d", g_vm->_grandMasterFTA->_currentTheme);
} }
@ -440,20 +382,20 @@ void Deejay::select(void) {
// Faction enumeration routines // Faction enumeration routines
void clearActiveFactions(void) { void clearActiveFactions(void) {
for (int i = 0; i < maxFactions; i++) for (int i = 0; i < kMaxFactions; i++)
activeFactions[i] = 0; g_vm->_grandMasterFTA->_activeFactions[i] = 0;
} }
void incrementActiveFaction(Actor *a) { void incrementActiveFaction(Actor *a) {
activeFactions[a->_faction]++; g_vm->_grandMasterFTA->_activeFactions[a->_faction]++;
} }
void useActiveFactions(void) { void useActiveFactions(void) {
int highCount = 0; int highCount = 0;
int highFaction = 0; int highFaction = 0;
for (int i = 0; i < maxFactions; i++) { for (int i = 0; i < kMaxFactions; i++) {
if (activeFactions[i] > highCount) { if (g_vm->_grandMasterFTA->_activeFactions[i] > highCount) {
highCount = activeFactions[i]; highCount = g_vm->_grandMasterFTA->_activeFactions[i];
highFaction = i; highFaction = i;
} }
} }

View File

@ -27,10 +27,13 @@
#ifndef SAGA2_BEEGEE_H #ifndef SAGA2_BEEGEE_H
#define SAGA2_BEEGEE_H #define SAGA2_BEEGEE_H
#include "saga2/objproto.h"
namespace Saga2 { namespace Saga2 {
enum { enum {
kNoEnemy = -1, kNoEnemy = -1,
kAuxThemes = 2,
kMaxThemes = 16 kMaxThemes = 16
}; };
@ -41,6 +44,18 @@ enum {
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// Music selection brain // Music selection brain
struct AuxAudioTheme {
bool active;
Location l;
uint32 loopID;
AuxAudioTheme() {
active = false;
loopID = 0;
l = Nowhere;
}
};
class Deejay { class Deejay {
private: private:
int _enemy; int _enemy;
@ -51,8 +66,23 @@ private:
int _current; int _current;
int _currentID; int _currentID;
public: public:
uint32 _currentTheme;
uint32 _auxTheme;
Point32 _themeAt;
int32 _lastGameTime;
int32 _elapsedGameTime;
int32 _pct;
bool _playingExternalLoop;
int _activeFactions[kMaxFactions];
AuxAudioTheme _aats[kAuxThemes];
Deejay() { Deejay() {
_enemy = -1; _enemy = -1;
_aggr = false; _aggr = false;
@ -61,6 +91,14 @@ public:
_ugd = false; _ugd = false;
_current = 0; _current = 0;
_currentID = 0; _currentID = 0;
_currentTheme = 0;
_auxTheme = 0;
_lastGameTime = 0;
_elapsedGameTime = 0;
_pct = 0;
_playingExternalLoop = false;
memset(_activeFactions, 0, sizeof(_activeFactions));
} }
~Deejay() {} ~Deejay() {}

View File

@ -468,6 +468,11 @@ enum {
kDefaultReach = 24 kDefaultReach = 24
}; };
// Actor Constants
enum {
kMaxFactions = 64
};
} // end of namespace Saga2 } // end of namespace Saga2
#endif #endif