Skip to content

Commit

Permalink
PRINCE: freeHeroAnim(), O_SETHEROANIM()
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaslw committed Jul 20, 2014
1 parent 8b9d3be commit 2749f97
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
9 changes: 6 additions & 3 deletions engines/prince/hero.cpp
Expand Up @@ -37,7 +37,7 @@ Hero::Hero(PrinceEngine *vm, GraphicsMan *graph) : _vm(vm), _graph(graph)
, _number(0), _visible(false), _state(MOVE), _middleX(0), _middleY(0)
, _boreNum(1), _currHeight(0), _moveDelay(0), _shadMinus(0), _moveSetType(0)
, _lastDirection(kHeroDirDown), _destDirection(kHeroDirDown), _talkTime(0), _boredomTime(0), _phase(0)
, _specAnim(0), _drawX(0), _drawY(0), _drawZ(0), _zoomFactor(0), _scaleValue(0)
, _specAnim(nullptr), _drawX(0), _drawY(0), _drawZ(0), _zoomFactor(0), _scaleValue(0)
, _shadZoomFactor(0), _shadScaleValue(0), _shadLineLen(0), _shadDrawX(0), _shadDrawY(0)
, _frameXSize(0), _frameYSize(0), _scaledFrameXSize(0), _scaledFrameYSize(0), _color(0)
, _coords(nullptr), _dirTab(nullptr), _currCoords(nullptr), _currDirTab(nullptr), _step(0)
Expand All @@ -52,6 +52,7 @@ Hero::~Hero() {
free(_zoomBitmap);
free(_shadowBitmap);
delete[] _shadowLine;
freeHeroAnim();
}

bool Hero::loadAnimSet(uint32 animSetNr) {
Expand Down Expand Up @@ -971,9 +972,11 @@ void Hero::freeOldMove() {
_state = Hero::STAY;
}

//TODO
void Hero::freeHeroAnim() {

if (_specAnim != nullptr) {
delete _specAnim;
_specAnim = nullptr;
}
}

}
Expand Down
2 changes: 1 addition & 1 deletion engines/prince/hero.h
Expand Up @@ -180,7 +180,7 @@ class Hero {
int16 _boredomTime; // Boredom current boredom time in frames
uint16 _boreNum; // Bore anim frame
int16 _talkTime; // TalkTime time of talk anim
int32 _specAnim; // SpecAnim additional anim
Animation *_specAnim; // additional anim

uint16 _currHeight; // height of current anim phase

Expand Down
28 changes: 27 additions & 1 deletion engines/prince/script.cpp
Expand Up @@ -181,6 +181,10 @@ int32 Script::getOptionStandardOffset(int option) {
}
}

uint8 *Script::getHeroAnimName(int offset) {
return &_data[offset];
}

void Script::setBackAnimId(int offset, int animId) {
WRITE_UINT32(&_data[offset], animId);
}
Expand Down Expand Up @@ -1167,8 +1171,30 @@ void Interpreter::O_WAITTEXT() {
}

void Interpreter::O_SETHEROANIM() {
uint16 hero = readScriptFlagValue();
uint16 heroId = readScriptFlagValue();
int32 offset = readScript<uint32>();
Hero *hero = nullptr;
if (!heroId) {
hero = _vm->_mainHero;
} else {
hero = _vm->_secondHero;
}
if (hero != nullptr) {
hero->freeHeroAnim();
if (hero ->_specAnim == nullptr) {
hero->_specAnim = new Animation();
if (offset < 100) {
const Common::String animName = Common::String::format("AN%02d", offset);
Resource::loadResource(hero->_specAnim, animName.c_str(), true);
} else {
const Common::String animName = Common::String((const char *)_script->getHeroAnimName(offset));
Common::String normalizedPath = lastPathComponent(animName, '\\');
Resource::loadResource(hero->_specAnim, normalizedPath.c_str(), true);
}
hero->_phase = 0;
hero->_state = Hero::SPEC;
}
}
debugInterpreter("O_SETHEROANIM hero %d, offset %d", hero, offset);
}

Expand Down
1 change: 1 addition & 0 deletions engines/prince/script.h
Expand Up @@ -138,6 +138,7 @@ class Script {
int32 getShadowScale(int locationNr);
uint8 *getRoomOffset(int locationNr);
int32 getOptionStandardOffset(int option);
uint8 *getHeroAnimName(int offset);
void setBackAnimId(int offset, int animId);
void setObjId(int offset, int objId);
void installBackAnims(Common::Array<BackgroundAnim> &backAnimList, int offset);
Expand Down

0 comments on commit 2749f97

Please sign in to comment.