home · contact · privacy
Added anti-hardcoding todo.
[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_action_key(), save_keybindings(),
9                           * keyswin_move_selection(), keyswin_mod_key()
10                           */
11 #include "map.h" /* for map_scroll(), map_center_player(), dir enum */
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(), reload_win_config()
16                          * toggle_winconfig(), save_win_configs(),
17                          * toggle_win_height_type(), toggle_win_width_type()
18                          */
19 #include "map_object_actions.h" /* for player_wait(), move_player() */
20 #include "command_db.h" /* for is_command_id_shortdsc() */
21
22
23
24 extern void record_control(int action, struct World * world)
25 {
26     if      (is_command_id_shortdsc(world, action, "wait"))
27     {
28         player_wait(world);
29     }
30     else if (is_command_id_shortdsc(world, action, "player_u"))
31     {
32         move_player(world, NORTH);
33     }
34     else if (is_command_id_shortdsc(world, action, "player_r"))
35     {
36         move_player(world, EAST);
37     }
38     else if (is_command_id_shortdsc(world, action, "player_d"))
39     {
40         move_player(world, SOUTH);
41     }
42     else if (is_command_id_shortdsc(world, action, "player_l"))
43     {
44         move_player(world, WEST);
45     }
46 }
47
48
49
50 extern uint8_t player_control(int key, struct World * world)
51 {
52     if      (key == get_action_key(world->keybindings, "player_u"))
53     {
54         move_player(world, NORTH);
55     }
56     else if (key == get_action_key(world->keybindings, "player_r"))
57     {
58         move_player(world, EAST);
59     }
60     else if (key == get_action_key(world->keybindings, "player_d"))
61     {
62         move_player(world, SOUTH);
63     }
64     else if (key == get_action_key(world->keybindings, "player_l"))
65     {
66         move_player(world, WEST);
67     }
68     else if (key == get_action_key(world->keybindings, "wait"))
69     {
70         player_wait(world);
71     }
72     else
73     {
74         return 1;
75     }
76     return 0;
77 }
78
79
80
81 extern uint8_t meta_control(int key, struct World * world)
82 {
83     struct WinMeta * win_meta = world->wmeta;
84     struct Win * win_keys     = get_win_by_id(world, 'k'); /* Bad hardcoding. */
85     struct Win * win_map      = get_win_by_id(world, 'm'); /* TODO: Replace.  */
86     struct Win * win_info     = get_win_by_id(world, 'i'); /*                 */
87     struct Win * win_log      = get_win_by_id(world, 'l'); /*                 */
88     char * err_toggle = "Trouble with toggle_window() in meta_keys().";
89     char * err_shift  = "Trouble with shift_active_win() in meta_keys().";
90     char * err_resize = "Trouble with growshrink_active_window() in "
91                         "meta_keys().";
92     if (key == get_action_key(world->keybindings, "quit"))
93     {
94         return 1;
95     }
96     else if (key == get_action_key(world->keybindings, "scrl_r"))
97     {
98         scroll_pad(win_meta, '+');
99     }
100     else if (key == get_action_key(world->keybindings, "scrl_l"))
101     {
102         scroll_pad(win_meta, '-');
103     }
104     else if (key == get_action_key(world->keybindings, "to_keywin"))
105     {
106         exit_err(toggle_window(win_meta, win_keys), world, err_toggle);
107     }
108     else if (key == get_action_key(world->keybindings, "to_mapwin"))
109     {
110         exit_err(toggle_window(win_meta, win_map), world, err_toggle);
111     }
112     else if (key == get_action_key(world->keybindings, "to_infowin"))
113     {
114         exit_err(toggle_window(win_meta, win_info), world, err_toggle);
115     }
116     else if (key == get_action_key(world->keybindings, "to_logwin"))
117     {
118         exit_err(toggle_window(win_meta, win_log), world, err_toggle);
119     }
120     else if (key == get_action_key(world->keybindings, "cyc_win_f"))
121     {
122         cycle_active_win(win_meta, 'f');
123     }
124     else if (key == get_action_key(world->keybindings, "cyc_win_b"))
125     {
126         cycle_active_win(win_meta, 'b');
127     }
128     else if (key == get_action_key(world->keybindings, "shift_f"))
129     {
130         exit_err(shift_active_win(win_meta, 'f'), world, err_shift);
131     }
132     else if (key == get_action_key(world->keybindings, "shift_b"))
133     {
134         exit_err(shift_active_win(win_meta, 'b'), world, err_shift);
135     }
136     else if (key == get_action_key(world->keybindings, "grow_h"))
137     {
138         exit_err(growshrink_active_window(world, '*'), world, err_resize);
139     }
140     else if (key == get_action_key(world->keybindings, "shri_h"))
141     {
142         exit_err(growshrink_active_window(world, '_'), world, err_resize);
143     }
144     else if (key == get_action_key(world->keybindings, "grow_v"))
145     {
146         exit_err(growshrink_active_window(world, '+'), world, err_resize);
147     }
148     else if (key == get_action_key(world->keybindings, "shri_v"))
149     {
150         exit_err(growshrink_active_window(world, '-'), world, err_resize);
151     }
152     else if (key == get_action_key(world->keybindings, "save_keys"))
153     {
154         save_keybindings(world);
155     }
156     else if (key == get_action_key(world->keybindings, "keys_u"))
157     {
158         keyswin_move_selection(world, 'u');
159     }
160     else if (key == get_action_key(world->keybindings, "keys_d"))
161     {
162         keyswin_move_selection(world, 'd');
163     }
164     else if (key == get_action_key(world->keybindings, "keys_m"))
165     {
166         keyswin_mod_key(world, win_meta);
167     }
168     else if (key == get_action_key(world->keybindings, "map_u"))
169     {
170         map_scroll(world->map, NORTH, win_map->frame.size);
171      }
172     else if (key == get_action_key(world->keybindings, "map_d"))
173     {
174         map_scroll(world->map, SOUTH, win_map->frame.size);
175     }
176     else if (key == get_action_key(world->keybindings, "map_r"))
177     {
178         map_scroll(world->map, EAST, win_map->frame.size);
179     }
180     else if (key == get_action_key(world->keybindings, "map_l"))
181     {
182         map_scroll(world->map, WEST, win_map->frame.size);
183     }
184     else if (key == get_action_key(world->keybindings, "map_c"))
185     {
186         map_center_player(world->map, world->player, win_map->frame.size);
187     }
188     else if (key == get_action_key(world->keybindings, "reload_wins"))
189     {
190         reload_win_config(world);
191     }
192     else if (key == get_action_key(world->keybindings, "winconf"))
193     {
194         toggle_winconfig(world, world->wmeta->active);
195     }
196     else if (key == get_action_key(world->keybindings, "to_height_t"))
197     {
198         toggle_win_height_type(world, world->wmeta->active);
199     }
200     else if (key == get_action_key(world->keybindings, "to_width_t"))
201     {
202         toggle_win_width_type(world, world->wmeta->active);
203     }
204     else if (key == get_action_key(world->keybindings, "save_winconf"))
205     {
206         save_win_configs(world);
207     }
208     return 0;
209 }