X-Git-Url: https://plomlompom.com/repos/foo.html?a=blobdiff_plain;ds=sidebyside;f=src%2Fclient%2Fmap.c;h=ab8148d25846a9f2594c6ebf0e61f187d7150f7f;hb=c89e7df6e7b6b64037b5b964e10a63ad38f86eb5;hp=48a9b5830de67de3cb60342b8e85277fb6700726;hpb=6b1d36c9e673fd8f8595119080dca63a39ba483b;p=plomrogue
diff --git a/src/client/map.c b/src/client/map.c
index 48a9b58..ab8148d 100644
--- a/src/client/map.c
+++ b/src/client/map.c
@@ -1,47 +1,99 @@
-/* src/client/map.c */
+/* src/client/map.c
+ *
+ * This file is part of PlomRogue. PlomRogue is licensed under the GPL version 3
+ * or any later version. For details on its copyright, license, and warranties,
+ * see the file NOTICE in the root directory of the PlomRogue source package.
+ */
#include "map.h"
#include /* uint8_t */
-#include "windows.h" /* struct Win, center_offset(), get_win_by_id() */
-#include "world.h" /* for global world */
+#include /* free() */
+#include /* sprintf() */
+#include /* strlen(), strncmp() */
+#include "../common/try_malloc.h" /* try_malloc() */
+#include "../common/rexit.h" /* exit_trouble() */
+#include "io.h" /* send() */
+#include "world.h" /* for world */
-extern void map_scroll(char d)
+extern void toggle_lookmode()
{
- struct Win * win = get_win_by_id('m');
- uint8_t offset;
- if (('8' == d || '2' == d) && world.map.size.y > win->frame_size.y)
+ if (!world.look)
{
- offset = center_offset(win->center.y,
- world.map.size.y, win->frame_size.y);
- win->center.y = offset + (win->frame_size.y / 2);
- if ('2' == d && win->center.y < world.map.size.y - 1)
- {
- win->center.y++;
- return;
- }
- win->center.y = win->center.y - ('8' == d && win->center.y > 0);
+ world.look_pos = world.player_pos;
+ world.look = 1;
}
- else if (('4' == d || '6' == d) && (world.map.size.x*2) > win->frame_size.x)
+ else
{
- offset = center_offset(win->center.x,
- world.map.size.x*2, win->frame_size.x);
- win->center.x = offset + (win->frame_size.x / 2);
- if ('6' == d && win->center.x < (world.map.size.x * 2) - 1)
+ world.look = 0;
+ }
+ query_mapcell();
+}
+
+
+
+extern uint8_t lookmode_nav(char * command)
+{
+ char * prefix = "move_";
+ uint8_t len_pref = strlen(prefix);
+ if (!strncmp(prefix, command, len_pref) && strlen(command) - 1 == len_pref)
+ {
+ uint8_t open_north = world.look_pos.y > 0;
+ uint8_t open_south = world.look_pos.y < world.map.length - 1;
+ uint8_t open_west = world.look_pos.x > 0;
+ uint8_t open_east = world.look_pos.x < world.map.length - 1;
+ uint8_t indent = world.look_pos.y % 2;
+ if ('s' == command[len_pref])
+ {
+ world.look_pos.x = world.look_pos.x - open_west;
+ }
+ else if ('d' == command[len_pref])
+ {
+ world.look_pos.x = world.look_pos.x + open_east;
+ }
+ else if ('w' == command[len_pref])
+ {
+ world.look_pos.y = world.look_pos.y - open_north;
+ world.look_pos.x = world.look_pos.x - !indent * open_west;
+ }
+ else if ('e' == command[len_pref])
+ {
+ world.look_pos.y = world.look_pos.y - open_north;
+ world.look_pos.x = world.look_pos.x + indent * open_east;
+ }
+ else if ('x' == command[len_pref])
+ {
+ world.look_pos.y = world.look_pos.y + open_south;
+ world.look_pos.x = world.look_pos.x - !indent * open_west;
+ }
+ else if ('c' == command[len_pref])
+ {
+ world.look_pos.y = world.look_pos.y + open_south;
+ world.look_pos.x = world.look_pos.x + indent * open_east;
+ }
+ else
{
- win->center.x++;
- return;
+ return 0;
}
- win->center.x = win->center.x - ('4' == d && win->center.x > 0);
+ query_mapcell();
+ return 1;
}
+ return 0;
}
-extern void map_center()
+extern void query_mapcell()
{
- struct Win * win_map = get_win_by_id('m');
- win_map->center.y = world.player_pos.y;
- win_map->center.x = world.player_pos.x * 2;
+ free(world.things_here);
+ world.things_here = NULL;
+ char * stack = "THINGS_HERE";
+ char * stack_query = try_malloc(strlen(stack) +1+3 +1+3 +1, __func__);
+ uint8_t y = world.look ? world.look_pos.y : world.player_pos.y;
+ uint8_t x = world.look ? world.look_pos.x : world.player_pos.x;
+ int test = sprintf(stack_query, "%s %d %d", stack, y, x);
+ exit_trouble(test < 0, __func__, "sprintf");
+ send(stack_query);
+ free(stack_query);
}