add wraparound support to C2 physics
[openc2e.git] / caosVM_input.cpp
blob6543cbe5d653696b300ddaae7dadbc73179deb50
1 /*
2 * caosVM_input.cpp
3 * openc2e
5 * Created by Alyssa Milburn on 28/07/2004.
6 * Copyright 2004 Alyssa Milburn. All rights reserved.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
20 #include "World.h"
21 #include "Engine.h"
22 #include "PointerAgent.h"
23 #include "Backend.h"
24 #include "caosVM.h"
25 #include <iostream>
26 using std::cerr;
28 /**
29 CLAC (command) message (integer)
30 %status maybe
32 Sets the type of message sent to the TARG agent when clicked. If set to -1, no message
33 will be sent. Using this command will override and reset the value set with CLIK.
35 void caosVM::c_CLAC() {
36 VM_VERIFY_SIZE(1)
37 VM_PARAM_INTEGER(message)
39 valid_agent(targ);
41 targ->clac[0] = message;
42 targ->clik = -1;
45 /**
46 CLAC (integer)
47 %status maybe
49 void caosVM::v_CLAC() {
50 valid_agent(targ);
52 if (targ->clik != -1)
53 result.setInt(targ->clac[0]);
54 else
55 result.setInt(-2);
58 /**
59 CLIK (command) msg1 (integer) msg2 (integer) msg3 (integer)
60 %status maybe
62 Sets three different message types that will sent to the TARG agent when clicked, on a
63 rotating basis. Setting any of the three types to -1 will cause it to be ignored. Using
64 this command will override and reset the value set by CLAC.
66 void caosVM::c_CLIK() {
67 VM_VERIFY_SIZE(3)
68 VM_PARAM_INTEGER(msg3)
69 VM_PARAM_INTEGER(msg2)
70 VM_PARAM_INTEGER(msg1)
72 valid_agent(targ);
74 targ->clac[0] = msg1;
75 targ->clac[1] = msg2;
76 targ->clac[2] = msg3;
77 targ->clik = 0;
80 /**
81 CLIK (integer) data (integer)
82 %status maybe
84 void caosVM::v_CLIK() {
85 VM_PARAM_INTEGER(data)
87 valid_agent(targ);
89 if (targ->clik == -1)
90 result.setInt(-2);
91 else switch (data) {
92 case 0: result.setInt(targ->clik); break;
93 case 1: result.setInt(targ->clac[0]); break;
94 case 2: result.setInt(targ->clac[1]); break;
95 case 3: result.setInt(targ->clac[2]); break;
99 /**
100 IMSK (command) flags (integer)
101 %status stub
103 Sets the input event flags for the target agent, which tell the engine which events the
104 agent requires scripts to be fired for. For example, setting the "key up" flag means the
105 target agent has the relevant script executed every time a key is released.
107 Add the following values together to calculate the flags parameter: 1 for key down, 2 for key up, 4 for mouse move, 8 for mouse down, 16 for mouse up, 32 for mouse wheel movement and 64 for (translated) keypress.
109 TODO: link to the script details (event numbers and parameters).
111 void caosVM::c_IMSK() {
112 VM_PARAM_INTEGER(flags)
114 valid_agent(targ);
115 targ->imsk_key_down = (flags & 1);
116 targ->imsk_key_up = (flags & 2);
117 targ->imsk_mouse_move = (flags & 4);
118 targ->imsk_mouse_down = (flags & 8);
119 targ->imsk_mouse_up = (flags & 16);
120 targ->imsk_mouse_wheel = (flags & 32);
121 targ->imsk_translated_char = (flags & 64);
122 // TODO
126 IMSK (integer)
127 %status stub
129 Returns the input event flags for the target agent. See the IMSK command for details.
131 void caosVM::v_IMSK() {
132 valid_agent(targ);
133 result.setInt(0); // TODO
137 KEYD (integer) keycode (integer)
138 %status maybe
140 Returns 1 if the specified key is held down, or 0 otherwise.
142 void caosVM::v_KEYD() {
143 VM_PARAM_INTEGER(keycode) // keycodes are crazy broken windows things
145 if (engine.backend->keyDown(keycode))
146 result.setInt(1);
147 else
148 result.setInt(0);
152 HOTS (agent)
153 %status maybe
154 %pragma variants all
156 Returns the agent that is currently underneath the Hand.
157 NB: this command is not a real c1/c2 command, backported for convenience
159 void caosVM::v_HOTS() {
160 Agent *a = world.agentAt(world.hand()->pointerX(), world.hand()->pointerY()); // TODO: use hotspot
162 result.setAgent(a);
166 HOTP (integer)
167 %status maybe
169 Returns the PART of the agent (given by HOTS) that is currently underneath the Hand.
171 Transparency of the parts themselves is ignored.
173 void caosVM::v_HOTP() {
174 CompoundPart *a = world.partAt(world.hand()->pointerX(), world.hand()->pointerY(), false);
175 if (a)
176 result.setInt(a->id);
177 else
178 result.setInt(-1);
182 PURE (command) value (integer)
183 %status maybe
185 Turns the normal pointing and clicking behavior of the Hand on (0) and off (1).
187 If set to off, CLIK and CLAC will not work, and clicking events must be handled by IMSK.
189 void caosVM::c_PURE() {
190 VM_PARAM_INTEGER(value)
192 world.hand()->handle_events = !value;
196 PURE (integer)
197 %status maybe
199 Returns whether the normal pointing and clicking behavior of the Hand is on or off.
201 void caosVM::v_PURE() {
202 // TODO: alex claims PURE is inverse behaviour for the command, is this true for this function too? (assuming it is for now)
203 if (world.hand()->handle_events)
204 result.setInt(0);
205 else
206 result.setInt(1);
210 MOPX (integer)
211 %status maybe
213 Returns the current X coordinate of the Hand in the world.
215 void caosVM::v_MOPX() {
216 result.setInt((int)world.hand()->pointerX());
220 MOPY (integer)
221 %status maybe
223 Returns the current Y coordinate of the Hand in the world.
225 void caosVM::v_MOPY() {
226 result.setInt((int)world.hand()->pointerY());
230 SCOL (integer) andmask (integer) eormask (integer) upspeeds (bytestring) downspeeds (bytestring)
231 %status stub
233 void caosVM::v_SCOL() {
234 VM_PARAM_BYTESTR(downspeeds)
235 VM_PARAM_BYTESTR(upspeeds)
236 VM_PARAM_INTEGER(eormask)
237 VM_PARAM_INTEGER(andmask)
239 result.setInt(0); // TODO
243 SCRL (command) enable (integer)
244 %status stub
246 Turns on (1) or off (0) keyboard/mouse scrolling.
248 void caosVM::c_SCRL() {
249 VM_PARAM_INTEGER(enable)
251 // TODO
255 MOUS (command) behaviour (integer)
256 %status stub
258 void caosVM::c_MOUS() {
259 VM_PARAM_INTEGER(behaviour)
261 // TODO
264 /* vim: set noet: */