1 /* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 *
21 */
22
23
24 #include "queen/state.h"
25
26 namespace Queen {
27
findDirection(uint16 state)28 Direction State::findDirection(uint16 state) {
29 static const Direction sd[] = {
30 DIR_BACK,
31 DIR_RIGHT,
32 DIR_LEFT,
33 DIR_FRONT
34 };
35 return sd[(state >> 2) & 3];
36 }
37
findTalk(uint16 state)38 StateTalk State::findTalk(uint16 state) {
39 return (state & (1 << 9)) ? STATE_TALK_TALK : STATE_TALK_MUTE;
40 }
41
findGrab(uint16 state)42 StateGrab State::findGrab(uint16 state) {
43 static const StateGrab sg[] = {
44 STATE_GRAB_NONE,
45 STATE_GRAB_DOWN,
46 STATE_GRAB_UP,
47 STATE_GRAB_MID
48 };
49 return sg[state & 3];
50 }
51
findOn(uint16 state)52 StateOn State::findOn(uint16 state) {
53 return (state & (1 << 8)) ? STATE_ON_ON : STATE_ON_OFF;
54 }
55
findDefaultVerb(uint16 state)56 Verb State::findDefaultVerb(uint16 state) {
57 static const Verb sdv[] = {
58 VERB_NONE,
59 VERB_OPEN,
60 VERB_NONE,
61 VERB_CLOSE,
62
63 VERB_NONE,
64 VERB_NONE,
65 VERB_LOOK_AT,
66 VERB_MOVE,
67
68 VERB_GIVE,
69 VERB_TALK_TO,
70 VERB_NONE,
71 VERB_NONE,
72
73 VERB_USE,
74 VERB_NONE,
75 VERB_PICK_UP,
76 VERB_NONE
77 };
78 return sdv[(state >> 4) & 0xF];
79 }
80
findUse(uint16 state)81 StateUse State::findUse(uint16 state) {
82 return (state & (1 << 10)) ? STATE_USE : STATE_USE_ON;
83 }
84
alterOn(uint16 * objState,StateOn state)85 void State::alterOn(uint16 *objState, StateOn state) {
86 switch (state) {
87 case STATE_ON_ON:
88 *objState |= (1 << 8);
89 break;
90 case STATE_ON_OFF:
91 *objState &= ~(1 << 8);
92 break;
93 default:
94 break;
95 }
96 }
97
alterDefaultVerb(uint16 * objState,Verb v)98 void State::alterDefaultVerb(uint16 *objState, Verb v) {
99 uint16 val;
100 switch (v) {
101 case VERB_OPEN:
102 val = 1;
103 break;
104 case VERB_CLOSE:
105 val = 3;
106 break;
107 case VERB_MOVE:
108 val = 7;
109 break;
110 case VERB_GIVE:
111 val = 8;
112 break;
113 case VERB_USE:
114 val = 12;
115 break;
116 case VERB_PICK_UP:
117 val = 14;
118 break;
119 case VERB_TALK_TO:
120 val = 9;
121 break;
122 case VERB_LOOK_AT:
123 val = 6;
124 break;
125 default:
126 val = 0;
127 break;
128 }
129 *objState = (*objState & ~0xF0) | (val << 4);
130 }
131
132 } // End of namespace Queen
133