ok... here is a version that combines like monsters... the code that does this could be made more efficient, but this works so I am happy. (the nested for loop bugs me, but I dont really see a much better solution right now, and it wont make much of a difference in game unless there are *hoards* of monsters, then I dont even want to think about it.)
Code: Select all
require "engine.class"
module(..., package.seeall, class.make)
function _M:init(x, y, w, h, bgcolor)
self.display_x = x
self.display_y = y
self.w, self.h = w, h
self.bgcolor = bgcolor
self.font = core.display.newFont("/data/font/VeraMono.ttf", 14)
self.font_h = self.font:lineSkip()
self.surface = core.display.newSurface(w, h)
end
--- Resize the display area
function _M:resize(x, y, w, h)
self.display_x, self.display_y = x, y
self.w, self.h = w, h
self.surface = core.display.newSurface(w, h)
self.changed = true
end
-- Displays the monsters
function _M:display()
if not game.player or not game.player.changed then return self.surface end
self.surface:erase(self.bgcolor[1], self.bgcolor[2], self.bgcolor[3])
local h = 0
local monsters = {}
local quantity = {}
-- initialize the array
for i, actor in ipairs(game.player.fov.actors_dist) do
monsters[i] = actor.name
quantity[i] = 1
end
-- eliminate duplicates and increase quantity
for i, mon in ipairs(monsters) do
for a, find_mon in ipairs(monsters) do
if find_mon == mon then -- yeah, don't ask, it wouldnt go in with my not in here so I did a dual layer if and an else :/
if a == i then -- bad me (my excuse is that this is my 2nd or 3rd day programming in lua)
else
if quantity[i] then quantity[i] = quantity[i] + 1 end -- only increase if exist
quantity[a] = nil
monsters[a] = nil --this will ensure that I dont show anything I dont want to
end
end
end
end
self.surface:drawString(self.font, "Visible Monsters:", 0, h, 200, 200, 200) h = h + self.font_h
--now to make it work, keep in mind the places of each unique one is IDENTICAL to the place in this array, so calling monsters[i] should work
for i, actor in ipairs(game.player.fov.actors_dist) do
if monsters[i] and quantity[i] == 1 then
self.surface:drawString(self.font, monsters[i], 0, h, actor.color_r, actor.color_g, actor.color_b) h = h + self.font_h
elseif monsters[i] then
self.surface:drawString(self.font, ("%s (x%d)"):format(monsters[i], quantity[i]), 0, h, actor.color_r, actor.color_g, actor.color_b) h = h + self.font_h
end
end
return self.surface
end
now to do a simple fix that will make turn a friendly/neutral/hostile npc's color to light green/blue/hostile (same color as in tactical mode), just use this instead of the last for:
Code: Select all
for i, actor in ipairs(game.player.fov.actors_dist) do
local color = {actor.color_r, actor.color_g, actor.color_b}
if actor.factstate == "friendly" then color={0,255,0} end
if actor.factstate == "neutral" then color={176,196,222} end
if actor.factstate == "hostile" then color={255,0,0} end
if monsters[i] and quantity[i] == 1 then
self.surface:drawString(self.font, monsters[i], 0, h, color[1], color[2], color[3]) h = h + self.font_h
elseif monsters[i] then
self.surface:drawString(self.font, ("%s (x%d)"):format(monsters[i], quantity[i]), 0, h, actor.color_r, actor.color_g, actor.color_b) h = h + self.font_h
end
end
ideally, there would be a keypress to change back and forth between the two.