ULTIMA4: Move moongates array to an engine field

This commit is contained in:
Paul Gilbert committed 2020-04-25 14:47:09 -07:00
1 parent eb885e9da1
commit 8efbf33f95
8 files changed
+67 -38

No files matched your search

@@ -386,50 +386,50 @@ void GameController::updateMoons(bool showmoongates) {
if (showmoongates) {
/* update the moongates if trammel changed */
if (trammelSubphase == 0) {
gate = moongateGetGateCoordsForPhase(oldTrammel);
gate = g_moongates->getGateCoordsForPhase(oldTrammel);
if (gate)
g_context->_location->_map->_annotations->remove(*gate, g_context->_location->_map->translateFromRawTileIndex(0x40));
gate = moongateGetGateCoordsForPhase(g_ultima->_saveGame->_trammelPhase);
gate = g_moongates->getGateCoordsForPhase(g_ultima->_saveGame->_trammelPhase);
if (gate)
g_context->_location->_map->_annotations->add(*gate, g_context->_location->_map->translateFromRawTileIndex(0x40));
} else if (trammelSubphase == 1) {
gate = moongateGetGateCoordsForPhase(g_ultima->_saveGame->_trammelPhase);
gate = g_moongates->getGateCoordsForPhase(g_ultima->_saveGame->_trammelPhase);
if (gate) {
g_context->_location->_map->_annotations->remove(*gate, g_context->_location->_map->translateFromRawTileIndex(0x40));
g_context->_location->_map->_annotations->add(*gate, g_context->_location->_map->translateFromRawTileIndex(0x41));
}
} else if (trammelSubphase == 2) {
gate = moongateGetGateCoordsForPhase(g_ultima->_saveGame->_trammelPhase);
gate = g_moongates->getGateCoordsForPhase(g_ultima->_saveGame->_trammelPhase);
if (gate) {
g_context->_location->_map->_annotations->remove(*gate, g_context->_location->_map->translateFromRawTileIndex(0x41));
g_context->_location->_map->_annotations->add(*gate, g_context->_location->_map->translateFromRawTileIndex(0x42));
}
} else if (trammelSubphase == 3) {
gate = moongateGetGateCoordsForPhase(g_ultima->_saveGame->_trammelPhase);
gate = g_moongates->getGateCoordsForPhase(g_ultima->_saveGame->_trammelPhase);
if (gate) {
g_context->_location->_map->_annotations->remove(*gate, g_context->_location->_map->translateFromRawTileIndex(0x42));
g_context->_location->_map->_annotations->add(*gate, g_context->_location->_map->translateFromRawTileIndex(0x43));
}
} else if ((trammelSubphase > 3) && (trammelSubphase < (MOON_SECONDS_PER_PHASE * 4 * 3) - 3)) {
gate = moongateGetGateCoordsForPhase(g_ultima->_saveGame->_trammelPhase);
gate = g_moongates->getGateCoordsForPhase(g_ultima->_saveGame->_trammelPhase);
if (gate) {
g_context->_location->_map->_annotations->remove(*gate, g_context->_location->_map->translateFromRawTileIndex(0x43));
g_context->_location->_map->_annotations->add(*gate, g_context->_location->_map->translateFromRawTileIndex(0x43));
}
} else if (trammelSubphase == (MOON_SECONDS_PER_PHASE * 4 * 3) - 3) {
gate = moongateGetGateCoordsForPhase(g_ultima->_saveGame->_trammelPhase);
gate = g_moongates->getGateCoordsForPhase(g_ultima->_saveGame->_trammelPhase);
if (gate) {
g_context->_location->_map->_annotations->remove(*gate, g_context->_location->_map->translateFromRawTileIndex(0x43));
g_context->_location->_map->_annotations->add(*gate, g_context->_location->_map->translateFromRawTileIndex(0x42));
}
} else if (trammelSubphase == (MOON_SECONDS_PER_PHASE * 4 * 3) - 2) {
gate = moongateGetGateCoordsForPhase(g_ultima->_saveGame->_trammelPhase);
gate = g_moongates->getGateCoordsForPhase(g_ultima->_saveGame->_trammelPhase);
if (gate) {
g_context->_location->_map->_annotations->remove(*gate, g_context->_location->_map->translateFromRawTileIndex(0x42));
g_context->_location->_map->_annotations->add(*gate, g_context->_location->_map->translateFromRawTileIndex(0x41));
}
} else if (trammelSubphase == (MOON_SECONDS_PER_PHASE * 4 * 3) - 1) {
gate = moongateGetGateCoordsForPhase(g_ultima->_saveGame->_trammelPhase);
gate = g_moongates->getGateCoordsForPhase(g_ultima->_saveGame->_trammelPhase);
if (gate) {
g_context->_location->_map->_annotations->remove(*gate, g_context->_location->_map->translateFromRawTileIndex(0x41));
g_context->_location->_map->_annotations->add(*gate, g_context->_location->_map->translateFromRawTileIndex(0x40));
@@ -670,7 +670,7 @@ void GameController::checkSpecialCreatures(Direction dir) {
bool GameController::checkMoongates() {
Coords dest;
if (moongateFindActiveGateAt(g_ultima->_saveGame->_trammelPhase, g_ultima->_saveGame->_feluccaPhase, g_context->_location->_coords, dest)) {
if (g_moongates->findActiveGateAt(g_ultima->_saveGame->_trammelPhase, g_ultima->_saveGame->_feluccaPhase, g_context->_location->_coords, dest)) {
gameSpellEffect(-1, -1, SOUND_MOONGATE); // Default spell effect (screen inversion without 'spell' sound effects)
@@ -679,7 +679,7 @@ bool GameController::checkMoongates() {
gameSpellEffect(-1, -1, SOUND_MOONGATE); // Again, after arriving
}
if (moongateIsEntryToShrineOfSpirituality(g_ultima->_saveGame->_trammelPhase, g_ultima->_saveGame->_feluccaPhase)) {
if (g_moongates->isEntryToShrineOfSpirituality(g_ultima->_saveGame->_trammelPhase, g_ultima->_saveGame->_feluccaPhase)) {
Shrine *shrine_spirituality;
shrine_spirituality = dynamic_cast<Shrine *>(mapMgr->get(MAP_SHRINE_SPIRITUALITY));
+1 -1
View File
@@ -1299,7 +1299,7 @@ bool Debugger::cmdGate(int argc, const char **argv) {
print("Gate %d!", gateNum);
if (g_context->_location->_map->isWorldMap()) {
const Coords *moongate = moongateGetGateCoordsForPhase(gateNum - 1);
const Coords *moongate = g_moongates->getGateCoordsForPhase(gateNum - 1);
if (moongate) {
g_context->_location->_coords = *moongate;
return false;
+24 -16
View File
@@ -28,41 +28,49 @@
namespace Ultima {
namespace Ultima4 {
typedef Std::map<int, Coords> MoongateList; /* map moon phase to map coordinates */
Moongates *g_moongates;
MoongateList gates;
void moongateAdd(int phase, const Coords &coords) {
if (gates.contains(phase))
error("Error: A moongate for phase %d already exists", phase);
gates[phase] = coords;
Moongates::Moongates() {
g_moongates = this;
}
const Coords *moongateGetGateCoordsForPhase(int phase) {
MoongateList::iterator moongate;
Moongates::~Moongates() {
g_moongates = nullptr;
}
moongate = gates.find(phase);
if (moongate != gates.end())
void Moongates::add(int phase, const Coords &coords) {
if (contains(phase))
error("Error: A moongate for phase %d already exists", phase);
(*this)[phase] = coords;
}
const Coords *Moongates::getGateCoordsForPhase(int phase) {
iterator moongate;
moongate = find(phase);
if (moongate != end())
return &moongate->_value;
return nullptr;
}
bool moongateFindActiveGateAt(int trammel, int felucca, const Coords &src, Coords &dest) {
bool Moongates::findActiveGateAt(int trammel, int felucca, const Coords &src, Coords &dest) {
const Coords *moongate_coords;
moongate_coords = moongateGetGateCoordsForPhase(trammel);
moongate_coords = getGateCoordsForPhase(trammel);
if (moongate_coords && (src == *moongate_coords)) {
moongate_coords = moongateGetGateCoordsForPhase(felucca);
moongate_coords = getGateCoordsForPhase(felucca);
if (moongate_coords) {
dest = *moongate_coords;
return true;
}
}
return false;
}
bool moongateIsEntryToShrineOfSpirituality(int trammel, int felucca) {
bool Moongates::isEntryToShrineOfSpirituality(int trammel, int felucca) {
return (trammel == 4 && felucca == 4) ? true : false;
}
+21 -5
View File
@@ -23,15 +23,31 @@
#ifndef ULTIMA4_GAME_MOONGATE_H
#define ULTIMA4_GAME_MOONGATE_H
#include "ultima/ultima4/core/coords.h"
#include "common/hashmap.h"
namespace Ultima {
namespace Ultima4 {
class Coords;
class Moongates : public Common::HashMap<int, Coords> {
public:
/**
* Constructor
*/
Moongates();
void moongateAdd(int phase, const Coords &coords);
const Coords *moongateGetGateCoordsForPhase(int phase);
bool moongateFindActiveGateAt(int trammel, int felucca, const Coords &src, Coords &dest);
bool moongateIsEntryToShrineOfSpirituality(int trammel, int felucca);
/**
* Destructor
*/
~Moongates();
void add(int phase, const Coords &coords);
const Coords *getGateCoordsForPhase(int phase);
bool findActiveGateAt(int trammel, int felucca, const Coords &src, Coords &dest);
bool isEntryToShrineOfSpirituality(int trammel, int felucca);
};
extern Moongates *g_moongates;
} // End of namespace Ultima4
} // End of namespace Ultima
+1 -1
View File
@@ -613,7 +613,7 @@ static int spellGate(int phase) {
GameController::flashTile(g_context->_location->_coords, "moongate", 2);
moongate = moongateGetGateCoordsForPhase(phase);
moongate = g_moongates->getGateCoordsForPhase(phase);
if (moongate)
g_context->_location->_coords = *moongate;
+1 -1
View File
@@ -336,7 +336,7 @@ void MapMgr::createMoongateFromConf(const ConfigElement &moongateConf) {
int phase = moongateConf.getInt("phase");
Coords coords(moongateConf.getInt("x"), moongateConf.getInt("y"));
moongateAdd(phase, coords);
g_moongates->add(phase, coords);
}
int MapMgr::initCompressedChunkFromConf(const ConfigElement &compressedChunkConf) {
+6 -3
View File
@@ -32,6 +32,7 @@
#include "ultima/ultima4/game/armor.h"
#include "ultima/ultima4/game/context.h"
#include "ultima/ultima4/game/game.h"
#include "ultima/ultima4/game/moongate.h"
#include "ultima/ultima4/game/person.h"
#include "ultima/ultima4/gfx/screen.h"
#include "ultima/ultima4/gfx/imageloader.h"
@@ -51,12 +52,13 @@ Ultima4Engine *g_ultima;
Ultima4Engine::Ultima4Engine(OSystem *syst, const Ultima::UltimaGameDescription *gameDesc) :
Shared::UltimaEngine(syst, gameDesc), _saveSlotToLoad(-1), _armors(nullptr),
_config(nullptr), _context(nullptr), _dialogueLoaders(nullptr), _game(nullptr),
_music(nullptr), _imageLoaders(nullptr), _saveGame(nullptr), _screen(nullptr),
_tileMaps(nullptr), _tileRules(nullptr), _tileSets(nullptr) {
_music(nullptr), _imageLoaders(nullptr), _moongates(nullptr), _saveGame(nullptr),
_screen(nullptr), _tileMaps(nullptr), _tileRules(nullptr), _tileSets(nullptr) {
g_ultima = this;
g_armors = nullptr;
g_context = nullptr;
g_game = nullptr;
g_moongates = nullptr;
g_screen = nullptr;
g_tileMaps = nullptr;
g_tileRules = nullptr;
@@ -70,6 +72,7 @@ Ultima4Engine::~Ultima4Engine() {
delete _dialogueLoaders;
delete _game;
delete _imageLoaders;
delete _moongates;
delete _music;
delete _saveGame;
delete _screen;
@@ -92,6 +95,7 @@ bool Ultima4Engine::initialize() {
_armors = new Armors();
_context = new Context();
_dialogueLoaders = new DialogueLoaders();
_moongates = new Moongates();
_screen = new Screen();
_screen->init();
_tileRules = new TileRules();
@@ -108,7 +112,6 @@ bool Ultima4Engine::initialize() {
_saveSlotToLoad = ConfMan.hasKey("save_slot") ? ConfMan.getInt("save_slot") : -1;
return true;
}
+2
View File
@@ -35,6 +35,7 @@ class Context;
class DialogueLoaders;
class ImageLoaders;
class GameController;
class Moongates;
class Music;
struct SaveGame;
class Screen;
@@ -64,6 +65,7 @@ public:
DialogueLoaders *_dialogueLoaders;
ImageLoaders *_imageLoaders;
GameController *_game;
Moongates *_moongates;
Music *_music;
SaveGame *_saveGame;
Screen *_screen;