Page 1 of 1

Furniture

Posted: Sat Oct 09, 2010 10:46 pm
by Lap
I've been thinking about how to best represent furniture. Having movable, breakable furniture seems like it needs an entirely new class. I'm thinking I'll have to do something like:

--- The place of a terrain entity in a map grid
TERRAIN = 1
--- The place of a terrain entity in a map grid
TRAP = 50
FURNITURE = 75
--- The place of an actor entity in a map grid
ACTOR = 100
--- The place of a projectile entity in a map grid
PROJECTILE = 500
--- The place of an object entity in a map grid
OBJECT = 1000

and trying to find all the other places where a new class would go. I'm not actually seeing the code for telling the engine to draw this new class of entities. Is it even possible? Should I be trying to represent furniture this way?

Re: Furniture

Posted: Sat Oct 09, 2010 10:53 pm
by darkgod
Well you can add lets say, things taht are not of an Object class inside the OBJECT slot, each map slot can contain any kind of Entity, as long as your code knows how to handle it.

As for additing a new kind of slot, I have plans for it but did not need to do it yet, if you require it I'll work on that, msot of the support already exist it just needs some magic to make updateMap() understand it

Re: Furniture

Posted: Sat Oct 09, 2010 10:59 pm
by Lap
I currently have furniture as objects and it's not difficult to have them be able to block moves, be moved, broken, etc., but when it comes to drawing the actual furniture it doesn't seem to be working well. Having it inside the object layer means that it might not get drawn at all if other objects are there and it also means that objects on top of the furniture won't get drawn.

The engine only draws one object per tile even if there are 100 of them there correct?

Re: Furniture

Posted: Sat Oct 09, 2010 11:01 pm
by darkgod
Yup, but taht's what I'm talking about: being able to tell the engine what to draw

Re: Furniture

Posted: Sat Oct 09, 2010 11:09 pm
by Lap
If the required code is already a semi planned feature should I just wait for later versions of the engine to continue working on furniture?

This also reminds me of a feature request that could be generally useful. When more than one object is in the same tile the engine runs a mod definable function. A mod can choose to then:

-do nothing
-display an alternate image file (a generic pile of crap, or more specifically check for an image that approximates what types of objects are there)
-displays some sort of visual alteration of the image file to let the player know there is more there.
-display another image file on top of the current image file (maybe a plus sign in the top right of the tile).

Re: Furniture

Posted: Sat Oct 09, 2010 11:31 pm
by darkgod
My change should let you do that :)

Currently for next beta a pile of objects will be notified though with small numbers in the corner

Re: Furniture

Posted: Sun Oct 10, 2010 12:43 am
by Lap
Thanks for all these new features. My mappers get quite cranky when I tell them something is currently an engine limitation. Plenty of other stuff to code until next beta.

Re: Furniture

Posted: Mon Oct 11, 2010 10:23 pm
by darkgod
In next beta you can have a file hat is loaded by load.lua (like "dofile('/mod/map_config.lua')" ) that will define how the map is displayed.

This is quite raw as it exports a part of the map code but this is the most flexible.

This is how the default code works: There are 18 "layers" of display (this is configurable by setting Map.zdepth = 18, which is the default) and each of the entities can use 3 layers, plus the 2 last ones as additonnal stuff (like the trees in ToME so that the player walks under it).
THis is obviously totaly module specific you could have only one display layer if you wanted an old school bare ASCII style

Code: Select all

local Map = require "engine.Map"

Map.updateMapDisplay = function(self, x, y, mos)
	local mm = Map.MM_FLOOR
	local g = self(x, y, Map.TERRAIN)
	local o = self(x, y, Map.OBJECT)
	local a = self(x, y, Map.ACTOR)
	local t = self(x, y, Map.TRAP)
	local p = self(x, y, Map.PROJECTILE)

	if g then
		-- Update path caches from path strings
		for i = 1, #self.path_strings do
			local ps = self.path_strings[i]
			self._fovcache.path_caches[ps]:set(x, y, g:check("block_move", x, y, ps, false, true))
		end

		mm = mm + (g:check("block_move") and Map.MM_BLOCK or 0)
		mm = mm + (g:check("change_level") and Map.MM_LEVEL_CHANGE or 0)
		g:getMapObjects(self.tiles, mos, 1)
	end
	if t then
		-- Handles trap being known
		if not self.actor_player or t:knownBy(self.actor_player) then
			t:getMapObjects(self.tiles, mos, 4)
			mm = mm + Map.MM_TRAP
		else
			t = nil
		end
	end
	if o then
		o:getMapObjects(self.tiles, mos, 7)
		if self.object_stack_count then
			local mo = o:getMapStackMO(self, x, y)
			if mo then mos[9] = mo end
		end
		mm = mm + Map.MM_OBJECT
	end
	if a then
		-- Handles invisibility and telepathy and other such things
		if not self.actor_player or self.actor_player:canSee(a) then
			local r = self.actor_player:reactionToward(a)
			mm = mm + (r > 0 and Map.MM_FRIEND or (r == 0 and Map.MM_NEUTRAL or Map.MM_HOSTILE))
			a:getMapObjects(self.tiles, mos, 10)
		end
	end
	if p then
		p:getMapObjects(self.tiles, mos, 13)
	end
	return mm
end