home · contact · privacy
Rewrote update_log () for a comeback of the message repition compression feature...
[plomrogue] / src / draw_wins.c
index 818037a0b18b92d378bbe9c99b161da87d09be71..0ec8d7a44719edab653f4018266304d0dafeb51f 100644 (file)
@@ -1,11 +1,12 @@
+#include "draw_wins.h"
 #include <stdlib.h>
 #include <stdint.h>
-#include <ncurses.h>
 #include <string.h>
+#include <ncurses.h>
 #include "windows.h"
-#include "draw_wins.h"
 #include "roguelike.h"
 #include "keybindings.h"
+#include "actors.h"
 
 void draw_with_linebreaks (struct Win * win, char * text, uint16_t start_y) {
 // Write text into window content space. Start on row start_y. Fill unused rows with whitespace.
@@ -74,22 +75,24 @@ void draw_map_win (struct Win * win) {
   struct World * world = (struct World *) win->data;
   struct Map * map = world->map;
   struct Player * player = world->player;
-  struct Monster * monster = world->monster;
+  struct Monster * monster;
   char * cells = map->cells;
-  uint16_t width_map_av = map->width - map->offset_x;
-  uint16_t height_map_av = map->height - map->offset_y;
+  uint16_t width_map_av  = map->size.x  - map->offset.x;
+  uint16_t height_map_av = map->size.y - map->offset.y;
   uint16_t x, y, z;
   for (y = 0; y < win->frame.size.y; y++) {
-    z = map->offset_x + (map->offset_y + y) * (map->width);
+    z = map->offset.x + (map->offset.y + y) * (map->size.x);
     for (x = 0; x < win->frame.size.x; x++) {
       if (y < height_map_av && x < width_map_av) {
-        if (z == (map->width * player->y) + player->x)
-          mvwaddch(win->frame.curses_win, y, x, '@');
-        else if (z == (map->width * monster->y) + monster->x)
-          mvwaddch(win->frame.curses_win, y, x, 'M');
-        else
           mvwaddch(win->frame.curses_win, y, x, cells[z]);
-        z++; } } } }
+        z++; } } }
+  if (   player->pos.y >= map->offset.y && player->pos.y < map->offset.y + win->frame.size.y
+      && player->pos.x >= map->offset.x && player->pos.x < map->offset.x + win->frame.size.x)
+    mvwaddch(win->frame.curses_win, player->pos.y - map->offset.y, player->pos.x - map->offset.x, '@');
+  for (monster = world->monster; monster != 0; monster = monster->next)
+    if (   monster->pos.y >= map->offset.y && monster->pos.y < map->offset.y + win->frame.size.y
+        && monster->pos.x >= map->offset.x && monster->pos.x < map->offset.x + win->frame.size.x)
+      mvwaddch(win->frame.curses_win, monster->pos.y - map->offset.y, monster->pos.x - map->offset.x, monster->name); }
 
 void draw_info_win (struct Win * win) {
 // Draw info window by appending win->data integer value to "Turn: " display.