DSB - how to check for walls? (making a new item)

This forum is for the Lua scriptable clone of DM/CSB called Dungeon Strikes Back by Sophia. Use DSB to build your own highly customised games.

Moderator: Sophia

Forum rules
Please read the Forum rules and policies before posting.
Post Reply
User avatar
boyflea
Expert
Posts: 321
Joined: Mon Nov 20, 2006 3:23 pm
Location: Southampton, UK
Contact:

DSB - how to check for walls? (making a new item)

Post by boyflea »

Hi, don;t ask me why but suddenly I find myself looking at DSB. It looks really powerful and cool, but unlike RTC all the functions and graphics require a bit of a rummage around to find. No problem.

Sophia has put up with me long enough and I'll post this question publically: I am a noob, so bear with.

Q: How do I make a Grappling hook using DSB?
Hey, before I post, I just found where all the methods are kept... [reads]

ok:

this is what I have: [don't cringe, this is a brute-force method of stealing other people's code, sorry]

objects.lua:

Code: Select all

obj.grappling_hook = {
    name="GRAPPLE",
    type="THING",
    class="MISC",
    mass=8,
    icon=gfx.icons[128],
    dungeon=gfx.rope,
	methods = {
		{ "CLIMB UP", 0, CLASS_NINJA, method_climbup }
		{ "CLIMB DOWN", 0, CLASS_NINJA, method_climbdown }
	}, 
    fit_pouch = true,
    fit_sheath = true
}
(NB: where can I check the gfx.icon? I want the one used for rope, so the one used here is just a guess...)

methods.lua:

Code: Select all

function method_climbup(name, ppos, who, what)
	local idle_set = false
	
	local m = lookup_method_info(name, what)
	if (not m) then return end
	
	local lev, xc, yc, face = dsb_party_coords()
	local dx, dy = dsb_forward(face)
	--xc = xc + dx
	--yc = yc + dy
	lev = lev - 1
	
	local got_pit = dsb_fetch(lev, xc, yc, CENTER)
	if (got_pit) then
		local blocked = false
	    for d=0,4 do
	    	local got_monster = search_for_type(lev, (xc + dx), (yc + dy), d, "MONSTER")
	    	if (got_monster) then
				blocked = true
				break
			end
		end
		if (not blocked) then
			for i in pairs(got_pit) do
				local v = got_pit[i]
				local arch = dsb_find_arch(v)
				if (arch.class == "PIT") then
				    if (not dsb_get_gfxflag(v, GF_INACTIVE)) then
						burn_stamina(who, m.stamina_used)
						att_idle(ppos, m.idleness)
						idle_set = true
						-- Giving the experience here is my tweak. Original DM
						-- gives xp even if there is no pit. I don't like that.
						xp_up(who, m.xp_class, m.xp_sub, m.xp_get)
						gt_rope_use = true
						dsb_party_place(lev, (xc + dx), (yc + dy), face)
					end
				end
			end
		end
	end
	
	if (not idle_set) then
		att_idle(ppos, m.idleness / 2)
	end		
end
And it works! ish
but.

I need to add to the monster block a check for walls:

is it something to do with -
dsb_fetch(level, x, y, tile_location)

???

cheers for any pointers on this, thanks.
The stonework walls? Pristine. The floor? Level. The waterworks? Flowing. Central heating? The Dragon in the basement was grumpily heating the pipes. Lord Chaos consulted the blueprints again, looking for the bathroom. #playmygame!
User avatar
Sophia
Concise and Honest
Posts: 4239
Joined: Thu Sep 12, 2002 9:50 pm
Location: Nowhere in particular
Contact:

Re: DSB - how to check for walls? (making a new item)

Post by Sophia »

A more elegant way of copying an object you want to use is clone_arch. This leaves everything unchanged except for the table specified. For example:

Code: Select all

obj.grappling_hook = clone_arch(obj.rope, {
   name = "GRAPPLE",
   methods = {
      { "CLIMB UP", 0, CLASS_NINJA, method_climbup }
      { "CLIMB DOWN", 0, CLASS_NINJA, method_climbdown }
   },
})
Anyway, checking for walls is accomplished with dsb_get_cell(level, x, y)
It returns true if the cell is a wall and false if the cell is not.

In addition to a check for walls, you're need to change looking for a ceiling pit, so don't forget to change the arch.class you're looking for from "PIT" to "PIT_CEIL". Another potential issue to worry about is that a climb up is a little more complicated because you'll need to check for monsters both at the destination square but also on top of the pit directly.

Finally, I'll mention that I rewrote method_climbdown for DSB 0.65, which I haven't finished yet. There are no significant differences stopping you from using the version you have, but if you're copying the code and want to start from the most current version of method_climbdown then download this file, rename it to methods.lua, and replace DSB's default base/methods.lua with the one you just downloaded. (This is not something that normally happens, don't worry...)
User avatar
Gambit37
Should eat more pies
Posts: 13714
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Re: DSB - how to check for walls? (making a new item)

Post by Gambit37 »

@boyflea, don't forget to check out the Wiki too; it's incomplete but already contains tons of useful info:
http://dmwiki.atomas.com/wiki/DSB
User avatar
boyflea
Expert
Posts: 321
Joined: Mon Nov 20, 2006 3:23 pm
Location: Southampton, UK
Contact:

Re: DSB - how to check for walls? (making a new item)

Post by boyflea »

Thanks for this - though having changed several parts to this equation at once has now forced me to re-write this function from scratch :)
Ok, let me try again. :)

so time to rethink approach:
CHECKS
- establish there is a pit ceiling above me
- offset target destination check up one level
- check if there is a monster flying above pit (if found, notify user via text alert)
- then offset destination to check against to x, y + FACE modifier
- on this target location, check for wall (if found, notify user via text alert)
- on this target location , check for beast (if found, notify user via text alert)
- if target space is empty, then move team to target location
SUCCESS
- modify experinece & stamina accordingly
The stonework walls? Pristine. The floor? Level. The waterworks? Flowing. Central heating? The Dragon in the basement was grumpily heating the pipes. Lord Chaos consulted the blueprints again, looking for the bathroom. #playmygame!
Post Reply