AVALANCHE: Add HighScore.
This commit is contained in:
parent
f2d5f65d33
commit
56e9d41ae8
8 changed files with 185 additions and 15 deletions
|
@ -57,6 +57,7 @@ AvalancheEngine::AvalancheEngine(OSystem *syst, const AvalancheGameDescription *
|
||||||
_nim = nullptr;
|
_nim = nullptr;
|
||||||
_ghostroom = nullptr;
|
_ghostroom = nullptr;
|
||||||
_help = nullptr;
|
_help = nullptr;
|
||||||
|
_highscore = nullptr;
|
||||||
|
|
||||||
_platform = gd->desc.platform;
|
_platform = gd->desc.platform;
|
||||||
initVariables();
|
initVariables();
|
||||||
|
@ -81,6 +82,7 @@ AvalancheEngine::~AvalancheEngine() {
|
||||||
delete _nim;
|
delete _nim;
|
||||||
delete _ghostroom;
|
delete _ghostroom;
|
||||||
delete _help;
|
delete _help;
|
||||||
|
delete _highscore;
|
||||||
|
|
||||||
for (int i = 0; i < 31; i++) {
|
for (int i = 0; i < 31; i++) {
|
||||||
for (int j = 0; j < 2; j++) {
|
for (int j = 0; j < 2; j++) {
|
||||||
|
@ -165,6 +167,7 @@ Common::ErrorCode AvalancheEngine::initialize() {
|
||||||
_nim = new Nim(this);
|
_nim = new Nim(this);
|
||||||
_ghostroom = new GhostRoom(this);
|
_ghostroom = new GhostRoom(this);
|
||||||
_help = new Help(this);
|
_help = new Help(this);
|
||||||
|
_highscore = new HighScore(this);
|
||||||
|
|
||||||
_graphics->init();
|
_graphics->init();
|
||||||
_dialogs->init();
|
_dialogs->init();
|
||||||
|
@ -200,7 +203,7 @@ void AvalancheEngine::synchronize(Common::Serializer &sz) {
|
||||||
sz.syncAsByte(_carryNum);
|
sz.syncAsByte(_carryNum);
|
||||||
for (int i = 0; i < kObjectNum; i++)
|
for (int i = 0; i < kObjectNum; i++)
|
||||||
sz.syncAsByte(_objects[i]);
|
sz.syncAsByte(_objects[i]);
|
||||||
sz.syncAsSint16LE(_dnascore);
|
sz.syncAsSint16LE(_score);
|
||||||
sz.syncAsSint32LE(_money);
|
sz.syncAsSint32LE(_money);
|
||||||
sz.syncAsByte(_room);
|
sz.syncAsByte(_room);
|
||||||
if (sz.isSaving())
|
if (sz.isSaving())
|
||||||
|
|
|
@ -46,6 +46,7 @@
|
||||||
#include "avalanche/help.h"
|
#include "avalanche/help.h"
|
||||||
#include "avalanche/shootemup.h"
|
#include "avalanche/shootemup.h"
|
||||||
#include "avalanche/mainmenu.h"
|
#include "avalanche/mainmenu.h"
|
||||||
|
#include "avalanche/highscore.h"
|
||||||
|
|
||||||
#include "common/serializer.h"
|
#include "common/serializer.h"
|
||||||
|
|
||||||
|
@ -91,6 +92,7 @@ public:
|
||||||
Nim *_nim;
|
Nim *_nim;
|
||||||
GhostRoom *_ghostroom;
|
GhostRoom *_ghostroom;
|
||||||
Help *_help;
|
Help *_help;
|
||||||
|
HighScore *_highscore;
|
||||||
|
|
||||||
OSystem *_system;
|
OSystem *_system;
|
||||||
|
|
||||||
|
@ -150,7 +152,7 @@ public:
|
||||||
// Former DNA structure
|
// Former DNA structure
|
||||||
byte _carryNum; // How many objects you're carrying...
|
byte _carryNum; // How many objects you're carrying...
|
||||||
bool _objects[kObjectNum]; // ...and which ones they are.
|
bool _objects[kObjectNum]; // ...and which ones they are.
|
||||||
int16 _dnascore; // your score, of course
|
int16 _score; // your score, of course
|
||||||
int32 _money; // your current amount of dosh
|
int32 _money; // your current amount of dosh
|
||||||
Room _room; // your current room
|
Room _room; // your current room
|
||||||
bool _wonNim; // Have you *won* Nim? (That's harder.)
|
bool _wonNim; // Have you *won* Nim? (That's harder.)
|
||||||
|
|
|
@ -955,7 +955,7 @@ void AvalancheEngine::drawToolbar() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void AvalancheEngine::drawScore() {
|
void AvalancheEngine::drawScore() {
|
||||||
uint16 score = _dnascore;
|
uint16 score = _score;
|
||||||
int8 numbers[3] = {0, 0, 0};
|
int8 numbers[3] = {0, 0, 0};
|
||||||
for (int i = 0; i < 2; i++) {
|
for (int i = 0; i < 2; i++) {
|
||||||
byte divisor = 1;
|
byte divisor = 1;
|
||||||
|
@ -981,12 +981,12 @@ void AvalancheEngine::drawScore() {
|
||||||
|
|
||||||
void AvalancheEngine::incScore(byte num) {
|
void AvalancheEngine::incScore(byte num) {
|
||||||
for (int i = 1; i <= num; i++) {
|
for (int i = 1; i <= num; i++) {
|
||||||
_dnascore++;
|
_score++;
|
||||||
|
|
||||||
if (_soundFx) {
|
if (_soundFx) {
|
||||||
for (int j = 1; j <= 97; j++)
|
for (int j = 1; j <= 97; j++)
|
||||||
// Length of 2 is a guess, the original doesn't have a delay specified
|
// Length of 2 is a guess, the original doesn't have a delay specified
|
||||||
_sound->playNote(177 + _dnascore * 3, 2);
|
_sound->playNote(177 + _score * 3, 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1333,7 +1333,7 @@ void AvalancheEngine::resetVariables() {
|
||||||
for (int i = 0; i < kObjectNum; i++)
|
for (int i = 0; i < kObjectNum; i++)
|
||||||
_objects[i] = false;
|
_objects[i] = false;
|
||||||
|
|
||||||
_dnascore = 0;
|
_score = 0;
|
||||||
_money = 0;
|
_money = 0;
|
||||||
_room = kRoomNowhere;
|
_room = kRoomNowhere;
|
||||||
_saveNum = 0;
|
_saveNum = 0;
|
||||||
|
|
110
engines/avalanche/highscore.cpp
Normal file
110
engines/avalanche/highscore.cpp
Normal file
|
@ -0,0 +1,110 @@
|
||||||
|
/* 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This code is based on the original source code of Lord Avalot d'Argent version 1.3.
|
||||||
|
* Copyright (c) 1994-1995 Mike: Mark and Thomas Thurman.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "avalanche/avalanche.h"
|
||||||
|
#include "avalanche/highscore.h"
|
||||||
|
|
||||||
|
#include "common/savefile.h"
|
||||||
|
|
||||||
|
namespace Avalanche {
|
||||||
|
|
||||||
|
HighScore::HighScore(AvalancheEngine *vm) {
|
||||||
|
_vm = vm;
|
||||||
|
}
|
||||||
|
|
||||||
|
void HighScore::displayHighScores() {
|
||||||
|
warning("STUB: HighScore::displayHighScores(");
|
||||||
|
}
|
||||||
|
|
||||||
|
void HighScore::saveHighScores() {
|
||||||
|
int firstSmaller = 0;
|
||||||
|
while ((_data[firstSmaller]._score >= _vm->_score) && (firstSmaller < 12))
|
||||||
|
firstSmaller++;
|
||||||
|
|
||||||
|
if (firstSmaller < 12) {
|
||||||
|
// Shift all the lower scores down a space:
|
||||||
|
for (int i = firstSmaller; i < 11; i++)
|
||||||
|
_data[i + 1] = _data[i];
|
||||||
|
// Set the new high score:
|
||||||
|
_data[firstSmaller]._name = "Player"; // TODO: Come up with something for that. In the original it wasn't implemented at all...
|
||||||
|
_data[firstSmaller]._rank = _vm->_parser->rank();
|
||||||
|
_data[firstSmaller]._score = _vm->_score;
|
||||||
|
}
|
||||||
|
|
||||||
|
Common::OutSaveFile *f = g_system->getSavefileManager()->openForSaving("scores.avd");
|
||||||
|
if (!f) {
|
||||||
|
warning("Can't create file 'scores.avd', high scores are not saved.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Common::Serializer sz(NULL, f);
|
||||||
|
syncHighScores(sz);
|
||||||
|
f->finalize();
|
||||||
|
delete f;
|
||||||
|
}
|
||||||
|
|
||||||
|
void HighScore::loadHighScroes() {
|
||||||
|
Common::File file;
|
||||||
|
if (!file.exists("scores.avd")) {
|
||||||
|
produceDefaultHighScores();
|
||||||
|
} else {
|
||||||
|
Common::InSaveFile *f = g_system->getSavefileManager()->openForLoading("scores.avd");
|
||||||
|
if (!f)
|
||||||
|
return;
|
||||||
|
Common::Serializer sz(f, NULL);
|
||||||
|
syncHighScores(sz);
|
||||||
|
delete f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void HighScore::produceDefaultHighScores() {
|
||||||
|
for (int i = 0; i < 12; i++) {
|
||||||
|
_data[i]._score = 32 - (i + 1) * 2;
|
||||||
|
_data[i]._rank = "...";
|
||||||
|
}
|
||||||
|
_data[0]._name = "Mike";
|
||||||
|
_data[1]._name = "Liz";
|
||||||
|
_data[2]._name = "Thomas";
|
||||||
|
_data[3]._name = "Mark";
|
||||||
|
_data[4]._name = "Mandy";
|
||||||
|
_data[5]._name = "Andrew";
|
||||||
|
_data[6]._name = "Lucy Tryphena";
|
||||||
|
_data[7]._name = "Tammy the dog";
|
||||||
|
_data[8]._name = "Avaricius";
|
||||||
|
_data[9]._name = "Spellchick";
|
||||||
|
_data[10]._name = "Caddelli";
|
||||||
|
_data[11]._name = "Spludwick";
|
||||||
|
}
|
||||||
|
|
||||||
|
void HighScore::syncHighScores(Common::Serializer &sz) {
|
||||||
|
for (int i = 0; i < 12; i++) {
|
||||||
|
sz.syncString(_data[i]._name);
|
||||||
|
sz.syncAsUint16LE(_data[i]._score);
|
||||||
|
sz.syncString(_data[i]._rank);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // End of namespace Avalanche
|
59
engines/avalanche/highscore.h
Normal file
59
engines/avalanche/highscore.h
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
/* 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This code is based on the original source code of Lord Avalot d'Argent version 1.3.
|
||||||
|
* Copyright (c) 1994-1995 Mike: Mark and Thomas Thurman.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef AVALANCHE_HIGHSCORE_H
|
||||||
|
#define AVALANCHE_HIGHSCORE_H
|
||||||
|
|
||||||
|
namespace Avalanche {
|
||||||
|
class AvalancheEngine;
|
||||||
|
|
||||||
|
struct HighScoreData {
|
||||||
|
Common::String _name;
|
||||||
|
uint16 _score;
|
||||||
|
Common::String _rank;
|
||||||
|
};
|
||||||
|
|
||||||
|
class HighScore {
|
||||||
|
public:
|
||||||
|
HighScore(AvalancheEngine *vm);
|
||||||
|
|
||||||
|
void displayHighScores();
|
||||||
|
void saveHighScores();
|
||||||
|
void loadHighScroes();
|
||||||
|
|
||||||
|
private:
|
||||||
|
AvalancheEngine *_vm;
|
||||||
|
|
||||||
|
HighScoreData _data[12];
|
||||||
|
|
||||||
|
void produceDefaultHighScores();
|
||||||
|
void syncHighScores(Common::Serializer &sz);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // End of namespace Avalanche
|
||||||
|
|
||||||
|
#endif // AVALANCHE_HIGHSCORE_H
|
|
@ -20,7 +20,8 @@ MODULE_OBJS = \
|
||||||
ghostroom.o \
|
ghostroom.o \
|
||||||
help.o \
|
help.o \
|
||||||
shootemup.o \
|
shootemup.o \
|
||||||
mainmenu.o
|
mainmenu.o \
|
||||||
|
highscore.o
|
||||||
|
|
||||||
# This module can be built as a plugin
|
# This module can be built as a plugin
|
||||||
ifeq ($(ENABLE_AVALANCHE), DYNAMIC_PLUGIN)
|
ifeq ($(ENABLE_AVALANCHE), DYNAMIC_PLUGIN)
|
||||||
|
|
|
@ -602,7 +602,7 @@ Common::String Parser::rank() {
|
||||||
};
|
};
|
||||||
|
|
||||||
for (int i = 0; i < 8; i++) {
|
for (int i = 0; i < 8; i++) {
|
||||||
if ((_vm->_dnascore >= ranks[i]._score) && (_vm->_dnascore < ranks[i + 1]._score))
|
if ((_vm->_score >= ranks[i]._score) && (_vm->_score < ranks[i + 1]._score))
|
||||||
return Common::String(ranks[i]._title);
|
return Common::String(ranks[i]._title);
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
|
@ -2306,7 +2306,7 @@ void Parser::doThat() {
|
||||||
break;
|
break;
|
||||||
case kVerbCodeScore: {
|
case kVerbCodeScore: {
|
||||||
Common::String tmpStr = Common::String::format("Your score is %d,%c%cout of a possible 128.%c%c " \
|
Common::String tmpStr = Common::String::format("Your score is %d,%c%cout of a possible 128.%c%c " \
|
||||||
"This gives you a rank of %s.%c%c%s", _vm->_dnascore, kControlCenter, kControlNewLine, kControlNewLine,
|
"This gives you a rank of %s.%c%c%s", _vm->_score, kControlCenter, kControlNewLine, kControlNewLine,
|
||||||
kControlNewLine, rank().c_str(), kControlNewLine, kControlNewLine, totalTime().c_str());
|
kControlNewLine, rank().c_str(), kControlNewLine, kControlNewLine, totalTime().c_str());
|
||||||
_vm->_dialogs->displayText(tmpStr);
|
_vm->_dialogs->displayText(tmpStr);
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,13 +72,11 @@ public:
|
||||||
byte _wearing; // what you're wearing
|
byte _wearing; // what you're wearing
|
||||||
|
|
||||||
Parser(AvalancheEngine *vm);
|
Parser(AvalancheEngine *vm);
|
||||||
|
|
||||||
void init();
|
void init();
|
||||||
void parse();
|
void parse();
|
||||||
void doThat();
|
void doThat();
|
||||||
void verbOpt(byte verb, Common::String &answer, char &ansKey);
|
void verbOpt(byte verb, Common::String &answer, char &ansKey);
|
||||||
void drink();
|
void drink();
|
||||||
|
|
||||||
void handleInputText(const Common::Event &event);
|
void handleInputText(const Common::Event &event);
|
||||||
void handleBackspace();
|
void handleBackspace();
|
||||||
void handleReturn();
|
void handleReturn();
|
||||||
|
@ -89,7 +87,7 @@ public:
|
||||||
void tryDropdown();
|
void tryDropdown();
|
||||||
int16 getPos(const Common::String &crit, const Common::String &src);
|
int16 getPos(const Common::String &crit, const Common::String &src);
|
||||||
void doVerb(VerbCode id);
|
void doVerb(VerbCode id);
|
||||||
|
Common::String rank();
|
||||||
void resetVariables();
|
void resetVariables();
|
||||||
void synchronize(Common::Serializer &sz);
|
void synchronize(Common::Serializer &sz);
|
||||||
|
|
||||||
|
@ -112,10 +110,7 @@ private:
|
||||||
|
|
||||||
byte wordNum(Common::String word);
|
byte wordNum(Common::String word);
|
||||||
void replace(Common::String oldChars, byte newChar);
|
void replace(Common::String oldChars, byte newChar);
|
||||||
|
|
||||||
Common::String rank();
|
|
||||||
Common::String totalTime();
|
Common::String totalTime();
|
||||||
|
|
||||||
void clearWords();
|
void clearWords();
|
||||||
void cheatParse(Common::String codes);
|
void cheatParse(Common::String codes);
|
||||||
void stripPunctuation(Common::String &word);
|
void stripPunctuation(Common::String &word);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue