Page 1 of 1

quick question

Posted: Sat Feb 04, 2012 8:24 pm
by marchewka
Repeating the question from Vault theme in Ideas thread - I'd be much obliged if someone provided me with 1 line examples of the following, needed for creation of new vaults:

1# How to create floor tile that contains item OR monster OR trap?

2# Similarly - how to create a tile that produces an item with some % chance?

3# How to create newEntity that does something randomly (say, swaps between two possible shadersr with 1/4 chance each game turn)

Re: quick question

Posted: Sun Feb 05, 2012 2:35 am
by Sharzyl
#1 and #2, you may want to check the Last Hope graveyard.
If you open a coffin, there's a chance to get treasure or monster.
If you want a tile, you want to check alarm trap that can summon enemy units, it's pretty common in Assassin Lord's hideout.

Not really understand about #3.

Re: quick question

Posted: Sun Feb 05, 2012 11:22 am
by marchewka
Thx for the answer. Checking the first two in the code. Regarding #3 - say i want to make a floor with shifting shadows, a tile that has 1/4 chance each round to have darkness effect applied to it or removed.

Re: quick question

Posted: Sun Feb 05, 2012 2:56 pm
by yufra
marchewka wrote:Thx for the answer. Checking the first two in the code. Regarding #3 - say i want to make a floor with shifting shadows, a tile that has 1/4 chance each round to have darkness effect applied to it or removed.
You will want to make the newEntity have an act function, which will then be called each game turn. Try looking at the infamous collapsing sand walls in ToME which can be found in `tome/data/general/grids/sand.lua`. This is the specific section:

Code: Select all

		local sand = require("engine.Object").new{
			name = "unstable sand tunnel", image = "terrain/sand.png",
			display = '.', color={r=203,g=189,b=72}, back_color={r=93,g=79,b=22},
			canAct = false,
			act = function(self)
				self:useEnergy()
				self.temporary = self.temporary - 1
				if self.temporary <= 0 then
					game.level.map(self.x, self.y, engine.Map.TERRAIN, self.old_feat)
					game.level:removeEntity(self)
					game.logSeen(self, "The unstable sand tunnel collapses!")
					game.nicer_tiles:updateAround(game.level, self.x, self.y)

					local a = game.level.map(self.x, self.y, engine.Map.ACTOR)
					if a then
						game.logPlayer(a, "You are crushed by the collapsing tunnel! You suffocate!")
						a:suffocate(30, self, "was buried alive")
						engine.DamageType:get(engine.DamageType.PHYSICAL).projector(self, self.x, self.y, engine.DamageType.PHYSICAL, a.life / 2)
					end
				end
			end,
			tunneler_dig = 1,
			dig = function(src, x, y, old)
				old.temporary = 20
				return nil, old, true
			end,
		}
Note that this is not an `engine.Grid` instance, but an `engine.Object` instance.