use Command class

svn-id: r11017
This commit is contained in:
Gregory Montoir 2003-10-31 13:47:28 +00:00
parent 23188d5188
commit d1ff236f3c
11 changed files with 207 additions and 145 deletions

View File

@ -647,7 +647,7 @@ Cutaway::ObjectType Cutaway::getObjectType(CutawayObject &object) {
/* Copy FROM_OBJECT into OBJECT */
if(object.objectNumber != object.fromObject) {
objectCopy(object.fromObject, object.objectNumber);
_logic->objectCopy(object.fromObject, object.objectNumber);
}
else {
// Same object, so just turn it on!
@ -1190,65 +1190,6 @@ void Cutaway::run(char *nextFilename) {
/* XXX playsong(_lastSong) */ ;
}
void Cutaway::objectCopy(int dummyObjectIndex, int realObjectIndex) {
// P3_COPY_FROM function in cutaway.c
/* Copy data from Dummy (D) object to object (K)
If COPY_FROM Object images are greater than COPY_TO Object
images then swap the objects around. */
ObjectData *dummyObject = _logic->objectData(dummyObjectIndex);
ObjectData *realObject = _logic->objectData(realObjectIndex);
int fromState = (dummyObject->name < 0) ? -1 : 0;
int frameCountReal = 1;
int frameCountDummy = 1;
int graphic = realObject->image;
if (graphic > 0) {
if (graphic > 5000)
graphic -= 5000;
GraphicData *data = _logic->graphicData(graphic);
if (data->lastFrame > 0)
frameCountReal = data->lastFrame - data->firstFrame + 1;
graphic = dummyObject->image;
if (graphic > 0) {
if (graphic > 5000)
graphic -= 5000;
data = _logic->graphicData(graphic);
if (data->lastFrame > 0)
frameCountDummy = data->lastFrame - data->firstFrame + 1;
}
}
ObjectData temp = *realObject;
*realObject = *dummyObject;
if (frameCountDummy > frameCountReal)
*dummyObject = temp;
realObject->name = abs(realObject->name);
if (fromState == -1)
dummyObject->name = -abs(dummyObject->name);
// Make sure that WALK_OFF_DATA is copied too!
for (int i = 1; i <= _logic->walkOffCount(); i++) {
WalkOffData *walkOffData = _logic->walkOffData(i);
if (walkOffData->entryObj == (int16)dummyObjectIndex) {
walkOffData->entryObj = (int16)realObjectIndex;
break;
}
}
}
void Cutaway::goToFinalRoom() {
// Lines 1901-2032 in cutaway.c
byte *ptr = _gameStatePtr;
@ -1361,7 +1302,7 @@ void Cutaway::updateGameState() {
ObjectData *objectData = _logic->objectData(objectIndex);
objectData->name = abs(objectData->name);
if (fromObject > 0)
objectCopy(fromObject, objectIndex);
_logic->objectCopy(fromObject, objectIndex);
_logic->roomRefreshObject(objectIndex);
}
else if (objectIndex < 0) { // Hide the object

View File

@ -259,9 +259,6 @@ class Cutaway {
//! Restore QueenLogic::_objectData from _personData
void restorePersonData();
//! Copy data from dummy object to object
void objectCopy(int dummyObjectIndex, int objectIndex);
//! Go to the final room
void goToFinalRoom();

View File

@ -58,12 +58,12 @@ enum Direction {
enum {
INK_BG_PANEL = 226,
INK_JOURNAL = 16,
INK_CMD_SELECT = 17,
INK_CMD_NORMAL = 1,
INK_JOURNAL = 248,
INK_CMD_SELECT = 255,
INK_CMD_NORMAL = 225,
INK_CMD_LOCK = 234,
INK_TALK_NORMAL = 1,
INK_JOE = 17,
INK_TALK_NORMAL = 7,
INK_JOE = 14,
INK_OUTLINED_TEXT = 16
};

View File

@ -142,8 +142,6 @@ private:
bool _gotTick;
uint8 _mouseCursor[14 * 14];
Dynalum _dynalum;
OSystem *_system;

View File

@ -30,7 +30,7 @@ namespace Queen {
Input::Input(OSystem *system) :
_system(system), _fastMode(false), _keyVerb(VERB_NONE),
_cutawayRunning(false), _cutawayQuit(false), _talkQuit(false),
_inKey(0) {
_inKey(0), _mouseButton(0), _mouse_x(0), _mouse_y(0) {
}
void Input::delay() {
@ -58,7 +58,6 @@ void Input::delay(uint amount) {
case OSystem::EVENT_MOUSEMOVE:
_mouse_x = event.mouse.x;
_mouse_y = event.mouse.y;
break;
case OSystem::EVENT_LBUTTONDOWN:

View File

@ -21,6 +21,7 @@
#include "stdafx.h"
#include "queen/logic.h"
#include "queen/command.h"
#include "queen/cutaway.h"
#include "queen/defs.h"
#include "queen/display.h"
@ -169,7 +170,7 @@ void State::alterDefaultVerb(uint16 *objState, Verb v) {
*objState = (*objState & ~0xF0) | (val << 4);
}
/*
void Command_::readAllCommandsFrom(byte *&ptr) {
uint16 i;
@ -218,7 +219,7 @@ void Command_::readAllCommandsFrom(byte *&ptr) {
_cmdGameState[i].readFrom(ptr);
}
}
*/
Common::RandomSource Logic::randomizer;
@ -232,6 +233,7 @@ Logic::Logic(Resource *resource, Graphics *graphics, Display *theDisplay, Input
_joe.x = _joe.y = 0;
_joe.scale = 100;
_walk = new Walk(this, _graphics);
_cmd = new Command(this, _graphics, _input, _walk);
memset(_gameState, 0, sizeof(_gameState));
initialise();
}
@ -239,6 +241,7 @@ Logic::Logic(Resource *resource, Graphics *graphics, Display *theDisplay, Input
Logic::~Logic() {
delete[] _jas;
delete _walk;
delete _cmd;
}
void Logic::initialise() {
@ -337,7 +340,7 @@ void Logic::initialise() {
_objectDescription[i].readFrom(ptr);
}
Command_ cmd; cmd.readAllCommandsFrom(ptr); // TEMP
_cmd->readCommandsFrom(ptr);
_entryObj = READ_BE_UINT16(ptr); ptr += 2;
@ -449,12 +452,14 @@ void Logic::initialise() {
else
_settings.speechToggle = true;
_cmd->clear(false);
// XXX SCENE = 0
memset(_gameState, 0, sizeof(_gameState));
_graphics->loadPanel();
_graphics->bobSetupControl();
joeSetup();
zoneSetupPanel();
memset(_zones, 0, sizeof(_zones));
_oldRoom = 0;
}
@ -771,6 +776,7 @@ void Logic::zoneSet(uint16 screen, uint16 zone, const Box& box) {
uint16 Logic::zoneIn(uint16 screen, uint16 x, uint16 y) const {
debug(9, "Logic::zoneIn(%d, (%d,%d))", screen, x, y);
int i;
if (screen == ZONE_PANEL) {
y -= ROOM_ZONE_HEIGHT;
@ -800,6 +806,7 @@ uint16 Logic::zoneInArea(uint16 screen, uint16 x, uint16 y) const {
void Logic::zoneClearAll(uint16 screen) {
debug(9, "Logic::zoneClearAll(%d)", screen);
int i;
for(i = 1; i < MAX_ZONES_NUMBER; ++i) {
_zones[screen][i].valid = false;
@ -1740,20 +1747,20 @@ uint16 Logic::joeFace() {
}
int16 Logic::joeWalkTo(int16 x, int16 y, const Command_ *cmd, bool mustWalk) {
int16 Logic::joeWalkTo(int16 x, int16 y, bool mustWalk) {
// Check to see if object is actually an exit to another
// room. If so, then set up new room
uint16 k = _roomData[_currentRoom];
ObjectData *objData = &_objectData[k + cmd->noun2];
ObjectData *objData = &_objectData[k + _cmd->selectedNoun()];
if (objData->x != 0 || objData->y != 0) {
x = objData->x;
y = objData->y;
}
if (cmd->action2.value() == VERB_WALK_TO) {
if (_cmd->selectedAction().value() == VERB_WALK_TO) {
_entryObj = objData->entryObj;
}
else {
@ -1762,17 +1769,16 @@ int16 Logic::joeWalkTo(int16 x, int16 y, const Command_ *cmd, bool mustWalk) {
_newRoom = 0;
if (_entryObj != 0 && cmd->action2.value() != VERB_CLOSE) {
if (_entryObj != 0 && _cmd->selectedAction().value() != VERB_CLOSE) {
// because this is an exit object, see if there is
// a walk off point and set (x,y) accordingly
WalkOffData *wod = walkOffPointForObject(k + cmd->noun2);
WalkOffData *wod = walkOffPointForObject(k + _cmd->selectedNoun());
if (wod != NULL) {
x = wod->x;
y = wod->y;
}
}
// determine which way for Joe to face Object
uint16 facing = State::findDirection(objData->state);
@ -1881,7 +1887,7 @@ void Logic::joeUseDress(bool showCut) {
joeFace();
if (gameState(VAR_DRESSING_MODE) == 0) {
playCutaway("cdres.CUT");
// XXX INS_ITEM_NUM(58);
inventoryInsertItem(58);
}
else {
playCutaway("cudrs.CUT");
@ -1889,8 +1895,7 @@ void Logic::joeUseDress(bool showCut) {
}
_display->palSetJoe(JP_DRESS);
joeSetupFromBanks("JoeD_A.BBK", "JoeD_B.BBK");
// XXX DEL_ITEM_NUM(56, 0);
// XXX INVENTORY();
inventoryDeleteItem(56);
gameState(VAR_DRESSING_MODE, 2);
}
@ -1901,12 +1906,11 @@ void Logic::joeUseClothes(bool showCut) {
joeFacing(DIR_FRONT);
joeFace();
playCutaway("cdclo.CUT");
// XXX INS_ITEM_NUM(56);
inventoryInsertItem(56);
}
_display->palSetJoe(JP_CLOTHES);
joeSetupFromBanks("Joe_A.BBK", "Joe_B.BBK");
// XXX DEL_ITEM_NUM(58,0);
// XXX INVENTORY();
inventoryDeleteItem(58);
gameState(VAR_DRESSING_MODE, 0);
}
@ -1994,6 +1998,130 @@ uint16 Logic::findObjectGlobalNumber(uint16 zoneNum) const {
}
uint16 Logic::findInventoryItem(int invSlot) const {
// queen.c l.3894-3898
if (invSlot >= 0 && invSlot < 4) {
return _inventoryItem[invSlot];
}
return 0;
}
void Logic::inventorySetup() {
_graphics->bankLoad("objects.BBK", 14);
_inventoryItem[0] = 1; // Bat
_inventoryItem[1] = _resource->isDemo() ? 7 : 2; // Journal
_inventoryItem[2] = 0;
_inventoryItem[3] = 0;
}
void Logic::inventoryRefresh() {
int16 i;
uint16 x = 182;
for (i = 0; i < 4; ++i) {
uint16 itemNum = _inventoryItem[i];
if (itemNum != 0) {
// 1st object in inventory uses frame 8,
// whereas 2nd, 3rd and 4th uses frame 9
uint16 dstFrame = (itemNum != 0) ? 8 : 9;
// unpack frame for object and draw it
_graphics->bankUnpack(_itemData[itemNum].frame, dstFrame, 14);
_graphics->bobDrawInventoryItem(dstFrame, x, 14);
}
else {
// no object, clear the panel
_graphics->bobDrawInventoryItem(0, x, 14);
}
x += 35;
}
// XXX OLDVERB=VERB;
update();
}
void Logic::inventoryInsertItem(uint16 itemNum, bool refresh) {
warning("Logic::inventoryInsertItem() unimplemented");
}
void Logic::inventoryDeleteItem(uint16 itemNum, bool refresh) {
warning("Logic::inventoryDeleteItem() unimplemented");
}
void Logic::inventoryScroll(uint16 count, bool up) {
warning("Logic::inventoryScroll() unimplemented");
}
void Logic::objectCopy(int dummyObjectIndex, int realObjectIndex) {
// P3_COPY_FROM function in cutaway.c
/* Copy data from Dummy (D) object to object (K)
If COPY_FROM Object images are greater than COPY_TO Object
images then swap the objects around. */
ObjectData *dummyObject = objectData(dummyObjectIndex);
ObjectData *realObject = objectData(realObjectIndex);
int fromState = (dummyObject->name < 0) ? -1 : 0;
int frameCountReal = 1;
int frameCountDummy = 1;
int graphic = realObject->image;
if (graphic > 0) {
if (graphic > 5000)
graphic -= 5000;
GraphicData *data = graphicData(graphic);
if (data->lastFrame > 0)
frameCountReal = data->lastFrame - data->firstFrame + 1;
graphic = dummyObject->image;
if (graphic > 0) {
if (graphic > 5000)
graphic -= 5000;
data = graphicData(graphic);
if (data->lastFrame > 0)
frameCountDummy = data->lastFrame - data->firstFrame + 1;
}
}
ObjectData temp = *realObject;
*realObject = *dummyObject;
if (frameCountDummy > frameCountReal)
*dummyObject = temp;
realObject->name = abs(realObject->name);
if (fromState == -1)
dummyObject->name = -abs(dummyObject->name);
// Make sure that WALK_OFF_DATA is copied too!
for (int i = 1; i <= _numWalkOffs; i++) {
WalkOffData *walkOff = &_walkOffData[i];
if (walkOff->entryObj == (int16)dummyObjectIndex) {
walkOff->entryObj = (int16)realObjectIndex;
break;
}
}
}
void Logic::checkPlayer() {
update();
_cmd->updatePlayer();
}
void Logic::update() {
_graphics->update(_currentRoom);
_input->delay();

View File

@ -41,29 +41,6 @@ struct ZoneSlot {
Box box;
};
// Temporary class
struct Command_ {
Verb action, action2;
uint16 noun, noun2;
CmdListData *_cmdList;
uint16 _numCmdList; //COM_LIST_MAX
CmdArea *_cmdArea;
uint16 _numCmdArea; //COM_A_MAX
CmdObject *_cmdObject;
uint16 _numCmdObject; //COM_O_MAX
CmdInventory *_cmdInventory;
uint16 _numCmdInventory; //COM_I_MAX
CmdGameState *_cmdGameState;
uint16 _numCmdGameState; //COM_G_MAX
void readAllCommandsFrom(byte *&ptr);
};
struct GameSettings {
int musicVolume;
bool musicToggle;
@ -130,10 +107,11 @@ struct State {
};
class Graphics;
class Resource;
class Command;
class Display;
class Input;
class Graphics;
class Resource;
class Sound;
class Walk;
@ -172,7 +150,7 @@ public:
uint16 currentRoomObjMax() const { return _objMax[_currentRoom]; }
uint16 currentRoomData() const { return _roomData[_currentRoom]; }
ObjectDescription *objectDescription(uint16 objNum) const { return &_objectDescription[objNum]; }
uint16 objectDescriptionCount() const { return _numDescriptions; }
uint16 objectDescriptionCount() const { return _numObjDesc; }
uint16 joeFacing() { return _joe.facing; }
uint16 joeX() { return _joe.x; }
@ -240,7 +218,7 @@ public:
uint16 joeFace();
//! WALK()
int16 joeWalkTo(int16 x, int16 y, const Command_ *cmd, bool mustWalk);
int16 joeWalkTo(int16 x, int16 y, bool mustWalk);
//! GRAB_JOE()
void joeGrab(uint16 state, uint16 speed);
@ -266,14 +244,27 @@ public:
Verb findVerbUnderCursor(int16 cursorx, int16 cursory) const;
uint16 findObjectUnderCursor(int16 cursorx, int16 cursory) const;
Walk *walk() { return _walk; }
Display *display() { return _display; }
Walk *walk() const { return _walk; }
Display *display() const { return _display; }
Command *command() const { return _cmd; }
uint16 findObjectRoomNumber(uint16 zoneNum) const;
uint16 findObjectGlobalNumber(uint16 zoneNum) const;
const char *lockedVerbPrefix() const { return _joeResponse[39]; }
void inventorySetup();
uint16 findInventoryItem(int invSlot) const;
void inventoryRefresh();
void inventoryInsertItem(uint16 itemNum, bool refresh = true);
void inventoryDeleteItem(uint16 itemNum, bool refresh = true);
void inventoryScroll(uint16 count, bool up);
//! Copy data from dummy object to object
void objectCopy(int dummyObjectIndex, int objectIndex);
void checkPlayer();
void update();
@ -324,7 +315,7 @@ protected:
uint16 _numObjects;
ObjectDescription *_objectDescription;
uint16 _numDescriptions;
uint16 _numObjDesc;
ActorData *_actorData;
uint16 _numActors; //ACTOR_DATA_MAX
@ -353,7 +344,7 @@ protected:
//! Object description (Look At)
char **_objDescription; //OBJECT_DESCRstr
uint16 _numObjDesc;
uint16 _numDescriptions;
char **_objName; //OBJECT_NAMEstr
uint16 _numNames;
@ -404,12 +395,16 @@ protected:
GameSettings _settings;
//! Inventory items
int16 _inventoryItem[4];
Resource *_resource;
Graphics *_graphics;
Display *_display;
Input *_input;
Sound *_sound;
Walk *_walk;
Command *_cmd;
//! Verbs (in order) available in panel
static const VerbEnum PANEL_VERBS[];

View File

@ -25,6 +25,7 @@
#include "base/plugins.h"
#include "common/config-manager.h"
#include "common/file.h"
#include "queen/command.h"
#include "queen/cutaway.h"
#include "queen/display.h"
#include "queen/graphics.h"
@ -158,13 +159,13 @@ void QueenEngine::roomChanged() {
_logic->gameState(VAR_INTRO_PLAYED, 1);
// XXX setupItems();
// XXX inventory();
_logic->inventorySetup();
_logic->inventoryRefresh();
}
else {
_logic->roomDisplay(_logic->roomName(_logic->currentRoom()), RDM_FADE_JOE, 100, 1, false);
}
// XXX _drawMouseFlag = 1;
_display->mouseCursorShow(true); // _drawMouseFlag = 1;
}
@ -187,22 +188,23 @@ void QueenEngine::go() {
_logic->currentRoom(_logic->newRoom());
roomChanged();
// XXX _logic->fullScreen(false);
if (_logic->currentRoom() == _logic->newRoom())
if (_logic->currentRoom() == _logic->newRoom()) {
_logic->newRoom(0);
}
}
else {
if (_logic->joeWalk() == 2) {
_logic->joeWalk(0);
// XXX executeAction(yes);
_logic->command()->executeCurrentAction(true);
}
else {
// XXX if (_parse == 1)
// XXX clearCommand(1);
if (_logic->command()->parse()) {
_logic->command()->clear(true);
}
_logic->joeWalk(0);
// XXX checkPlayer();
_logic->checkPlayer();
}
}
break; // XXX don't loop yet
}
}

View File

@ -265,7 +265,7 @@ struct ItemData {
//! state of the object
uint16 state;
//! bank bobframe
uint16 bobFrame;
uint16 frame;
//! entry in OBJECT_DESCR (>0 if available)
int16 sfxDescription;
@ -273,7 +273,7 @@ struct ItemData {
name = (int16)READ_BE_UINT16(ptr); ptr += 2;
description = READ_BE_UINT16(ptr); ptr += 2;
state = READ_BE_UINT16(ptr); ptr += 2;
bobFrame = READ_BE_UINT16(ptr); ptr += 2;
frame = READ_BE_UINT16(ptr); ptr += 2;
sfxDescription = (int16)READ_BE_UINT16(ptr); ptr += 2;
}
};

View File

@ -156,7 +156,7 @@ bool Walk::animateJoe() {
if (pbs->speed == 0) {
pbs->speed = 1;
}
_logic->update(); // CHECK_PLAYER();
_logic->checkPlayer();
if (_logic->joeWalk() == 2) { // || cutQuit
// we are about to do something else, so stop walking
interrupted = true;

View File

@ -16,7 +16,6 @@ COMMAND
=======
ALTER_DEFAULT() Command::alterDefault
CLEAR_COMMAND() Command::clear
CHECK_PLAYER() Command::checkPlayer
EXECUTE_ACTION() Command::executeCurrentAction
FIND_DEFAULT() Command::findDefault
LOOK() Command::look
@ -33,7 +32,8 @@ SELECT_ITEM() Command::grabSelectedItem
SELECT_NOUN() Command::grabSelectedNoun
SELECT_VERB() Command::grabSelectedVerb
-
ACTION,ACTION2 Command::_action*
ACTION Command::_currentAction
ACTION2 Command::_selectedAction
CLEVEL Command::_commandLevel
COM_A Command::_cmdArea
COM_A_MAX Command::_numCmdArea
@ -49,7 +49,8 @@ COMMANDstr Command::_command
DEFCOMM Command::_defaultVerb
MKEY Command::_mouseKey
OLDVERB,VERB Command::_*verb*
OLDNOUN,NOUN,NOUN2 Command::_*noun*
OLDNOUN,NOUN Command::_*noun*
NOUN2 Command::_selectedNoun
PARSE Command::_parse
SUBJ1,SUBJ2,SUBJECT Command::_subject*
@ -163,14 +164,14 @@ no_check_keys Input::_noCheckKeys
INVENTORY
=========
DEL_ITEM_NUM()
INS_ITEM_NUM()
INVDWN()
INVENTORY()
INVUP()
SETUP_ITEMS()
DEL_ITEM_NUM() Logic::inventoryDeleteItem // TODO
INS_ITEM_NUM() Logic::inventoryInsertItem // TODO
INVDWN() Logic::inventoryScroll // TODO
INVENTORY() Logic::inventoryRefresh
INVUP() Logic::inventoryScroll // TODO
SETUP_ITEMS() Logic::inventorySetup
-
INV1,INV2,INV3,INV4
INV1,INV2,INV3,INV4 Logic::_inventoryItem
JOE
@ -202,6 +203,7 @@ in_journal
LOGIC
=====
CHECK_PLAYER() Logic::checkPlayer
DISP_OBJECTS() Logic::roomSetupObjects
DISP_ROOM() Logic::roomDisplay
FIND_BOB() Logic::findBob
@ -209,7 +211,7 @@ FIND_FRAME() Logic::findFrame
FIND_GRAPHIC() Logic::graphicData
FIND_SCALE() Logic::findScale
FIND_VERB() Logic::findVerb
P3_COPY_FROM() Cutaway::objectCopy
P3_COPY_FROM() Logic::objectCopy
R_MAP() (handle map 'm1')
REDISP_OBJECT() Logic::roomRefreshObject
restart_game()
@ -217,8 +219,8 @@ SETUP_BOBS() Graphics::bobSetupControl
SETUP_FURNITURE() Logic::roomSetupFurniture
SETUP_ROOM() QueenEngine::roomChanged
SETUP_SCREENS() *not needed* (only calls Graphics::loadPanel)
SETUP_VARS()
update() Graphics::update
SETUP_VARS() *not needed* (equivalent to Command::clear(), SCENE=0, clear(gamestate))
update() Logic::update
-
A_ANIMstr Logic::_aAnim
A_ANIM_MAX Logic::_numAAnim