Skip to content

Commit

Permalink
HOPKINS: Get rid of a magic value, rename a couple of pathfinding fun…
Browse files Browse the repository at this point in the history
…ctions
  • Loading branch information
Strangerke committed Jan 10, 2013
1 parent de93e44 commit 9f153a3
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 21 deletions.
2 changes: 1 addition & 1 deletion engines/hopkins/globals.cpp
Expand Up @@ -324,7 +324,7 @@ void Globals::clearAll() {
BufLig = (int16 *)g_PTRNUL;
chemin = (int16 *)g_PTRNUL;

for (int idx = 0; idx < 400; ++idx) {
for (int idx = 0; idx < MAX_LINES; ++idx) {
_vm->_linesManager.Ligne[idx]._lineDataEndIdx = 0;
_vm->_linesManager.Ligne[idx].field2 = 0;
_vm->_linesManager.Ligne[idx].field4 = 0;
Expand Down
2 changes: 2 additions & 0 deletions engines/hopkins/hopkins.h
Expand Up @@ -73,6 +73,8 @@ enum {
#define SCREEN_WIDTH 640
#define SCREEN_HEIGHT 480

#define MAX_LINES 400

struct HopkinsGameDescription;

class HopkinsEngine : public Engine {
Expand Down
24 changes: 12 additions & 12 deletions engines/hopkins/lines.cpp
Expand Up @@ -29,7 +29,7 @@
namespace Hopkins {

LinesManager::LinesManager() {
for (int i = 0; i < 400; ++i) {
for (int i = 0; i < MAX_LINES; ++i) {
Common::fill((byte *)&_zoneLine[i], (byte *)&_zoneLine[i] + sizeof(LigneZoneItem), 0);
Common::fill((byte *)&Ligne[i], (byte *)&Ligne[i] + sizeof(LigneItem), 0);
}
Expand All @@ -53,7 +53,7 @@ void LinesManager::setParent(HopkinsEngine *vm) {
}

void LinesManager::CLEAR_ZONE() {
for (int idx = 0; idx < 400; ++idx)
for (int idx = 0; idx < MAX_LINES; ++idx)
removeZoneLine(idx);

next_ligne = 0;
Expand Down Expand Up @@ -120,7 +120,7 @@ int LinesManager::OPTI_ZONE(int posX, int minZoneNum, bool lastRow) {
* Remove Zone Line
*/
void LinesManager::removeZoneLine(int idx) {
if (idx > 400)
if (idx > MAX_LINES)
error("Attempting to remove a line obstacle > MAX_LIGNE.");

_vm->_linesManager._zoneLine[idx].zoneData = (int16 *)_vm->_globals.freeMemory((byte *)_vm->_linesManager._zoneLine[idx].zoneData);
Expand All @@ -136,7 +136,7 @@ void LinesManager::addZoneLine(int idx, int a2, int a3, int a4, int a5, int bobZ
_vm->_globals.BOBZONE_FLAG[bobZoneIdx] = true;
_vm->_globals.BOBZONE[bobZoneIdx] = a3;
} else {
if (idx > 400)
if (idx > MAX_LINES)
error("Attempting to add a line obstacle > MAX_LIGNE.");

_zoneLine[idx].zoneData = (int16 *)_vm->_globals.freeMemory((byte *)_zoneLine[idx].zoneData);
Expand Down Expand Up @@ -180,17 +180,17 @@ void LinesManager::addZoneLine(int idx, int a2, int a3, int a4, int a5, int bobZ
}


void LinesManager::RESET_OBSTACLE() {
for (int idx = 0; idx < 400; ++idx) {
RETIRE_LIGNE(idx);
void LinesManager::resetLines() {
for (int idx = 0; idx < MAX_LINES; ++idx) {
removeLine(idx);
Ligne[idx]._lineDataEndIdx = 0;
Ligne[idx]._lineData = (int16 *)g_PTRNUL;
}
}

// Remove Line
void LinesManager::RETIRE_LIGNE(int idx) {
if (idx > 400)
void LinesManager::removeLine(int idx) {
if (idx > MAX_LINES)
error("Attempting to add a line obstacle > MAX_LIGNE.");
Ligne[idx]._lineData = (int16 *)_vm->_globals.freeMemory((byte *)Ligne[idx]._lineData);
}
Expand Down Expand Up @@ -219,7 +219,7 @@ void LinesManager::AJOUTE_LIGNE(int idx, int a2, int a3, int a4, int a5, int a6,
int v39;
int v40;

if (idx > 400)
if (idx > MAX_LINES)
error("Attempting to add a line obstacle > MAX_LIGNE.");

if (_linesNumb < idx)
Expand Down Expand Up @@ -419,7 +419,7 @@ void LinesManager::initRoute() {
_vm->_graphicsManager.min_x == curLineX || _vm->_graphicsManager.min_y == curLineY ||
(lineX == curLineX && lineY == curLineY))
break;
if (lineIdx == 400)
if (lineIdx == MAX_LINES)
error("ERROR - LAST LINE NOT FOUND");

int16 *nextLineData = Ligne[lineIdx + 1]._lineData;
Expand All @@ -429,7 +429,7 @@ void LinesManager::initRoute() {
}

_vm->_objectsManager._lastLine = lineIdx;
for (int idx = 1; idx < 400; idx++) {
for (int idx = 1; idx < MAX_LINES; idx++) {
if ((Ligne[idx]._lineDataEndIdx < _vm->_globals._maxLineLength) && (idx != _vm->_objectsManager._lastLine + 1)) {
Ligne[idx].field6 = Ligne[idx - 1].field6;
Ligne[idx].field8 = Ligne[idx - 1].field8;
Expand Down
4 changes: 2 additions & 2 deletions engines/hopkins/lines.h
Expand Up @@ -75,8 +75,8 @@ class LinesManager {
int OPTI_ZONE(int posX, int minZoneNum, bool lastRow);
void removeZoneLine(int idx);
void addZoneLine(int idx, int a2, int a3, int a4, int a5, int bobZoneIdx);
void RESET_OBSTACLE();
void RETIRE_LIGNE(int idx);
void resetLines();
void removeLine(int idx);
void AJOUTE_LIGNE(int idx, int a2, int a3, int a4, int a5, int a6, int a7);
bool checkCollisionLine(int xp, int yp, int *foundDataIdx, int *foundLineIdx, int startLineIdx, int endLineIdx);
void initRoute();
Expand Down
8 changes: 4 additions & 4 deletions engines/hopkins/objects.cpp
Expand Up @@ -2049,7 +2049,7 @@ void ObjectsManager::GOHOME2() {

// Load Obstacle
void ObjectsManager::CHARGE_OBSTACLE(const Common::String &file) {
_vm->_linesManager.RESET_OBSTACLE();
_vm->_linesManager.resetLines();
_vm->_linesManager._linesNumb = 0;
_lastLine = 0;
byte *ptr = _vm->_fileManager.loadFile(file);
Expand Down Expand Up @@ -2177,7 +2177,7 @@ void ObjectsManager::CARRE_ZONE() {
_vm->_globals.CarreZone[idx].fieldC = 0;
}

for (int idx = 0; idx < 400; ++idx) {
for (int idx = 0; idx < MAX_LINES; ++idx) {
dataP = _vm->_linesManager._zoneLine[idx].zoneData;
if (dataP != (int16 *)g_PTRNUL) {
v4 = _vm->_linesManager._zoneLine[idx].field2;
Expand Down Expand Up @@ -2620,7 +2620,7 @@ void ObjectsManager::CLEAR_ECRAN() {
_vm->_globals.CLEAR_VBOB();
_vm->_animationManager.clearAnim();
_vm->_linesManager.CLEAR_ZONE();
_vm->_linesManager.RESET_OBSTACLE();
_vm->_linesManager.resetLines();
_vm->_globals.resetCache();

for (int v1 = 0; v1 <= 48; v1++) {
Expand Down Expand Up @@ -4131,7 +4131,7 @@ void ObjectsManager::INILINK(const Common::String &file) {
}
}

_vm->_linesManager.RESET_OBSTACLE();
_vm->_linesManager.resetLines();
for (size_t idx = 0; idx < nbytes; idx++) {
if (ptr[idx] == 'O' && ptr[idx + 1] == 'B' && ptr[idx + 2] == '2') {
v16 = ptr + idx + 4;
Expand Down
4 changes: 2 additions & 2 deletions engines/hopkins/talk.cpp
Expand Up @@ -1070,7 +1070,7 @@ void TalkManager::OBJET_VIVANT(const Common::String &a2) {
_vm->_eventsManager.VBL();
_vm->_graphicsManager.no_scroll = 1;
_vm->_linesManager.CLEAR_ZONE();
_vm->_linesManager.RESET_OBSTACLE();
_vm->_linesManager.resetLines();
_vm->_globals.resetCache();

for (int i = 0; i <= 44; i++)
Expand Down Expand Up @@ -1146,7 +1146,7 @@ void TalkManager::OBJET_VIVANT(const Common::String &a2) {
_characterSprite = _vm->_globals.freeMemory(_characterSprite);
_vm->_graphicsManager.NB_SCREEN(false);
_vm->_linesManager.CLEAR_ZONE();
_vm->_linesManager.RESET_OBSTACLE();
_vm->_linesManager.resetLines();
_vm->_globals.resetCache();
for (int i = 0; i <= 44; i++)
_vm->_globals.BOBZONE[i] = 0;
Expand Down

0 comments on commit 9f153a3

Please sign in to comment.