(fixed) Monster targets oddness

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
kaypy
Artisan
Posts: 171
Joined: Sun Jan 19, 2014 7:11 am

(fixed) Monster targets oddness

Post by kaypy »

Hi

Poking around in the monster targetting code, I found this section
monster_ai@380 wrote:

Code: Select all

local rscans = { }
local numscans = 0
local bpen = 99
local rscan

for tl in pairs(exvar[id].mai_targetlist) do
	local targx = exvar[id].mai_targetlist[tl].x
	local targy = exvar[id].mai_targetlist[tl].y
	local tpdir, trange = linedirfrom(x, y, targx, targy)
	
	if (tpdir) then
		if (trange <= sight) then
			local tscan = scandirection("target_scan", mon_arch, id, tpdir, trange, lev, x, y)
			if (tscan.reach and
					not tscan.immed_no_move and
					not tscan.immed_into_cloud) 
					then
				local pen = dsb_rand(0, 3)
				
				tscan.visible = true
				tscan.indirect = true
                
				if (exvar[id].mai_setdir) then
					if (exvar[id].mai_setdir == dir) then
						pen = 0
					else
						pen = pen + 3
					end
				end
                
				if (tscan.no_move) then pen = pen + 7 end
				if (tscan.door) then pen = pen + 4 end
				if (tscan.mon_group) then pen = pen + 4 end
				if (tscan.cloud) then
					pen = pen + 2
					if (tscan.immed_into_cloud) then
						pen = pen + 5
					end
				end
				if (tpdir ~= face) then pen = pen + 1 end
				if (tpdir == (face+2)%4) then pen = pen + 2 end
						                
				numscans = numscans + 1
				if (pen < bpen) then
					rscan = { pdir = tpdir, scan = tscan,
						range = trange, pen = pen }
				end
                
			end
		end
	end
end
A few oddities:

The code uses the state of tscan.immed_into_cloud ("if (tscan.immed_into_cloud) then pen = pen + 5 end"), but an outer check skips that entire section of code if tscan_immed_into_cloud is set.

The code compares the calculated pen for each target to the bpen value. I am guessing it is looking for the minimum pen value, but the bpen value isn't being reset, so it just winds up being a check against the "this is bigger than any value I expect to ever see"
Friends don't let friends eat worm round
Post Reply