some refactoring in Command code (removed/commented unused code, renamed some methods)

svn-id: r11619
This commit is contained in:
Gregory Montoir 2003-12-13 20:05:28 +00:00
parent 35c481fd61
commit 32d044d302
7 changed files with 402 additions and 516 deletions

File diff suppressed because it is too large Load Diff

View File

@ -51,31 +51,22 @@ struct CmdText {
};
struct CurrentCmdState {
struct CmdState {
void init();
void addObject(int16 objNum);
Verb oldVerb;
Verb verb;
Verb oldVerb, verb;
Verb action;
int16 oldNoun;
int16 noun;
int16 oldNoun, noun;
int commandLevel;
int16 subject1;
int16 subject2;
};
int16 subject[2];
struct SelectedCmdState {
void init();
Verb defaultVerb;
Verb action;
int16 noun;
Verb selAction;
int16 selNoun;
};
class Command {
public:
@ -85,7 +76,7 @@ public:
void clear(bool clearTexts);
//! execute last constructed command
void executeCurrentAction(bool walk);
void executeCurrentAction();
//! get player input and construct command from it
void updatePlayer();
@ -93,8 +84,6 @@ public:
//! read all command arrays from stream
void readCommandsFrom(byte *&ptr);
//! return true if command is ready to be executed
bool parse() const { return _parse; }
enum {
MAX_MATCHING_CMDS = 50
@ -103,6 +92,9 @@ public:
private:
ObjectData *findObjectData(uint16 objRoomNum) const;
ItemData *findItemData(Verb invNum) const;
int16 executeCommand(uint16 comId, int16 condResult);
int16 makeJoeWalkTo(int16 x, int16 y, int16 objNum, Verb v, bool mustWalk);
@ -116,16 +108,10 @@ private:
bool executeIfCutaway(const char *description);
bool executeIfDialog(const char *description);
bool handleDefaultCommand(bool walk);
void executeStandardStuff(Verb action, int16 subj1, int16 subj2);
bool handleWrongAction();
void sayInvalidAction(Verb action, int16 subj1, int16 subj2);
void changeObjectState(Verb action, int16 obj, int16 song, bool cutDone);
void cleanupCurrentAction();
//! find default verb action for specified object
Verb findDefault(uint16 obj, bool itemType);
//! alter default verb action for specified object and update command display
void alterDefault(Verb def, bool itemType);
//! OPEN_CLOSE_OTHER(OBJECT_DATA[S][4])
void openOrCloseAssociatedObject(Verb action, int16 obj);
@ -145,15 +131,17 @@ private:
//! update description for object and returns description number to use
uint16 nextObjectDescription(ObjectDescription *objDesc, uint16 firstDesc);
//! look at current object / item and speak its description
void look();
void lookCurrentItem();
void lookCurrentRoom();
void lookCurrentIcon();
//! speak description of selected object
void lookAtSelectedObject();
bool isVerbPanel(Verb v) const { return v >= VERB_PANEL_COMMAND_FIRST && v <= VERB_PANEL_COMMAND_LAST; };
//! get the current objects under the cursor
void lookForCurrentObject();
//! get the current icon panel under the cursor (inventory item or verb)
void lookForCurrentIcon();
bool isVerbAction(Verb v) const { return (v >= VERB_PANEL_COMMAND_FIRST && v <= VERB_PANEL_COMMAND_LAST) || (v == VERB_WALK_TO); };
bool isVerbInv(Verb v) const { return v >= VERB_INV_FIRST && v <= VERB_INV_LAST; }
bool isVerbScrollInv(Verb v) const { return v == VERB_SCROLL_UP || v == VERB_SCROLL_DOWN; }
CmdListData *_cmdList;
uint16 _numCmdList;
@ -176,9 +164,8 @@ private:
//! flag indicating that the current command is fully constructed
bool _parse;
CurrentCmdState _curCmd;
SelectedCmdState _selCmd;
//! state of current constructed command
CmdState _state;
//! last user selection
int _mouseKey, _selPosX, _selPosY;

View File

@ -968,7 +968,7 @@ uint16 Logic::roomRefreshObject(uint16 obj) {
// check the object is in the current room
if (pod->room != _currentRoom) {
debug(0, "Trying to display an object (%i=%s) that is not in room (object room=%i, current room=%i)", obj, _objName[ABS(pod->name)], pod->room, _currentRoom);
debug(0, "Refreshing an object (%i=%s) not in current room (object room=%i, current room=%i)", obj, _objName[ABS(pod->name)], pod->room, _currentRoom);
return curImage;
}
@ -1770,6 +1770,7 @@ void Logic::joeSpeak(uint16 descNum, bool objectType) {
Verb Logic::findVerbUnderCursor(int16 cursorx, int16 cursory) const {
static const Verb pv[] = {
VERB_NONE,
VERB_OPEN,
@ -1802,27 +1803,21 @@ uint16 Logic::findObjectUnderCursor(int16 cursorx, int16 cursory) const {
}
uint16 Logic::findObjectRoomNumber(uint16 zoneNum) const {
uint16 Logic::findObjectNumber(uint16 zoneNum) const {
// l.316-327 select.c
uint16 noun = zoneNum;
uint16 objectMax = _objMax[_currentRoom];
debug(0, "Logic::findObjectRoomNumber(%X, %X)", zoneNum, objectMax);
uint16 obj = zoneNum;
uint16 objectMax = currentRoomObjMax();
debug(9, "Logic::findObjectNumber(%X, %X)", zoneNum, objectMax);
if (zoneNum > objectMax) {
// this is an area box, check for associated object
uint16 obj = currentRoomArea(zoneNum - objectMax)->object;
if (obj != 0 && objectData(obj)->name != 0) {
obj = currentRoomArea(zoneNum - objectMax)->object;
if (obj != 0) {
// there is an object, get its number
noun = obj - _roomData[_currentRoom];
obj -= currentRoomData();
}
}
return noun;
}
uint16 Logic::findObjectGlobalNumber(uint16 zoneNum) const {
return _roomData[_currentRoom] + findObjectRoomNumber(zoneNum);
return obj;
}
@ -2015,8 +2010,11 @@ void Logic::objectCopy(int dummyObjectIndex, int realObjectIndex) {
void Logic::checkPlayer() {
update();
_vm->command()->updatePlayer();
if (!_vm->input()->cutawayRunning()) {
_vm->command()->updatePlayer();
}
}

View File

@ -198,8 +198,7 @@ public:
Verb findVerbUnderCursor(int16 cursorx, int16 cursory) const;
uint16 findObjectUnderCursor(int16 cursorx, int16 cursory) const;
uint16 findObjectRoomNumber(uint16 zoneNum) const;
uint16 findObjectGlobalNumber(uint16 zoneNum) const;
uint16 findObjectNumber(uint16 zoneNum) const;
void inventorySetup();
uint16 findInventoryItem(int invSlot) const;

View File

@ -142,12 +142,12 @@ void QueenEngine::go() {
else {
if (_logic->joeWalk() == JWM_EXECUTE) {
_logic->joeWalk(JWM_NORMAL);
_command->executeCurrentAction(true);
_command->executeCurrentAction();
}
else {
if (_command->parse()) {
_command->clear(true);
}
// if (_command->parse()) {
// _command->clear(true);
// }
_logic->joeWalk(JWM_NORMAL);
_logic->checkPlayer();
}

View File

@ -382,32 +382,7 @@ struct CmdListData {
bool setConditions;
//! graphic image order
int16 imageOrder;
//! special section to execute
/*!
refer to execute.c l.423-451
<table>
<tr>
<td>value</td>
<td>description</td>
</tr>
<tr>
<td>1</td>
<td>use journal</td>
</tr>
<tr>
<td>2</td>
<td>use dress</td>
</tr>
<tr>
<td>3</td>
<td>use normal clothes</td>
</tr>
<tr>
<td>4</td>
<td>use underwear</td>
</tr>
</table>
*/
//! special section to execute (refer to execute.c l.423-451)
int16 specialSection;
void readFrom(byte *&ptr) {

View File

@ -14,14 +14,13 @@ unpack() Graphics::bankUnpack
COMMAND
=======
ALTER_DEFAULT() Command::alterDefault
ALTER_DEFAULT() *not needed* (use State::alterDefaultVerb)
CLEAR_COMMAND() Command::clear
EXECUTE_ACTION() Command::executeCurrentAction
FIND_DEFAULT() Command::findDefault
LOOK() Command::look
LOOK_ICON() Command::lookCurrentIcon
LOOK_ITEM() Command::lookCurrentItem
LOOK_ROOM() Command::lookCurrentRoom
FIND_DEFAULT() *not needed* (use State::findDefaultVerb)
LOOK() Command::lookAtSelectedObject
LOOK_ICON(),LOOK_ITEM() Command::lookForCurrentIcon
LOOK_ROOM() Command::lookForCurrentObject
OPEN_CLOSE_OTHER() Command::openOrCloseAssociatedObject
P1_SET_CONDITIONS() Command::setConditions
P2_SET_AREAS() Command::setAreas
@ -33,9 +32,9 @@ SELECT_NOUN() Command::grabSelectedNoun
SELECT_VERB() Command::grabSelectedVerb
WALK() Command::makeJoeWalkTo
-
ACTION Command::_curCmd.action
ACTION2 Command::_selCmd.action
CLEVEL Command::_curCmd.commandLevel
ACTION Command::_state.action
ACTION2 Command::_state.selAction
CLEVEL Command::_state.commandLevel
COM_A Command::_cmdArea
COM_A_MAX Command::_numCmdArea
COM_O Command::_cmdObject
@ -47,13 +46,13 @@ COM_I_MAX Command::_numCmdInventory
COM_LIST Command::_cmdList
COM_LIST_MAX Command::_numCmdList
COMMANDstr Command::_command
DEFCOMM Command::_selCmd.defaultVerb
DEFCOMM Command::_state.defaultVerb
MKEY Command::_mouseKey
OLDVERB,VERB Command::_curCmd.*verb
OLDNOUN,NOUN Command::_curCmd.*noun
NOUN2 Command::_selCmd.noun
OLDVERB,VERB Command::_state.*verb
OLDNOUN,NOUN Command::_state.*noun
NOUN2 Command::_state.selNoun
PARSE Command::_parse
SUBJ1,SUBJ2,SUBJECT Command::_selCmd.subject*
SUBJ1,SUBJ2 Command::_state.subject*
CREDIT SCRIPTING SYSTEM
@ -497,4 +496,4 @@ OBJMAXv // == Logic::_objMax[Logic::_currentRoom]
TEMPstr
WORDstr
JOE2str,PERSON2str // locals in Talk::initialTalk
SUBJECT