minetest-game-adventuretest/NOTES.md

4.3 KiB

migration to mt 5.0/5.2

There are the issues Tignasse Verte mentionned: Adding placer in register_functions.lua (related commit for minenux are commit a996d5ac709446322d6c6261c21e5f0752a6aeeb ) and replacing the two occourances of nodeupdate with minetest.check_for_falling. (relatd commit for minenux are commit 8c53cabfce2d079df76e57b27b020e016837e8fc )

Other changes are necessary because I changed (and had to change) quite a lot in mg_villages internally recently. If you want to get further with running the game under newer versions of MT, replace the versions of cottages, handle_schematics and mg_villages AdventureTest comes with with the newest versions.

Then, remove the line mg_villages.on_generated(minp,maxp,seed) in adventuretest/register_functions.lua. This may have an impact on quests the old explorer is handling out, but if you ignore these for now, the world ought to be usable.

Comment out the file/content of mg/fill_chests.lua for now as that requires a few adjustments for filling the chests with the right content, and that's a bit too much to write here in an inconvenient forum post.

You won't see any villagers spawning because their spawn blocks are not placed. My first attempts there ended in a severe overcrowding of villagers. Needs finetuning/understanding what BrandonReese did to keep it balanced. But then, this seems to be an open issue on Github as well...

Mobs will likely not work very well. A lot changed regarding them. They certainly could use an update as well - as could the goblins. I'm sure the witches from the same modder would feel welcome in the AdventureTest universe, too.

Fiel of view for monsters vs characters

From https://forum.minetest.net/viewtopic.php?p=182737#p182737

If it helps any, here is the in_fov code from mobs redo mod that works (self is mob, pos is player position and self.fov is set to 90, self.rotate is usually 0 for front facing mobs): CODE: SELECT ALL

in_fov = function(self,pos)
	-- checks if POS is in self's FOV
	local yaw = self.object:getyaw() + self.rotate
	local vx = math.sin(yaw)
	local vz = math.cos(yaw)
	local ds = math.sqrt(vx^2 + vz^2)
	local ps = math.sqrt(pos.x^2 + pos.z^2)
	local d = { x = vx / ds, z = vz / ds }
	local p = { x = pos.x / ps, z = pos.z / ps }
	local an = ( d.x * p.x ) + ( d.z * p.z )

	a = math.deg( math.acos( an ) )

Thank you everyone, especially TeTpaAka and Nore. All problems were at last solved, and the code now reports the angle difference between entities like it should! You get 0* when standing right in front of the mob, 90* when standing parallel to either side, 180* when standing behind... whereas flying up or down now accounts pitch correctly on top of that.

Here is the final and fully functional version. I hope it will be helpful to more people than just me, if anyone ever needs a simple and efficient FOV scanner for Minetest.

local function in_fov (pos1, pos2, yaw, pitch, fov)
	local function yaw2vec (yaw, pitch)
		-- we must invert the yaw for x to keep the result from inverting when facing opposite directions (0* becoming 180*)
		return {x = math.sin(-yaw) * math.cos(pitch), y = math.sin(pitch), z = math.cos(yaw) * math.cos(pitch)}
	end

	local function dotproduct (v1, v2)
		return ((v1.x * v2.x) + (v1.y * v2.y) + (v1.z * v2.z))
	end

	local function angle (v1, v2)
		return math.deg(math.acos(dotproduct(v1, v2) / (vector.length(v1) * vector.length(v2))))
	end

	local v = vector.subtract(pos2, pos1)
	print(angle(yaw2vec(yaw, pitch), v))
end

here is the final version of the function which I'll be including in my mod, simplified to only 5 lines of code but with the same result: CODE: SELECT ALL

-- returns the angle difference between pos1 and pos2, as seen from pos1 at the specified yaw and pitch
function pos_to_angle (pos1, pos2, yaw, pitch)
	-- note: we must invert the yaw for x in yaw_vec, to keep the result from inverting when facing opposite directions (0* becoming 180*)
	local yaw_vec = {x = -math.sin(yaw) * math.cos(pitch), y = math.sin(pitch), z = math.cos(yaw) * math.cos(pitch)}
	local pos_subtract = vector.subtract(pos2, pos1)
	local pos_dotproduct = (yaw_vec.x * pos_subtract.x) + (yaw_vec.y * pos_subtract.y) + (yaw_vec.z * pos_subtract.z)
	local angle = math.deg(math.acos(pos_dotproduct / (vector.length(yaw_vec) * vector.length(pos_subtract))))
	return angle
end