home · contact · privacy
The player is now a map object like any other. All actor contacts now lead to violenc...
[plomrogue] / src / control.c
1 /* control.c */
2
3 #include "control.h"
4 #include <stdint.h> /* for uint8_t */
5 #include "windows.h" /* for cycle_active_win(), shift_active_win(), struct Win,
6                       *  struct WinMeta
7                       */
8 #include "keybindings.h" /* for get_keycode_to_action(), mod_selected_keyb(),
9                           * move_keyb_mod_selection()
10                           */
11 #include "map.h" /* for map_scroll(), map_center_object() */
12 #include "main.h" /* for World struct */
13 #include "rexit.h" /* for exit_err() */
14 #include "wincontrol.h" /* for scroll_pad(), toggle_window(),
15                          * growshrink_active_window(), toggle_winconfig(),
16                          * toggle_win_height_type(), toggle_win_width_type()
17                          */
18 #include "map_object_actions.h" /* for player_wait(), move_player() */
19 #include "command_db.h" /* for is_command_id_shortdsc() */
20 #include "misc.h" /* for load_interface_conf(), unload_interface_conf(),
21                    * save_interface_conf()
22                    */
23 #include "yx_uint16.h" /* for dir enum */
24 #include "map_objects.h" /* for get_player() */
25
26
27
28 extern uint16_t get_available_keycode_to_action(struct World * world,
29                                                 char * name)
30 {
31     uint16_t keycode = get_keycode_to_action(world->kb_global.kbs, name);
32     if (0 != keycode || 0 == world->wmeta->active)
33     {
34         return keycode;
35     }
36     struct WinConf * wc = get_winconf_by_win(world, world->wmeta->active);
37     if (0 == wc->view)
38     {
39         keycode = get_keycode_to_action(wc->kb.kbs, name);
40     }
41     else if (1 == wc->view)
42     {
43         keycode = get_keycode_to_action(world->kb_wingeom.kbs, name);
44     }
45     else if (2 == wc->view)
46     {
47         keycode = get_keycode_to_action(world->kb_winkeys.kbs, name);
48     }
49     return keycode;
50 }
51
52
53
54 extern void record_control(int action, struct World * world)
55 {
56     if      (is_command_id_shortdsc(world, action, "wait"))
57     {
58         player_wait(world);
59     }
60     else if (is_command_id_shortdsc(world, action, "player_u"))
61     {
62         move_player(world, NORTH);
63     }
64     else if (is_command_id_shortdsc(world, action, "player_r"))
65     {
66         move_player(world, EAST);
67     }
68     else if (is_command_id_shortdsc(world, action, "player_d"))
69     {
70         move_player(world, SOUTH);
71     }
72     else if (is_command_id_shortdsc(world, action, "player_l"))
73     {
74         move_player(world, WEST);
75     }
76 }
77
78
79
80 extern uint8_t player_control(int key, struct World * world)
81 {
82     if      (key == get_available_keycode_to_action(world, "player_u"))
83     {
84         move_player(world, NORTH);
85     }
86     else if (key == get_available_keycode_to_action(world, "player_r"))
87     {
88         move_player(world, EAST);
89     }
90     else if (key == get_available_keycode_to_action(world, "player_d"))
91     {
92         move_player(world, SOUTH);
93     }
94     else if (key == get_available_keycode_to_action(world, "player_l"))
95     {
96         move_player(world, WEST);
97     }
98     else if (key == get_available_keycode_to_action(world, "wait"))
99     {
100         player_wait(world);
101     }
102     else
103     {
104         return 0;
105     }
106     return 1;
107 }
108
109
110
111 extern uint8_t wingeom_control(int key, struct World * world)
112 {
113     char * err_shift  = "Trouble with shift_active_win() in wingeom_control().";
114     char * err_resize = "Trouble with growshrink_active_window() in "
115                         "wingeom_control().";
116     if      (key == get_available_keycode_to_action(world, "to_height_t"))
117     {
118         toggle_win_height_type(world, world->wmeta->active);
119     }
120     else if (key == get_available_keycode_to_action(world, "to_width_t"))
121     {
122         toggle_win_width_type(world, world->wmeta->active);
123     }
124     else if (key == get_available_keycode_to_action(world, "grow_h"))
125     {
126         exit_err(growshrink_active_window(world, '*'), world, err_resize);
127     }
128     else if (key == get_available_keycode_to_action(world, "shri_h"))
129     {
130         exit_err(growshrink_active_window(world, '_'), world, err_resize);
131     }
132     else if (key == get_available_keycode_to_action(world, "grow_v"))
133     {
134         exit_err(growshrink_active_window(world, '+'), world, err_resize);
135     }
136     else if (key == get_available_keycode_to_action(world, "shri_v"))
137     {
138         exit_err(growshrink_active_window(world, '-'), world, err_resize);
139     }
140     else if (key == get_available_keycode_to_action(world, "shift_f"))
141     {
142         exit_err(shift_active_win(world->wmeta, 'f'), world, err_shift);
143     }
144     else if (key == get_available_keycode_to_action(world, "shift_b"))
145     {
146         exit_err(shift_active_win(world->wmeta, 'b'), world, err_shift);
147     }
148     else
149     {
150         return 0;
151     }
152     return 1;
153 }
154
155
156
157 extern uint8_t winkeyb_control(int key, struct World * world)
158 {
159     struct WinConf * wc = get_winconf_by_win(world, world->wmeta->active);
160     if      (key == get_available_keycode_to_action(world, "w_keys_u"))
161     {
162         move_keyb_mod_selection(&wc->kb, 'u');
163     }
164     else if (key == get_available_keycode_to_action(world, "w_keys_d"))
165     {
166         move_keyb_mod_selection(&wc->kb, 'd');
167     }
168     else if (key == get_available_keycode_to_action(world, "w_keys_m"))
169     {
170         mod_selected_keyb(world, &wc->kb);
171     }
172     else
173     {
174         return 0;
175     }
176     return 1;
177 }
178
179
180
181 extern uint8_t meta_control(int key, struct World * world)
182 {
183     struct WinMeta * win_meta = world->wmeta;
184     struct Win * win_map      = get_win_by_id(world, 'm');
185     char * err_toggle = "Trouble with toggle_window() in meta_control().";
186     if      (key == get_available_keycode_to_action(world, "quit"))
187     {
188         return 1;
189     }
190     else if (key == get_available_keycode_to_action(world, "winconf"))
191     {
192         toggle_winconfig(world, world->wmeta->active);
193     }
194     else if (key == get_available_keycode_to_action(world, "cyc_win_f"))
195     {
196         cycle_active_win(world->wmeta, 'f');
197     }
198     else if (key == get_available_keycode_to_action(world, "cyc_win_b"))
199     {
200         cycle_active_win(world->wmeta, 'b');
201     }
202     else if (key == get_available_keycode_to_action(world, "scrl_r"))
203     {
204         scroll_pad(win_meta, '+');
205     }
206     else if (key == get_available_keycode_to_action(world, "scrl_l"))
207     {
208         scroll_pad(win_meta, '-');
209     }
210     else if (key == get_available_keycode_to_action(world, "to_a_keywin"))
211     {
212         uint8_t test = toggle_window(win_meta, get_win_by_id(world, 'k'));
213         exit_err(test, world, err_toggle);
214     }
215     else if (key == get_available_keycode_to_action(world, "to_g_keywin"))
216     {
217         uint8_t test = toggle_window(win_meta, get_win_by_id(world, '0'));
218         exit_err(test, world, err_toggle);
219     }
220     else if (key == get_available_keycode_to_action(world, "to_wg_keywin"))
221     {
222         uint8_t test = toggle_window(win_meta, get_win_by_id(world, '1'));
223         exit_err(test, world, err_toggle);
224     }
225     else if (key == get_available_keycode_to_action(world, "to_wk_keywin"))
226     {
227         uint8_t test = toggle_window(win_meta, get_win_by_id(world, '2'));
228         exit_err(test, world, err_toggle);
229     }
230     else if (key == get_available_keycode_to_action(world, "to_mapwin"))
231     {
232         exit_err(toggle_window(win_meta, win_map), world, err_toggle);
233     }
234     else if (key == get_available_keycode_to_action(world, "to_infowin"))
235     {
236         uint8_t test = toggle_window(win_meta, get_win_by_id(world, 'i'));
237         exit_err(test, world, err_toggle);
238     }
239     else if (key == get_available_keycode_to_action(world, "to_inv"))
240     {
241         uint8_t test = toggle_window(win_meta, get_win_by_id(world, 'c'));
242         exit_err(test, world, err_toggle);
243     }
244     else if (key == get_available_keycode_to_action(world, "to_logwin"))
245     {
246         uint8_t test = toggle_window(win_meta, get_win_by_id(world, 'l'));
247         exit_err(test, world, err_toggle);
248     }
249     else if (key == get_available_keycode_to_action(world, "save_conf"))
250     {
251         save_interface_conf(world);
252     }
253     else if (key == get_available_keycode_to_action(world, "g_keys_u"))
254     {
255         move_keyb_mod_selection(&world->kb_global, 'u');
256     }
257     else if (key == get_available_keycode_to_action(world, "g_keys_d"))
258     {
259         move_keyb_mod_selection(&world->kb_global, 'd');
260     }
261     else if (key == get_available_keycode_to_action(world, "g_keys_m"))
262     {
263         mod_selected_keyb(world, &world->kb_global);
264     }
265     else if (key == get_available_keycode_to_action(world, "wg_keys_u"))
266     {
267         move_keyb_mod_selection(&world->kb_wingeom, 'u');
268     }
269     else if (key == get_available_keycode_to_action(world, "wg_keys_d"))
270     {
271         move_keyb_mod_selection(&world->kb_wingeom, 'd');
272     }
273     else if (key == get_available_keycode_to_action(world, "wg_keys_m"))
274     {
275         mod_selected_keyb(world, &world->kb_wingeom);
276     }
277     else if (key == get_available_keycode_to_action(world, "wk_keys_u"))
278     {
279         move_keyb_mod_selection(&world->kb_winkeys, 'u');
280     }
281     else if (key == get_available_keycode_to_action(world, "wk_keys_d"))
282     {
283         move_keyb_mod_selection(&world->kb_winkeys, 'd');
284     }
285     else if (key == get_available_keycode_to_action(world, "wk_keys_m"))
286     {
287         mod_selected_keyb(world, &world->kb_winkeys);
288     }
289     else if (key == get_available_keycode_to_action(world, "map_u"))
290     {
291         map_scroll(world->map, NORTH, win_map->frame.size);
292      }
293     else if (key == get_available_keycode_to_action(world, "map_d"))
294     {
295         map_scroll(world->map, SOUTH, win_map->frame.size);
296     }
297     else if (key == get_available_keycode_to_action(world, "map_r"))
298     {
299         map_scroll(world->map, EAST, win_map->frame.size);
300     }
301     else if (key == get_available_keycode_to_action(world, "map_l"))
302     {
303         map_scroll(world->map, WEST, win_map->frame.size);
304     }
305     else if (key == get_available_keycode_to_action(world, "map_c"))
306     {
307         map_center_object(world->map, get_player(world), win_map->frame.size);
308     }
309     else if (key == get_available_keycode_to_action(world, "reload_conf"))
310     {
311         unload_interface_conf(world);
312         load_interface_conf(world);
313     }
314     else if (key == get_available_keycode_to_action(world, "winconf"))
315     {
316         toggle_winconfig(world, world->wmeta->active);
317     }
318     return 0;
319 }