home · contact · privacy
Moved key mod process into its own function for the reason defined in the previous...
[plomrogue] / roguelike.c
index 8a358f3d6c6e92926831e86e0af1353d1e24126c..8e7cae124fe62199842f53cf72d5b0759a28dfe9 100644 (file)
@@ -51,8 +51,10 @@ void update_log (struct World *, char *);
 void save_keybindings(struct World *);
 int get_action_key (struct KeyBinding *, char *);
 char * get_keyname(int);
+void mod_key (struct World *, struct WinMeta *);
 char is_passable (struct World *, int, int);
 void move_player (struct World *, char);
+void player_wait(struct World *);
 
 void draw_with_linebreaks (struct Win * win, char * text, int start_y) {
 // Write text into window content space. Start on row start_y. Fill unused rows with whitespace.
@@ -346,6 +348,15 @@ char * get_keyname(int keycode) {
     sprintf(keyname, "(unknown)");
   return keyname;  }
 
+void mod_key (struct World * world, struct WinMeta * win_meta) {
+// In keybinding window, mark selection modifiable, modify key. Ensure max of three digits in key code field.
+  world->keyswindata->edit = 1;
+  draw_all_windows (win_meta);
+  int key = getch();
+  if (key < 1000)
+    world->keybindings[world->keyswindata->select].key = key;
+  world->keyswindata->edit = 0; }
+
 char is_passable (struct World * world, int x, int y) {
 // Check if coordinate on (or beyond) map is accessible to movement.
   char passable = 0;
@@ -395,6 +406,11 @@ void move_player (struct World * world, char d) {
   prev = success * d;
   next_turn (world); }
 
+void player_wait(struct World * world) {
+// Make player wait one turn.
+  next_turn (world);
+  update_log (world, "\nYou wait."); }
+
 int main () {
   struct World world;
   init_keybindings(&world);
@@ -472,13 +488,8 @@ int main () {
       world.keyswindata->select--;
     else if (key == get_action_key(world.keybindings, "keys nav down") && world.keyswindata->select < world.keyswindata->max)
       world.keyswindata->select++;
-    else if (key == get_action_key(world.keybindings, "keys mod")) {
-      world.keyswindata->edit = 1;
-      draw_all_windows (&win_meta);
-      key = getch();
-      if (key < 1000) // ensure maximum of three digits in key code field
-        world.keybindings[world.keyswindata->select].key = key;
-      world.keyswindata->edit = 0; }
+    else if (key == get_action_key(world.keybindings, "keys mod"))
+      mod_key (&world, &win_meta);
     else if (key == get_action_key(world.keybindings, "map up") && map.offset_y > 0)
       map.offset_y--;
     else if (key == get_action_key(world.keybindings, "map down"))
@@ -495,9 +506,8 @@ int main () {
       move_player(&world, 'e');
     else if (key == get_action_key(world.keybindings, "player left"))
       move_player(&world, 'w');
-    else if (key == get_action_key(world.keybindings, "wait") ) {
-      next_turn (&world);
-      update_log (&world, "\nYou wait."); } }
+    else if (key == get_action_key(world.keybindings, "wait") )
+      player_wait (&world); }
 
   free(map.cells);
   for (key = 0; key <= world.keyswindata->max; key++)