ULTIMA1: Refactored quest flags list into it's own class

This commit is contained in:
Paul Gilbert 2020-01-19 21:26:58 -08:00 committed by Paul Gilbert
parent 5fb10f662d
commit a19b789f15
6 changed files with 164 additions and 23 deletions

View File

@ -70,6 +70,7 @@ MODULE_OBJS += \
ultima1/actions/ready.o \
ultima1/actions/stats.o \
ultima1/core/party.o \
ultima1/core/quests.o \
ultima1/core/resources.o \
ultima1/maps/map.o \
ultima1/maps/map_base.o \

View File

@ -0,0 +1,57 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, In, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "ultima/ultima1/core/quests.h"
#include "ultima/ultima1/core/resources.h"
#include "ultima/ultima1/game.h"
namespace Ultima {
namespace Ultima1 {
Quests::Quests(Ultima1Game *game) {
for (int idx = 0; idx < FLAGS_COUNT; ++idx)
push_back(QuestFlag(game));
}
void Quests::synchronize(Common::Serializer &s) {
for (uint idx = 0; idx < size(); ++idx)
(*this)[idx].synchronize(s);
}
/*-------------------------------------------------------------------*/
void QuestFlag::synchronize(Common::Serializer &s) {
s.syncAsByte(_state);
}
void QuestFlag::complete() {
if (isInProgress()) {
_state = COMPLETED;
Shared::CInfoMsg msg(_game->_res->QUEST_COMPLETED, true);
msg.execute(_game);
_game->playFX(5);
}
}
} // End of namespace Ultima1
} // End of namespace Ultima

View File

@ -0,0 +1,99 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#ifndef ULTIMA_ULTIMA1_CORE_QUESTS_H
#define ULTIMA_ULTIMA1_CORE_QUESTS_H
#include "common/array.h"
#include "common/serializer.h"
namespace Ultima {
namespace Ultima1 {
#define FLAGS_COUNT 9
class Ultima1Game;
/**
* Quest entry
*/
class QuestFlag {
enum FlagState { UNSTARTED = 0, IN_PROGRESS = -1, COMPLETED = 1 };
private:
Ultima1Game *_game;
FlagState _state;
public:
/**
* Constructor
*/
QuestFlag() : _game(nullptr), _state(UNSTARTED) {}
/**
* Constructor
*/
QuestFlag(Ultima1Game *game) : _game(game), _state(UNSTARTED) {}
/**
* Synchronize the data for a single flag
*/
void synchronize(Common::Serializer &s);
/**
* Returns true if the quest is unstarted
*/
bool isUnstarted() const { return _state == UNSTARTED; }
/**
* Returns true if the quest is in progress
*/
bool isInProgress() const { return _state == IN_PROGRESS; }
/**
* Called when a quest is completed
*/
bool isComplete() const { return _state == COMPLETED; }
/**
* Complete an in-progress quest
*/
void complete();
};
/**
* Manages the list of quest flags
*/
class Quests : public Common::Array<QuestFlag> {
public:
/**
* Constructor
*/
Quests(Ultima1Game *game);
/**
* Synchronize the data for a single flag
*/
void synchronize(Common::Serializer &s);
};
} // End of namespace Ultima1
} // End of namespace Ultima
#endif

View File

@ -40,7 +40,7 @@ namespace Ultima1 {
EMPTY_MESSAGE_MAP(Ultima1Game, Shared::Game);
Ultima1Game::Ultima1Game() : Shared::Game() {
Ultima1Game::Ultima1Game() : Shared::Game(), _quests(this) {
_res = new GameResources();
_map = new Maps::Ultima1Map(this);
_party = new Party(this);
@ -63,7 +63,6 @@ Ultima1Game::Ultima1Game() : Shared::Game() {
}
Common::fill(&_gems[0], &_gems[4], 0);
Common::fill(&_questFlags[0], &_questFlags[9], UNSTARTED);
}
Ultima1Game::~Ultima1Game() {
@ -81,8 +80,7 @@ void Ultima1Game::synchronize(Common::Serializer &s) {
for (int idx = 0; idx < 4; ++idx)
s.syncAsUint16LE(_gems[idx]);
for (int idx = 0; idx < 9; ++idx)
s.syncAsSint16LE(_questFlags[idx]);
_quests.synchronize(s);
}
void Ultima1Game::starting(bool isLoading) {
@ -101,16 +99,5 @@ void Ultima1Game::giveTreasure(int coins, int v2) {
// TODO
}
void Ultima1Game::questCompleted(uint questNum) {
assert(questNum < 9);
if (_questFlags[questNum] == IN_PROGRESS) {
_questFlags[questNum] = COMPLETED;
Shared::CInfoMsg msg(_res->QUEST_COMPLETED, true);
msg.execute(this);
playFX(5);
}
}
} // End of namespace Ultima1
} // End of namespace Ultima

View File

@ -25,6 +25,7 @@
#include "ultima/shared/early/game.h"
#include "ultima/shared/gfx/visual_container.h"
#include "ultima/ultima1/core/quests.h"
namespace Ultima {
namespace Ultima1 {
@ -41,14 +42,13 @@ class GameResources;
class Ultima1Game : public Shared::Game {
DECLARE_MESSAGE_MAP;
enum QuestFlag { UNSTARTED = 0, IN_PROGRESS = -1, COMPLETED = 1 };
public:
GameResources *_res;
Shared::Gfx::VisualItem *_gameView;
Shared::Gfx::VisualItem *_titleView;
Shared::Gfx::VisualItem *_charGenView;
uint _gems[4];
QuestFlag _questFlags[9];
Quests _quests;
public:
CLASSDEF;
Ultima1Game();
@ -78,11 +78,6 @@ public:
* Give some treasure
*/
void giveTreasure(int coins, int v2);
/**
* Called when a quest is completed
*/
void questCompleted(uint questNum);
};
} // End of namespace Ultima1

View File

@ -258,7 +258,9 @@ void DungeonMonster::monsterDead() {
}
if (index) {
static_cast<Ultima1Game *>(_game)->questCompleted(8 - index);
// Mark monster-based quests as complete if in progress
Ultima1Game *game = static_cast<Ultima1Game *>(_game);
game->_quests[8 - index].complete();
}
}