diff options
author | Simei Yin | 2018-04-15 21:10:02 +0200 |
---|---|---|
committer | Simei Yin | 2018-04-15 22:10:41 +0200 |
commit | 7c74e81e0ac7f9482c3732cb9305929d9e83a0c4 (patch) | |
tree | dca2e59cd323a64cfb70a5a996b3da0ba223bd20 | |
parent | 756a1096d8f07bf8dec93be126f8b702a884daa3 (diff) | |
download | scummvm-rg350-7c74e81e0ac7f9482c3732cb9305929d9e83a0c4.tar.gz scummvm-rg350-7c74e81e0ac7f9482c3732cb9305929d9e83a0c4.tar.bz2 scummvm-rg350-7c74e81e0ac7f9482c3732cb9305929d9e83a0c4.zip |
SLUDGE: Objectify PeopleManager
-rw-r--r-- | engines/sludge/builtin.cpp | 73 | ||||
-rw-r--r-- | engines/sludge/cursors.cpp | 14 | ||||
-rw-r--r-- | engines/sludge/freeze.cpp | 11 | ||||
-rw-r--r-- | engines/sludge/loadsave.cpp | 13 | ||||
-rw-r--r-- | engines/sludge/main_loop.cpp | 2 | ||||
-rw-r--r-- | engines/sludge/people.cpp | 214 | ||||
-rw-r--r-- | engines/sludge/people.h | 152 | ||||
-rw-r--r-- | engines/sludge/sludge.cpp | 4 | ||||
-rw-r--r-- | engines/sludge/sludge.h | 2 | ||||
-rw-r--r-- | engines/sludge/sludger.cpp | 6 | ||||
-rw-r--r-- | engines/sludge/speech.cpp | 8 | ||||
-rw-r--r-- | engines/sludge/variable.cpp | 10 |
12 files changed, 273 insertions, 236 deletions
diff --git a/engines/sludge/builtin.cpp b/engines/sludge/builtin.cpp index 8cba903d5c..e8e9b87f17 100644 --- a/engines/sludge/builtin.cpp +++ b/engines/sludge/builtin.cpp @@ -62,7 +62,6 @@ extern int lastFramesPerSecond, thumbWidth, thumbHeight; extern bool allowAnyFilename; extern VariableStack *noStack; extern StatusStuff *nowStatus; -extern ScreenRegion *overRegion; extern int numBIFNames, numUserFunc; extern Common::String *allUserFunc; @@ -856,7 +855,7 @@ builtIn(anim) { } // First store the frame numbers and take 'em off the stack - PersonaAnimation *ba = createPersonaAnim(numParams - 1, fun->stack); + PersonaAnimation *ba = g_sludge->_peopleMan->createPersonaAnim(numParams - 1, fun->stack); // Only remaining paramter is the file number int fileNumber; @@ -868,7 +867,7 @@ builtIn(anim) { LoadedSpriteBank *sprBanky = g_sludge->_gfxMan->loadBankForAnim(fileNumber); if (!sprBanky) return BR_ERROR; // File not found, fatal done already - setBankFile(ba, sprBanky); + g_sludge->_peopleMan->setBankFile(ba, sprBanky); // Return value newAnimationVariable(fun->reg, ba); @@ -1341,7 +1340,7 @@ builtIn(getObjectX) { return BR_ERROR; trimStack(fun->stack); - OnScreenPerson *pers = findPerson(objectNumber); + OnScreenPerson *pers = g_sludge->_peopleMan->findPerson(objectNumber); if (pers) { setVariable(fun->reg, SVT_INT, pers->x); } else { @@ -1362,7 +1361,7 @@ builtIn(getObjectY) { return BR_ERROR; trimStack(fun->stack); - OnScreenPerson *pers = findPerson(objectNumber); + OnScreenPerson *pers = g_sludge->_peopleMan->findPerson(objectNumber); if (pers) { setVariable(fun->reg, SVT_INT, pers->y); } else { @@ -1450,7 +1449,7 @@ builtIn(addCharacter) { if (!getValueType(objectNumber, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR; trimStack(fun->stack); - if (addPerson(x, y, objectNumber, p)) + if (g_sludge->_peopleMan->addPerson(x, y, objectNumber, p)) return BR_CONTINUE; return BR_ERROR; } @@ -1461,7 +1460,7 @@ builtIn(hideCharacter) { if (!getValueType(objectNumber, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR; trimStack(fun->stack); - setShown(false, objectNumber); + g_sludge->_peopleMan->setShown(false, objectNumber); return BR_CONTINUE; } @@ -1471,14 +1470,14 @@ builtIn(showCharacter) { if (!getValueType(objectNumber, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR; trimStack(fun->stack); - setShown(true, objectNumber); + g_sludge->_peopleMan->setShown(true, objectNumber); return BR_CONTINUE; } builtIn(removeAllCharacters) { UNUSEDALL killSpeechTimers(); - killMostPeople(); + g_sludge->_peopleMan->killMostPeople(); return BR_CONTINUE; } @@ -1491,7 +1490,7 @@ builtIn(setCharacterDrawMode) { if (!getValueType(obj, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR; trimStack(fun->stack); - setDrawMode(di, obj); + g_sludge->_peopleMan->setDrawMode(di, obj); return BR_CONTINUE; } builtIn(setCharacterTransparency) { @@ -1503,7 +1502,7 @@ builtIn(setCharacterTransparency) { if (!getValueType(obj, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR; trimStack(fun->stack); - setPersonTransparency(obj, x); + g_sludge->_peopleMan->setPersonTransparency(obj, x); return BR_CONTINUE; } builtIn(setCharacterColourise) { @@ -1524,7 +1523,7 @@ builtIn(setCharacterColourise) { if (!getValueType(obj, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR; trimStack(fun->stack); - setPersonColourise(obj, r, g, b, mix); + g_sludge->_peopleMan->setPersonColourise(obj, r, g, b, mix); return BR_CONTINUE; } @@ -1537,7 +1536,7 @@ builtIn(setScale) { if (!getValueType(val1, SVT_INT, fun->stack->thisVar)) return BR_ERROR; trimStack(fun->stack); - setScale((int16)val1, (int16)val2); + g_sludge->_peopleMan->setScale((int16)val1, (int16)val2); return BR_CONTINUE; } @@ -1549,7 +1548,7 @@ builtIn(stopCharacter) { trimStack(fun->stack); // Return value - setVariable(fun->reg, SVT_INT, stopPerson(obj)); + setVariable(fun->reg, SVT_INT, g_sludge->_peopleMan->stopPerson(obj)); return BR_CONTINUE; } @@ -1560,7 +1559,7 @@ builtIn(pasteCharacter) { return BR_ERROR; trimStack(fun->stack); - OnScreenPerson *thisPerson = findPerson(obj); + OnScreenPerson *thisPerson = g_sludge->_peopleMan->findPerson(obj); if (thisPerson) { PersonaAnimation *myAnim; myAnim = thisPerson->myAnim; @@ -1589,8 +1588,8 @@ builtIn(animate) { if (!getValueType(obj, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR; trimStack(fun->stack); - animatePerson(obj, pp); - setVariable(fun->reg, SVT_INT, timeForAnim(pp)); + g_sludge->_peopleMan->animatePerson(obj, pp); + setVariable(fun->reg, SVT_INT, g_sludge->_peopleMan->timeForAnim(pp)); return BR_CONTINUE; } @@ -1604,7 +1603,7 @@ builtIn(setCostume) { if (!getValueType(obj, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR; trimStack(fun->stack); - animatePerson(obj, pp); + g_sludge->_peopleMan->animatePerson(obj, pp); return BR_CONTINUE; } @@ -1617,7 +1616,7 @@ builtIn(floatCharacter) { if (!getValueType(obj, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR; trimStack(fun->stack); - setVariable(fun->reg, SVT_INT, floatCharacter(di, obj)); + setVariable(fun->reg, SVT_INT, g_sludge->_peopleMan->floatCharacter(di, obj)); return BR_CONTINUE; } @@ -1630,7 +1629,7 @@ builtIn(setCharacterWalkSpeed) { if (!getValueType(obj, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR; trimStack(fun->stack); - setVariable(fun->reg, SVT_INT, setCharacterWalkSpeed(di, obj)); + setVariable(fun->reg, SVT_INT, g_sludge->_peopleMan->setCharacterWalkSpeed(di, obj)); return BR_CONTINUE; } @@ -1643,7 +1642,7 @@ builtIn(turnCharacter) { if (!getValueType(obj, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR; trimStack(fun->stack); - setVariable(fun->reg, SVT_INT, turnPersonToFace(obj, di)); + setVariable(fun->reg, SVT_INT, g_sludge->_peopleMan->turnPersonToFace(obj, di)); return BR_CONTINUE; } @@ -1656,7 +1655,7 @@ builtIn(setCharacterExtra) { if (!getValueType(obj, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR; trimStack(fun->stack); - setVariable(fun->reg, SVT_INT, setPersonExtra(obj, di)); + setVariable(fun->reg, SVT_INT, g_sludge->_peopleMan->setPersonExtra(obj, di)); return BR_CONTINUE; } @@ -1666,7 +1665,7 @@ builtIn(removeCharacter) { if (!getValueType(objectNumber, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR; trimStack(fun->stack); - removeOneCharacter(objectNumber); + g_sludge->_peopleMan->removeOneCharacter(objectNumber); return BR_CONTINUE; } @@ -1686,12 +1685,12 @@ static BuiltReturn moveChr(int numParams, LoadedFunction *fun, bool force, bool trimStack(fun->stack); if (force) { - if (forceWalkingPerson(x, y, objectNumber, fun, -1)) + if (g_sludge->_peopleMan->forceWalkingPerson(x, y, objectNumber, fun, -1)) return BR_PAUSE; } else if (immediate) { - jumpPerson(x, y, objectNumber); + g_sludge->_peopleMan->jumpPerson(x, y, objectNumber); } else { - if (makeWalkingPerson(x, y, objectNumber, fun, -1)) + if (g_sludge->_peopleMan->makeWalkingPerson(x, y, objectNumber, fun, -1)) return BR_PAUSE; } return BR_CONTINUE; @@ -1712,12 +1711,12 @@ static BuiltReturn moveChr(int numParams, LoadedFunction *fun, bool force, bool return BR_CONTINUE; if (force) { - if (forceWalkingPerson(reggie->sX, reggie->sY, objectNumber, fun, reggie->di)) + if (g_sludge->_peopleMan->forceWalkingPerson(reggie->sX, reggie->sY, objectNumber, fun, reggie->di)) return BR_PAUSE; } else if (immediate) { - jumpPerson(reggie->sX, reggie->sY, objectNumber); + g_sludge->_peopleMan->jumpPerson(reggie->sX, reggie->sY, objectNumber); } else { - if (makeWalkingPerson(reggie->sX, reggie->sY, objectNumber, fun, reggie->di)) + if (g_sludge->_peopleMan->makeWalkingPerson(reggie->sX, reggie->sY, objectNumber, fun, reggie->di)) return BR_PAUSE; } return BR_CONTINUE; @@ -2007,7 +2006,7 @@ builtIn(spinCharacter) { return BR_ERROR; trimStack(fun->stack); - OnScreenPerson *thisPerson = findPerson(objectNumber); + OnScreenPerson *thisPerson = g_sludge->_peopleMan->findPerson(objectNumber); if (thisPerson) { thisPerson->wantAngle = number; thisPerson->spinning = true; @@ -2026,7 +2025,7 @@ builtIn(getCharacterDirection) { if (!getValueType(objectNumber, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR; trimStack(fun->stack); - OnScreenPerson *thisPerson = findPerson(objectNumber); + OnScreenPerson *thisPerson = g_sludge->_peopleMan->findPerson(objectNumber); if (thisPerson) { setVariable(fun->reg, SVT_INT, thisPerson->direction); } else { @@ -2041,7 +2040,7 @@ builtIn(isCharacter) { if (!getValueType(objectNumber, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR; trimStack(fun->stack); - OnScreenPerson *thisPerson = findPerson(objectNumber); + OnScreenPerson *thisPerson = g_sludge->_peopleMan->findPerson(objectNumber); setVariable(fun->reg, SVT_INT, thisPerson != NULL); return BR_CONTINUE; } @@ -2052,7 +2051,7 @@ builtIn(normalCharacter) { if (!getValueType(objectNumber, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR; trimStack(fun->stack); - OnScreenPerson *thisPerson = findPerson(objectNumber); + OnScreenPerson *thisPerson = g_sludge->_peopleMan->findPerson(objectNumber); if (thisPerson) { thisPerson->myAnim = thisPerson->myPersona->animation[thisPerson->direction]; setVariable(fun->reg, SVT_INT, 1); @@ -2068,7 +2067,7 @@ builtIn(isMoving) { if (!getValueType(objectNumber, SVT_OBJTYPE, fun->stack->thisVar)) return BR_ERROR; trimStack(fun->stack); - OnScreenPerson *thisPerson = findPerson(objectNumber); + OnScreenPerson *thisPerson = g_sludge->_peopleMan->findPerson(objectNumber); if (thisPerson) { setVariable(fun->reg, SVT_INT, thisPerson->walking); } else { @@ -2173,7 +2172,7 @@ builtIn(setCharacterSpinSpeed) { return BR_ERROR; trimStack(fun->stack); - OnScreenPerson *thisPerson = findPerson(who); + OnScreenPerson *thisPerson = g_sludge->_peopleMan->findPerson(who); if (thisPerson) { thisPerson->spinSpeed = speed; @@ -2194,7 +2193,7 @@ builtIn(setCharacterAngleOffset) { return BR_ERROR; trimStack(fun->stack); - OnScreenPerson *thisPerson = findPerson(who); + OnScreenPerson *thisPerson = g_sludge->_peopleMan->findPerson(who); if (thisPerson) { thisPerson->angleOffset = angle; @@ -2390,7 +2389,7 @@ builtIn(getCharacterScale) { return BR_ERROR; trimStack(fun->stack); - OnScreenPerson *pers = findPerson(objectNumber); + OnScreenPerson *pers = g_sludge->_peopleMan->findPerson(objectNumber); if (pers) { setVariable(fun->reg, SVT_INT, pers->scale * 100); } else { diff --git a/engines/sludge/cursors.cpp b/engines/sludge/cursors.cpp index 0c7745e9ff..849a627c73 100644 --- a/engines/sludge/cursors.cpp +++ b/engines/sludge/cursors.cpp @@ -44,18 +44,18 @@ CursorManager::~CursorManager() { } void CursorManager::init() { - _mouseCursorAnim = makeNullAnim(); + _mouseCursorAnim = _vm->_peopleMan->makeNullAnim(); _mouseCursorFrameNum = 0; _mouseCursorCountUp = 0; } void CursorManager::kill() { - deleteAnim(_mouseCursorAnim); + _vm->_peopleMan->deleteAnim(_mouseCursorAnim); _mouseCursorAnim = nullptr; } void CursorManager::pickAnimCursor(PersonaAnimation *pp) { - deleteAnim(_mouseCursorAnim); + _vm->_peopleMan->deleteAnim(_mouseCursorAnim); _mouseCursorAnim = pp; _mouseCursorFrameNum = 0; _mouseCursorCountUp = 0; @@ -107,18 +107,18 @@ void CursorManager::pasteCursor(int x, int y, PersonaAnimation *c) { void CursorManager::freeze(FrozenStuffStruct *frozenStuff) { frozenStuff->mouseCursorAnim = _mouseCursorAnim; frozenStuff->mouseCursorFrameNum = _mouseCursorFrameNum; - _mouseCursorAnim = makeNullAnim(); + _mouseCursorAnim = _vm->_peopleMan->makeNullAnim(); _mouseCursorFrameNum = 0; } void CursorManager::resotre(FrozenStuffStruct *frozenStuff) { - deleteAnim(_mouseCursorAnim); + _vm->_peopleMan->deleteAnim(_mouseCursorAnim); _mouseCursorAnim = frozenStuff->mouseCursorAnim; _mouseCursorFrameNum = frozenStuff->mouseCursorFrameNum; } void CursorManager::saveCursor(Common::WriteStream *stream) { - saveAnim(_mouseCursorAnim, stream); + _vm->_peopleMan->saveAnim(_mouseCursorAnim, stream); stream->writeUint16BE(_mouseCursorFrameNum); } @@ -126,7 +126,7 @@ bool CursorManager::loadCursor(Common::SeekableReadStream *stream) { _mouseCursorAnim = new PersonaAnimation; if (!checkNew(_mouseCursorAnim)) return false; - if (!loadAnim(_mouseCursorAnim, stream)) + if (!_vm->_peopleMan->loadAnim(_mouseCursorAnim, stream)) return false; _mouseCursorFrameNum = stream->readUint16BE(); return true; diff --git a/engines/sludge/freeze.cpp b/engines/sludge/freeze.cpp index 0f032731c7..cbafa40bdc 100644 --- a/engines/sludge/freeze.cpp +++ b/engines/sludge/freeze.cpp @@ -41,10 +41,6 @@ namespace Sludge { -extern OnScreenPerson *allPeople; -extern ScreenRegion *allScreenRegions; -extern ScreenRegion *overRegion; - void GraphicsManager::freezeGraphics() { int w = _winWidth; @@ -87,8 +83,7 @@ bool GraphicsManager::freeze() { _backdropSurface.copyFrom(_freezeSurface); _backdropExists = true; - newFreezer->allPeople = allPeople; - allPeople = NULL; + _vm->_peopleMan->freeze(newFreezer); StatusStuff *newStatusStuff = new StatusStuff ; if (!checkNew(newStatusStuff)) @@ -133,9 +128,7 @@ void GraphicsManager::unfreeze(bool killImage) { _vm->_evtMan->mouseX() = (int)(_vm->_evtMan->mouseX() / _cameraZoom); _vm->_evtMan->mouseY() = (int)(_vm->_evtMan->mouseY() / _cameraZoom); - killAllPeople(); - allPeople = _frozenStuff->allPeople; - + g_sludge->_peopleMan->resotre(_frozenStuff); g_sludge->_regionMan->resotre(_frozenStuff); killLightMap(); diff --git a/engines/sludge/loadsave.cpp b/engines/sludge/loadsave.cpp index 01ee1474b1..bfedcfce4c 100644 --- a/engines/sludge/loadsave.cpp +++ b/engines/sludge/loadsave.cpp @@ -214,11 +214,11 @@ bool saveVariable(Variable *from, Common::WriteStream *stream) { return saveStackRef(from->varData.theStack, stream); case SVT_COSTUME: - saveCostume(from->varData.costumeHandler, stream); + g_sludge->_peopleMan->saveCostume(from->varData.costumeHandler, stream); return false; case SVT_ANIM: - saveAnim(from->varData.animHandler, stream); + g_sludge->_peopleMan->saveAnim(from->varData.animHandler, stream); return false; case SVT_NULL: @@ -253,14 +253,14 @@ bool loadVariable(Variable *to, Common::SeekableReadStream *stream) { to->varData.costumeHandler = new Persona; if (!checkNew(to->varData.costumeHandler)) return false; - loadCostume(to->varData.costumeHandler, stream); + g_sludge->_peopleMan->loadCostume(to->varData.costumeHandler, stream); return true; case SVT_ANIM: to->varData.animHandler = new PersonaAnimation ; if (!checkNew(to->varData.animHandler)) return false; - loadAnim(to->varData.animHandler, stream); + g_sludge->_peopleMan->loadAnim(to->varData.animHandler, stream); return true; default: @@ -397,7 +397,7 @@ bool saveGame(const Common::String &fname) { saveVariable(&globalVars[a], fp); } - savePeople(fp); + g_sludge->_peopleMan->savePeople(fp); if (currentFloor->numPolygons) { fp->writeByte(1); @@ -502,7 +502,6 @@ bool loadGame(const Common::String &fname) { g_sludge->_txtMan->loadFont(ssgVersion, fp); - killAllPeople(); g_sludge->_regionMan->kill(); int camerX = fp->readUint16BE(); @@ -540,7 +539,7 @@ bool loadGame(const Common::String &fname) { loadVariable(&globalVars[a], fp); } - loadPeople(fp); + g_sludge->_peopleMan->loadPeople(fp); if (fp->readByte()) { if (!setFloor(fp->readUint16BE())) diff --git a/engines/sludge/main_loop.cpp b/engines/sludge/main_loop.cpp index 905d91d9c2..eac8610cc7 100644 --- a/engines/sludge/main_loop.cpp +++ b/engines/sludge/main_loop.cpp @@ -63,7 +63,7 @@ int main_loop(Common::String filename) { while (!g_sludge->_evtMan->quit()) { g_sludge->_evtMan->checkInput(); - walkAllPeople(); + g_sludge->_peopleMan->walkAllPeople(); if (g_sludge->_evtMan->handleInput()) { runSludge(); } diff --git a/engines/sludge/people.cpp b/engines/sludge/people.cpp index d0694795c3..a43f0f1a86 100644 --- a/engines/sludge/people.cpp +++ b/engines/sludge/people.cpp @@ -47,22 +47,30 @@ namespace Sludge { extern VariableStack *noStack; - extern int ssgVersion; - -ScreenRegion personRegion; extern Floor *currentFloor; -OnScreenPerson *allPeople = NULL; -int16 scaleHorizon = 75; -int16 scaleDivide = 150; +PeopleManager::PeopleManager(SludgeEngine *vm) { + _vm = vm; + _allPeople = nullptr; + _scaleHorizon = 75; + _scaleDivide = 150; + _personRegion = new ScreenRegion; +} + +PeopleManager::~PeopleManager() { + kill(); -void setFrames(OnScreenPerson &m, int a) { + delete _personRegion; + _personRegion = nullptr; +} + +void PeopleManager::setFrames(OnScreenPerson &m, int a) { m.myAnim = m.myPersona->animation[(a * m.myPersona->numDirections) + m.direction]; } -PersonaAnimation *createPersonaAnim(int num, VariableStack *&stacky) { - PersonaAnimation *newP = new PersonaAnimation ; +PersonaAnimation *PeopleManager::createPersonaAnim(int num, VariableStack *&stacky) { + PersonaAnimation *newP = new PersonaAnimation ; checkNew(newP); newP->numFrames = num; @@ -93,8 +101,8 @@ PersonaAnimation *createPersonaAnim(int num, VariableStack *&stacky) { return newP; } -PersonaAnimation *makeNullAnim() { - PersonaAnimation *newAnim = new PersonaAnimation ; +PersonaAnimation *PeopleManager::makeNullAnim() { + PersonaAnimation *newAnim = new PersonaAnimation ; if (!checkNew(newAnim)) return NULL; @@ -104,10 +112,10 @@ PersonaAnimation *makeNullAnim() { return newAnim; } -PersonaAnimation *copyAnim(PersonaAnimation *orig) { +PersonaAnimation *PeopleManager::copyAnim(PersonaAnimation *orig) { int num = orig->numFrames; - PersonaAnimation *newAnim = new PersonaAnimation ; + PersonaAnimation *newAnim = new PersonaAnimation ; if (!checkNew(newAnim)) return NULL; @@ -135,7 +143,7 @@ PersonaAnimation *copyAnim(PersonaAnimation *orig) { return newAnim; } -void deleteAnim(PersonaAnimation *orig) { +void PeopleManager::deleteAnim(PersonaAnimation *orig) { if (orig) { if (orig->numFrames) { @@ -146,7 +154,7 @@ void deleteAnim(PersonaAnimation *orig) { } } -void turnMeAngle(OnScreenPerson *thisPerson, int direc) { +void PeopleManager::turnMeAngle(OnScreenPerson *thisPerson, int direc) { int d = thisPerson->myPersona->numDirections; thisPerson->angle = direc; direc += (180 / d) + 180 + thisPerson->angleOffset; @@ -155,14 +163,14 @@ void turnMeAngle(OnScreenPerson *thisPerson, int direc) { thisPerson->direction = (direc * d) / 360; } -bool initPeople() { - personRegion.sX = 0; - personRegion.sY = 0; - personRegion.di = -1; +bool PeopleManager::init() { + _personRegion->sX = 0; + _personRegion->sY = 0; + _personRegion->di = -1; return true; } -void spinStep(OnScreenPerson *thisPerson) { +void PeopleManager::spinStep(OnScreenPerson *thisPerson) { int diff = (thisPerson->angle + 360) - thisPerson->wantAngle; int eachSlice = thisPerson->spinSpeed ? thisPerson->spinSpeed : (360 / thisPerson->myPersona->numDirections); while (diff > 180) { @@ -179,7 +187,7 @@ void spinStep(OnScreenPerson *thisPerson) { } } -void rethinkAngle(OnScreenPerson *thisPerson) { +void PeopleManager::rethinkAngle(OnScreenPerson *thisPerson) { int d = thisPerson->myPersona->numDirections; int direc = thisPerson->angle + (180 / d) + 180 + thisPerson->angleOffset; while (direc >= 360) @@ -187,7 +195,7 @@ void rethinkAngle(OnScreenPerson *thisPerson) { thisPerson->direction = (direc * d) / 360; } -bool turnPersonToFace(int thisNum, int direc) { +bool PeopleManager::turnPersonToFace(int thisNum, int direc) { OnScreenPerson *thisPerson = findPerson(thisNum); if (thisPerson) { if (thisPerson->continueAfterWalking) @@ -202,7 +210,7 @@ bool turnPersonToFace(int thisNum, int direc) { return false; } -bool setPersonExtra(int thisNum, int extra) { +bool PeopleManager::setPersonExtra(int thisNum, int extra) { OnScreenPerson *thisPerson = findPerson(thisNum); if (thisPerson) { thisPerson->extra = extra; @@ -213,20 +221,20 @@ bool setPersonExtra(int thisNum, int extra) { return false; } -void setScale(int16 h, int16 d) { - scaleHorizon = h; - scaleDivide = d; +void PeopleManager::setScale(int16 h, int16 d) { + _scaleHorizon = h; + _scaleDivide = d; } -void moveAndScale(OnScreenPerson &me, float x, float y) { +void PeopleManager::moveAndScale(OnScreenPerson &me, float x, float y) { me.x = x; me.y = y; - if (!(me.extra & EXTRA_NOSCALE) && scaleDivide) - me.scale = (me.y - scaleHorizon) / scaleDivide; + if (!(me.extra & EXTRA_NOSCALE) && _scaleDivide) + me.scale = (me.y - _scaleHorizon) / _scaleDivide; } -OnScreenPerson *findPerson(int v) { - OnScreenPerson *thisPerson = allPeople; +OnScreenPerson *PeopleManager::findPerson(int v) { + OnScreenPerson *thisPerson = _allPeople; while (thisPerson) { if (v == thisPerson->thisType->objectNum) break; @@ -235,13 +243,13 @@ OnScreenPerson *findPerson(int v) { return thisPerson; } -void movePerson(int x, int y, int objNum) { +void PeopleManager::movePerson(int x, int y, int objNum) { OnScreenPerson *moveMe = findPerson(objNum); if (moveMe) moveAndScale(*moveMe, x, y); } -void setShown(bool h, int ob) { +void PeopleManager::setShown(bool h, int ob) { OnScreenPerson *moveMe = findPerson(ob); if (moveMe) moveMe->show = h; @@ -271,7 +279,7 @@ enum drawModes { numDrawModes }; -void setMyDrawMode(OnScreenPerson *moveMe, int h) { +void PeopleManager::setMyDrawMode(OnScreenPerson *moveMe, int h) { switch (h) { case drawModeTransparent3: moveMe->r = moveMe->g = moveMe->b = 0; @@ -377,7 +385,7 @@ void setMyDrawMode(OnScreenPerson *moveMe, int h) { } -void setDrawMode(int h, int ob) { +void PeopleManager::setDrawMode(int h, int ob) { OnScreenPerson *moveMe = findPerson(ob); if (!moveMe) return; @@ -385,7 +393,7 @@ void setDrawMode(int h, int ob) { setMyDrawMode(moveMe, h); } -void setPersonTransparency(int ob, byte x) { +void PeopleManager::setPersonTransparency(int ob, byte x) { OnScreenPerson *moveMe = findPerson(ob); if (!moveMe) return; @@ -395,7 +403,7 @@ void setPersonTransparency(int ob, byte x) { moveMe->transparency = x; } -void setPersonColourise(int ob, byte r, byte g, byte b, byte colourmix) { +void PeopleManager::setPersonColourise(int ob, byte r, byte g, byte b, byte colourmix) { OnScreenPerson *moveMe = findPerson(ob); if (!moveMe) return; @@ -406,11 +414,11 @@ void setPersonColourise(int ob, byte r, byte g, byte b, byte colourmix) { moveMe->colourmix = colourmix; } -void shufflePeople() { - OnScreenPerson **thisReference = &allPeople; +void PeopleManager::shufflePeople() { + OnScreenPerson **thisReference = &_allPeople; OnScreenPerson *A, *B; - if (!allPeople) + if (!_allPeople) return; while ((*thisReference)->next) { @@ -434,11 +442,11 @@ void shufflePeople() { } } -void drawPeople() { +void PeopleManager::drawPeople() { shufflePeople(); - OnScreenPerson *thisPerson = allPeople; - PersonaAnimation *myAnim = NULL; + OnScreenPerson *thisPerson = _allPeople; + PersonaAnimation *myAnim = NULL; g_sludge->_regionMan->resetOverRegion(); while (thisPerson) { @@ -473,10 +481,10 @@ void drawPeople() { r = g_sludge->_gfxMan->scaleSprite(myAnim->theSprites->bank.sprites[fNum], myAnim->theSprites->bank.myPalette, thisPerson, m); if (r) { if (!thisPerson->thisType->screenName.empty()) { - if (personRegion.thisType != thisPerson->thisType) + if (_personRegion->thisType != thisPerson->thisType) g_sludge->_regionMan->resetLastRegion(); - personRegion.thisType = thisPerson->thisType; - g_sludge->_regionMan->setOverRegion(&personRegion); + _personRegion->thisType = thisPerson->thisType; + g_sludge->_regionMan->setOverRegion(_personRegion); } } } @@ -504,38 +512,30 @@ void drawPeople() { } } -void makeTalker(OnScreenPerson &me) { +void PeopleManager::makeTalker(OnScreenPerson &me) { setFrames(me, ANI_TALK); } -void makeSilent(OnScreenPerson &me) { +void PeopleManager::makeSilent(OnScreenPerson &me) { setFrames(me, ANI_STAND); } -bool handleClosestPoint(int &setX, int &setY, int &setPoly) { +bool PeopleManager::handleClosestPoint(int &setX, int &setY, int &setPoly) { int gotX = 320, gotY = 200, gotPoly = -1, i, j, xTest1, yTest1, xTest2, yTest2, closestX, closestY, oldJ, currentDistance = 0xFFFFF, thisDistance; -// FILE * dbug = fopen ("debug_closest.txt", "at"); -// fprintf (dbug, "\nGetting closest point to %i, %i\n", setX, setY); - for (i = 0; i < currentFloor->numPolygons; i++) { oldJ = currentFloor->polygon[i].numVertices - 1; for (j = 0; j < currentFloor->polygon[i].numVertices; j++) { -// fprintf (dbug, "Polygon %i, line %i... ", i, j); xTest1 = currentFloor->vertex[currentFloor->polygon[i].vertexID[j]].x; yTest1 = currentFloor->vertex[currentFloor->polygon[i].vertexID[j]].y; xTest2 = currentFloor->vertex[currentFloor->polygon[i].vertexID[oldJ]].x; yTest2 = currentFloor->vertex[currentFloor->polygon[i].vertexID[oldJ]].y; closestPointOnLine(closestX, closestY, xTest1, yTest1, xTest2, yTest2, setX, setY); -// fprintf (dbug, "closest point is %i, %i... ", closestX, closestY); xTest1 = setX - closestX; yTest1 = setY - closestY; thisDistance = xTest1 * xTest1 + yTest1 * yTest1; -// fprintf (dbug, "Distance squared %i\n", thisDistance); if (thisDistance < currentDistance) { -// fprintf (dbug, "** We have a new winner!**\n"); - currentDistance = thisDistance; gotX = closestX; gotY = closestY; @@ -544,7 +544,6 @@ bool handleClosestPoint(int &setX, int &setY, int &setPoly) { oldJ = j; } } -// fclose (dbug); if (gotPoly == -1) return false; @@ -555,7 +554,7 @@ bool handleClosestPoint(int &setX, int &setY, int &setPoly) { return true; } -bool doBorderStuff(OnScreenPerson *moveMe) { +bool PeopleManager::doBorderStuff(OnScreenPerson *moveMe) { if (moveMe->inPoly == moveMe->walkToPoly) { moveMe->inPoly = -1; moveMe->thisStepX = moveMe->walkToX; @@ -625,7 +624,7 @@ bool doBorderStuff(OnScreenPerson *moveMe) { return true; } -bool walkMe(OnScreenPerson *thisPerson, bool move = true) { +bool PeopleManager::walkMe(OnScreenPerson *thisPerson, bool move) { float xDiff, yDiff, maxDiff, s; for (;;) { @@ -666,7 +665,7 @@ bool walkMe(OnScreenPerson *thisPerson, bool move = true) { return false; } -bool makeWalkingPerson(int x, int y, int objNum, LoadedFunction *func, int di) { +bool PeopleManager::makeWalkingPerson(int x, int y, int objNum, LoadedFunction *func, int di) { if (x == 0 && y == 0) return false; if (currentFloor->numPolygons == 0) @@ -705,7 +704,7 @@ bool makeWalkingPerson(int x, int y, int objNum, LoadedFunction *func, int di) { } } -bool stopPerson(int o) { +bool PeopleManager::stopPerson(int o) { OnScreenPerson *moveMe = findPerson(o); if (moveMe) if (moveMe->continueAfterWalking) { @@ -719,7 +718,7 @@ bool stopPerson(int o) { return false; } -bool forceWalkingPerson(int x, int y, int objNum, LoadedFunction *func, int di) { +bool PeopleManager::forceWalkingPerson(int x, int y, int objNum, LoadedFunction *func, int di) { if (x == 0 && y == 0) return false; OnScreenPerson *moveMe = findPerson(objNum); @@ -749,7 +748,7 @@ bool forceWalkingPerson(int x, int y, int objNum, LoadedFunction *func, int di) } } -void jumpPerson(int x, int y, int objNum) { +void PeopleManager::jumpPerson(int x, int y, int objNum) { if (x == 0 && y == 0) return; OnScreenPerson *moveMe = findPerson(objNum); @@ -763,7 +762,7 @@ void jumpPerson(int x, int y, int objNum) { moveAndScale(*moveMe, x, y); } -bool floatCharacter(int f, int objNum) { +bool PeopleManager::floatCharacter(int f, int objNum) { OnScreenPerson *moveMe = findPerson(objNum); if (!moveMe) return false; @@ -771,7 +770,7 @@ bool floatCharacter(int f, int objNum) { return true; } -bool setCharacterWalkSpeed(int f, int objNum) { +bool PeopleManager::setCharacterWalkSpeed(int f, int objNum) { if (f <= 0) return false; OnScreenPerson *moveMe = findPerson(objNum); @@ -781,8 +780,8 @@ bool setCharacterWalkSpeed(int f, int objNum) { return true; } -void walkAllPeople() { - OnScreenPerson *thisPerson = allPeople; +void PeopleManager::walkAllPeople() { + OnScreenPerson *thisPerson = _allPeople; while (thisPerson) { if (thisPerson->walking) { @@ -799,7 +798,7 @@ void walkAllPeople() { } } -bool addPerson(int x, int y, int objNum, Persona *p) { +bool PeopleManager::addPerson(int x, int y, int objNum, Persona *p) { OnScreenPerson *newPerson = new OnScreenPerson; if (!checkNew(newPerson)) return false; @@ -849,7 +848,7 @@ bool addPerson(int x, int y, int objNum, Persona *p) { } // NOW ADD IT IN THE RIGHT PLACE - OnScreenPerson **changethat = &allPeople; + OnScreenPerson **changethat = &_allPeople; while (((*changethat) != NULL) && ((*changethat)->y < y)) changethat = &((*changethat)->next); @@ -860,7 +859,7 @@ bool addPerson(int x, int y, int objNum, Persona *p) { return (bool)(newPerson->thisType != NULL); } -int timeForAnim(PersonaAnimation *fram) { +int PeopleManager::timeForAnim(PersonaAnimation *fram) { int total = 0; for (int a = 0; a < fram->numFrames; a++) { total += fram->frames[a].howMany; @@ -868,7 +867,7 @@ int timeForAnim(PersonaAnimation *fram) { return total; } -void animatePerson(int obj, PersonaAnimation *fram) { // Set a new SINGLE animation +void PeopleManager::animatePerson(int obj, PersonaAnimation *fram) { // Set a new SINGLE animation OnScreenPerson *moveMe = findPerson(obj); if (moveMe) { if (moveMe->continueAfterWalking) @@ -880,7 +879,7 @@ void animatePerson(int obj, PersonaAnimation *fram) { // Set a new SINGLE anima } } -void animatePerson(int obj, Persona *per) { // Set a new costume +void PeopleManager::animatePerson(int obj, Persona *per) { // Set a new costume OnScreenPerson *moveMe = findPerson(obj); if (moveMe) { // if (moveMe->continueAfterWalking) abortFunction (moveMe->continueAfterWalking); @@ -897,22 +896,22 @@ void animatePerson(int obj, Persona *per) { // Set a new costume } } -void killAllPeople() { +void PeopleManager::kill() { OnScreenPerson *killPeople; - while (allPeople) { - if (allPeople->continueAfterWalking) - abortFunction(allPeople->continueAfterWalking); - allPeople->continueAfterWalking = NULL; - killPeople = allPeople; - allPeople = allPeople->next; + while (_allPeople) { + if (_allPeople->continueAfterWalking) + abortFunction(_allPeople->continueAfterWalking); + _allPeople->continueAfterWalking = NULL; + killPeople = _allPeople; + _allPeople = _allPeople->next; g_sludge->_objMan->removeObjectType(killPeople->thisType); delete killPeople; } } -void killMostPeople() { +void PeopleManager::killMostPeople() { OnScreenPerson *killPeople; - OnScreenPerson **lookyHere = &allPeople; + OnScreenPerson **lookyHere = &_allPeople; while (*lookyHere) { if ((*lookyHere)->extra & EXTRA_NOREMOVE) { @@ -933,12 +932,12 @@ void killMostPeople() { } } -void removeOneCharacter(int i) { +void PeopleManager::removeOneCharacter(int i) { OnScreenPerson *p = findPerson(i); if (p) { ScreenRegion *overRegion = g_sludge->_regionMan->getOverRegion(); - if (overRegion == &personRegion && overRegion->thisType == p->thisType) { + if (overRegion == _personRegion && overRegion->thisType == p->thisType) { overRegion = nullptr; } @@ -947,7 +946,7 @@ void removeOneCharacter(int i) { p->continueAfterWalking = NULL; OnScreenPerson **killPeople; - for (killPeople = &allPeople; *killPeople != p; killPeople = &((*killPeople)->next)) { + for (killPeople = &_allPeople; *killPeople != p; killPeople = &((*killPeople)->next)) { ; } @@ -957,7 +956,7 @@ void removeOneCharacter(int i) { } } -bool saveAnim(PersonaAnimation *p, Common::WriteStream *stream) { +bool PeopleManager::saveAnim(PersonaAnimation *p, Common::WriteStream *stream) { stream->writeUint16BE(p->numFrames); if (p->numFrames) { stream->writeUint32LE(p->theSprites->ID); @@ -971,7 +970,7 @@ bool saveAnim(PersonaAnimation *p, Common::WriteStream *stream) { return true; } -bool loadAnim(PersonaAnimation *p, Common::SeekableReadStream *stream) { +bool PeopleManager::loadAnim(PersonaAnimation *p, Common::SeekableReadStream *stream) { p->numFrames = stream->readUint16BE(); if (p->numFrames) { @@ -997,21 +996,20 @@ bool loadAnim(PersonaAnimation *p, Common::SeekableReadStream *stream) { return true; } -bool saveCostume(Persona *cossy, Common::WriteStream *stream) { +bool PeopleManager::saveCostume(Persona *cossy, Common::WriteStream *stream) { int a; stream->writeUint16BE(cossy->numDirections); for (a = 0; a < cossy->numDirections * 3; a++) { if (!saveAnim(cossy->animation[a], stream)) return false; } -// debugCostume ("Saved", cossy); return true; } -bool loadCostume(Persona *cossy, Common::SeekableReadStream *stream) { +bool PeopleManager::loadCostume(Persona *cossy, Common::SeekableReadStream *stream) { int a; cossy->numDirections = stream->readUint16BE(); - cossy->animation = new PersonaAnimation *[cossy->numDirections * 3]; + cossy->animation = new PersonaAnimation *[cossy->numDirections * 3]; if (!checkNew(cossy->animation)) return false; for (a = 0; a < cossy->numDirections * 3; a++) { @@ -1022,16 +1020,15 @@ bool loadCostume(Persona *cossy, Common::SeekableReadStream *stream) { if (!loadAnim(cossy->animation[a], stream)) return false; } -// debugCostume ("Loaded", cossy); return true; } -bool savePeople(Common::WriteStream *stream) { - OnScreenPerson *me = allPeople; +bool PeopleManager::savePeople(Common::WriteStream *stream) { + OnScreenPerson *me = _allPeople; int countPeople = 0, a; - stream->writeSint16LE(scaleHorizon); - stream->writeSint16LE(scaleDivide); + stream->writeSint16LE(_scaleHorizon); + stream->writeSint16LE(_scaleDivide); while (me) { countPeople++; @@ -1040,7 +1037,7 @@ bool savePeople(Common::WriteStream *stream) { stream->writeUint16BE(countPeople); - me = allPeople; + me = _allPeople; for (a = 0; a < countPeople; a++) { stream->writeFloatLE(me->x); @@ -1093,17 +1090,19 @@ bool savePeople(Common::WriteStream *stream) { return true; } -bool loadPeople(Common::SeekableReadStream *stream) { - OnScreenPerson **pointy = &allPeople; +bool PeopleManager::loadPeople(Common::SeekableReadStream *stream) { + kill(); + + OnScreenPerson **pointy = &_allPeople; OnScreenPerson *me; - scaleHorizon = stream->readSint16LE(); - scaleDivide = stream->readSint16LE(); + _scaleHorizon = stream->readSint16LE(); + _scaleDivide = stream->readSint16LE(); int countPeople = stream->readUint16BE(); int a; - allPeople = NULL; + _allPeople = NULL; for (a = 0; a < countPeople; a++) { me = new OnScreenPerson; if (!checkNew(me)) @@ -1184,8 +1183,17 @@ bool loadPeople(Common::SeekableReadStream *stream) { *pointy = me; pointy = &(me->next); } -// db ("End of loadPeople"); return true; } +void PeopleManager::freeze(FrozenStuffStruct *frozenStuff) { + frozenStuff->allPeople = _allPeople; + _allPeople = nullptr; +} + +void PeopleManager::resotre(FrozenStuffStruct *frozenStuff) { + kill(); + _allPeople = frozenStuff->allPeople; +} + } // End of namespace Sludge diff --git a/engines/sludge/people.h b/engines/sludge/people.h index 95b8e923b6..3fe41941ec 100644 --- a/engines/sludge/people.h +++ b/engines/sludge/people.h @@ -26,6 +26,9 @@ namespace Sludge { +struct FrozenStuffStruct; +struct ScreenRegion; + struct AnimFrame { int frameNum, howMany; int noise; @@ -42,12 +45,12 @@ struct AnimFrame { struct PersonaAnimation { struct LoadedSpriteBank *theSprites; - AnimFrame *frames; + AnimFrame *frames; int numFrames; }; struct Persona { - PersonaAnimation **animation; + PersonaAnimation **animation; int numDirections; }; @@ -59,8 +62,8 @@ struct OnScreenPerson { int walkToX, walkToY, thisStepX, thisStepY, inPoly, walkToPoly; bool walking, spinning; struct LoadedFunction *continueAfterWalking; - PersonaAnimation *myAnim; - PersonaAnimation *lastUsedAnim; + PersonaAnimation *myAnim; + PersonaAnimation *lastUsedAnim; Persona *myPersona; int frameNum, frameTick, angle, wantAngle, angleOffset; bool show; @@ -70,62 +73,91 @@ struct OnScreenPerson { byte r, g, b, colourmix, transparency; }; -// Initialisation and creation -bool initPeople(); -bool addPerson(int x, int y, int objNum, Persona *p); - -// Draw to screen and to backdrop -void drawPeople(); -void freezePeople(int, int); - -// Removalisationisms -void killAllPeople(); -void killMostPeople(); -void removeOneCharacter(int i); - -// Things which affect or use all characters -OnScreenPerson *findPerson(int v); -void setScale(int16 h, int16 d); - -// Things which affect one character -void makeTalker(OnScreenPerson &me); -void makeSilent(OnScreenPerson &me); -void setShown(bool h, int ob); -void setDrawMode(int h, int ob); -void setPersonTransparency(int ob, byte x); -void setPersonColourise(int ob, byte r, byte g, byte b, byte colourmix); - -// Moving 'em -void movePerson(int x, int y, int objNum); -bool makeWalkingPerson(int x, int y, int objNum, struct LoadedFunction *func, int di); -bool forceWalkingPerson(int x, int y, int objNum, struct LoadedFunction *func, int di); -void jumpPerson(int x, int y, int objNum); -void walkAllPeople(); -bool turnPersonToFace(int thisNum, int direc); -bool stopPerson(int o); -bool floatCharacter(int f, int objNum); -bool setCharacterWalkSpeed(int f, int objNum); - -// Animating 'em -void animatePerson(int obj, PersonaAnimation *); -void animatePerson(int obj, Persona *per); -PersonaAnimation *createPersonaAnim(int num, struct VariableStack *&stacky); -inline void setBankFile(PersonaAnimation *newP, LoadedSpriteBank *sB) { - newP->theSprites = sB; -} -bool setPersonExtra(int f, int newSetting); -int timeForAnim(PersonaAnimation *fram); -PersonaAnimation *copyAnim(PersonaAnimation *orig); -PersonaAnimation *makeNullAnim(); -void deleteAnim(PersonaAnimation *orig); - -// Loading and saving -bool saveAnim(PersonaAnimation *p, Common::WriteStream *stream); -bool loadAnim(PersonaAnimation *p, Common::SeekableReadStream *stream); -bool savePeople(Common::WriteStream *stream); -bool loadPeople(Common::SeekableReadStream *stream); -bool saveCostume(Persona *cossy, Common::WriteStream *stream); -bool loadCostume(Persona *cossy, Common::SeekableReadStream *stream); +class PeopleManager { +public: + PeopleManager(SludgeEngine *vm); + ~PeopleManager(); + + // Initialisation and creation + bool init(); + bool addPerson(int x, int y, int objNum, Persona *p); + + // Draw to screen and to backdrop + void drawPeople(); + void freezePeople(int, int); + + // Removalisationisms + void kill(); + void killMostPeople(); + void removeOneCharacter(int i); + + // Things which affect or use all characters + OnScreenPerson *findPerson(int v); + void setScale(int16 h, int16 d); + + // Things which affect one character + void makeTalker(OnScreenPerson &me); + void makeSilent(OnScreenPerson &me); + void setShown(bool h, int ob); + void setDrawMode(int h, int ob); + void setPersonTransparency(int ob, byte x); + void setPersonColourise(int ob, byte r, byte g, byte b, byte colourmix); + + // Moving 'em + void movePerson(int x, int y, int objNum); + bool makeWalkingPerson(int x, int y, int objNum, struct LoadedFunction *func, int di); + bool forceWalkingPerson(int x, int y, int objNum, struct LoadedFunction *func, int di); + void jumpPerson(int x, int y, int objNum); + void walkAllPeople(); + bool turnPersonToFace(int thisNum, int direc); + bool stopPerson(int o); + bool floatCharacter(int f, int objNum); + bool setCharacterWalkSpeed(int f, int objNum); + + // Animating 'em + void animatePerson(int obj, PersonaAnimation *); + void animatePerson(int obj, Persona *per); + PersonaAnimation *createPersonaAnim(int num, struct VariableStack *&stacky); + inline void setBankFile(PersonaAnimation *newP, LoadedSpriteBank *sB) { + newP->theSprites = sB; + } + bool setPersonExtra(int f, int newSetting); + int timeForAnim(PersonaAnimation *fram); + PersonaAnimation *copyAnim(PersonaAnimation *orig); + PersonaAnimation *makeNullAnim(); + void deleteAnim(PersonaAnimation *orig); + + // Loading and saving + bool saveAnim(PersonaAnimation *p, Common::WriteStream *stream); + bool loadAnim(PersonaAnimation *p, Common::SeekableReadStream *stream); + bool savePeople(Common::WriteStream *stream); + bool loadPeople(Common::SeekableReadStream *stream); + bool saveCostume(Persona *cossy, Common::WriteStream *stream); + bool loadCostume(Persona *cossy, Common::SeekableReadStream *stream); + + // Freeze + void freeze(FrozenStuffStruct *frozenStuff); + void resotre(FrozenStuffStruct *frozenStuff); + +private: + ScreenRegion *_personRegion; + OnScreenPerson *_allPeople; + int16 _scaleHorizon; + int16 _scaleDivide; + + SludgeEngine *_vm; + + void setFrames(OnScreenPerson &m, int a); + void turnMeAngle(OnScreenPerson *thisPerson, int direc); + void spinStep(OnScreenPerson *thisPerson); + void rethinkAngle(OnScreenPerson *thisPerson); + void moveAndScale(OnScreenPerson &me, float x, float y); + void setMyDrawMode(OnScreenPerson *moveMe, int h); + void shufflePeople(); + bool handleClosestPoint(int &setX, int &setY, int &setPoly); + bool doBorderStuff(OnScreenPerson *moveMe); + bool walkMe(OnScreenPerson *thisPerson, bool move = true); +}; } // End of namespace Sludge diff --git a/engines/sludge/sludge.cpp b/engines/sludge/sludge.cpp index 483fb53d7d..38fe12a4a6 100644 --- a/engines/sludge/sludge.cpp +++ b/engines/sludge/sludge.cpp @@ -29,6 +29,7 @@ #include "sludge/event.h" #include "sludge/fonttext.h" #include "sludge/graphics.h" +#include "sludge/people.h" #include "sludge/region.h" #include "sludge/sludge.h" #include "sludge/sound.h" @@ -74,6 +75,7 @@ SludgeEngine::SludgeEngine(OSystem *syst, const SludgeGameDescription *gameDesc) fatalInfo = "Initialisation error! Something went wrong before we even got started!"; // Init managers + _peopleMan = new PeopleManager(this); _resMan = new ResourceManager(); _languageMan = new LanguageManager(); _objMan = new ObjectManager(this); @@ -126,6 +128,8 @@ SludgeEngine::~SludgeEngine() { _speechMan = nullptr; delete _regionMan; _regionMan = nullptr; + delete _peopleMan; + _peopleMan = nullptr; } Common::Error SludgeEngine::run() { diff --git a/engines/sludge/sludge.h b/engines/sludge/sludge.h index fa1038231a..66a443e32a 100644 --- a/engines/sludge/sludge.h +++ b/engines/sludge/sludge.h @@ -41,6 +41,7 @@ extern SludgeEngine *g_sludge; class CursorManager; class EventManager; class GraphicsManager; +class PeopleManager; class RegionManager; class SoundManager; class SpeechManager; @@ -90,6 +91,7 @@ public: CursorManager *_cursorMan; SpeechManager *_speechMan; RegionManager *_regionMan; + PeopleManager *_peopleMan; SludgeEngine(OSystem *syst, const SludgeGameDescription *gameDesc); virtual ~SludgeEngine(); diff --git a/engines/sludge/sludger.cpp b/engines/sludge/sludger.cpp index 01d3b1794e..4f5f204d92 100644 --- a/engines/sludge/sludger.cpp +++ b/engines/sludge/sludger.cpp @@ -147,7 +147,7 @@ void initSludge() { g_sludge->_languageMan->init(); g_sludge->_gfxMan->init(); g_sludge->_resMan->init(); - initPeople(); + g_sludge->_peopleMan->init(); initFloor(); g_sludge->_objMan->init(); g_sludge->_speechMan->init(); @@ -179,7 +179,7 @@ void initSludge() { void killSludge() { killAllFunctions(); - killAllPeople(); + g_sludge->_peopleMan->kill(); g_sludge->_regionMan->kill(); setFloorNull(); g_sludge->_speechMan->kill(); @@ -330,7 +330,7 @@ void displayBase() { g_sludge->_gfxMan->clear(); // Clear screen g_sludge->_gfxMan->drawBackDrop();// Draw Backdrop g_sludge->_gfxMan->drawZBuffer(g_sludge->_gfxMan->getCamX(), g_sludge->_gfxMan->getCamY(), false); - drawPeople();// Then add any moving characters... + g_sludge->_peopleMan->drawPeople();// Then add any moving characters... g_sludge->_gfxMan->displaySpriteLayers(); } diff --git a/engines/sludge/speech.cpp b/engines/sludge/speech.cpp index 6324da88cc..c688bf312d 100644 --- a/engines/sludge/speech.cpp +++ b/engines/sludge/speech.cpp @@ -61,7 +61,7 @@ void SpeechManager::kill() { } if (_speech->currentTalker) { - makeSilent(*(_speech->currentTalker)); + g_sludge->_peopleMan->makeSilent(*(_speech->currentTalker)); _speech->currentTalker = NULL; } @@ -176,7 +176,7 @@ int SpeechManager::wrapSpeechPerson(const Common::String &theText, OnScreenPerso - thePerson.thisType->speechGap, thePerson.thisType->wrapSpeech, sampleFile); if (animPerson) { - makeTalker(thePerson); + g_sludge->_peopleMan->makeTalker(thePerson); _speech->currentTalker = &thePerson; } return i; @@ -188,7 +188,7 @@ int SpeechManager::wrapSpeech(const Common::String &theText, int objT, int sampl int cameraY = g_sludge->_gfxMan->getCamY(); _speech->lookWhosTalking = objT; - OnScreenPerson *thisPerson = findPerson(objT); + OnScreenPerson *thisPerson = g_sludge->_peopleMan->findPerson(objT); if (thisPerson) { setObjFontColour(thisPerson->thisType); i = wrapSpeechPerson(theText, *thisPerson, sampleFile, animPerson); @@ -274,7 +274,7 @@ bool SpeechManager::load(Common::SeekableReadStream *stream) { _speech->lookWhosTalking = stream->readUint16BE(); if (stream->readByte()) { - _speech->currentTalker = findPerson(stream->readUint16BE()); + _speech->currentTalker = g_sludge->_peopleMan->findPerson(stream->readUint16BE()); } else { _speech->currentTalker = NULL; } diff --git a/engines/sludge/variable.cpp b/engines/sludge/variable.cpp index 9cbb9f49f8..ae96dd654e 100644 --- a/engines/sludge/variable.cpp +++ b/engines/sludge/variable.cpp @@ -65,7 +65,7 @@ void unlinkVar(Variable &thisVar) { break; case SVT_ANIM: - deleteAnim(thisVar.varData.animHandler); + g_sludge->_peopleMan->deleteAnim(thisVar.varData.animHandler); break; default: @@ -87,10 +87,10 @@ void newAnimationVariable(Variable &thisVar, PersonaAnimation *i) { PersonaAnimation *getAnimationFromVar(Variable &thisVar) { if (thisVar.varType == SVT_ANIM) - return copyAnim(thisVar.varData.animHandler); + return g_sludge->_peopleMan->copyAnim(thisVar.varData.animHandler); if (thisVar.varType == SVT_INT && thisVar.varData.intValue == 0) - return makeNullAnim(); + return g_sludge->_peopleMan->makeNullAnim(); fatal("Expecting an animation variable; found Variable of type", typeName[thisVar.varType]); return NULL; @@ -116,7 +116,7 @@ Persona *getCostumeFromVar(Variable &thisVar) { return NULL; for (int iii = 0; iii < 3; iii++) - p->animation[iii] = copyAnim(thisVar.varData.animHandler); + p->animation[iii] = g_sludge->_peopleMan->copyAnim(thisVar.varData.animHandler); break; @@ -370,7 +370,7 @@ bool copyMain(const Variable &from, Variable &to) { return true; case SVT_ANIM: - to.varData.animHandler = copyAnim(from.varData.animHandler); + to.varData.animHandler = g_sludge->_peopleMan->copyAnim(from.varData.animHandler); return true; case SVT_NULL: |