aboutsummaryrefslogtreecommitdiff
path: root/advtrains_luaautomation
Commit message (Expand)AuthorAge
* LuaATC: remove accidental mesecons hard-dependencyorwell962021-11-04
* LuaATC: Fix position of error label, use consistent name "LuaATC" instead of ...orwell962021-11-02
* LuaATC: Add Mesecons LuaATC Controller (similar to Mesecons Luacontroller)orwell962021-11-02
* LuaATC PCNaming: Allow naming active components using the toolorwell962021-11-02
* Hopefully fix #177orwell962021-04-25
* Fix undeclared globals warnings (#176)orwell962021-04-25
* Increase size of LuaATC code input forms to 15x12 unitsorwell962021-03-22
* Remove "Last punched" from LuaATC init code fshlqkj2021-03-22
* Rework active_common formspec layouthlqkj2021-03-22
* Rework envsetup formspec layouthlqkj2021-03-22
* Replace deprecated depends.txt's by mod.conf and organize dependencies consis...orwell962021-03-13
* LuaATC: add sending atc command to train by ID, and getters for in/out text (...orwell962021-03-02
* LuaATC: add interrupt_safe() and clear_interrupts(), fix queue mainlooporwell962021-02-17
* LuaATC: Improve error/print logging, log only to subscribed playersorwell962021-02-17
* Clean up structure of atlatc README.md after rebaseorwell962021-02-17
* Updated atlac readme to consistently use Markdown formattingMaverick27972021-02-17
* Restore LuaATC autocouple interface accidentally lost in 74a2199orwell962021-02-15
* luaatc: Train event: also remember arrow connection in enter callback, remove...orwell962021-02-10
* luaatc: don't fail train event when train has already passed the rail at even...orwell962021-02-10
* Add debug prints, modify LZB to fix problems with look_aheadorwell962021-02-10
* Fix things, rework signal aspect select dialog, transform old aspects on-the-flyorwell962021-02-10
* Simplify Signal Aspect Table (H#132) [breaks compatibility with signal API]orwell962021-02-10
* Fix lots of things around new LZBorwell962021-02-10
* Disable ARS train flag and surrounding usesorwell962021-02-10
* Add approach callback mechanism to LuaATCorwell962021-02-10
* Make is_node_loaded() checks also for mesecon interactions and digiline_send(...orwell962021-02-04
* Discard get_node_or_nil() for area-loaded check and use either a distance-bas...orwell962021-02-03
* Make advtrains use serialize_lib (save version 4)orwell962021-01-12
* add maximum length parameter to split_at_fc and split_off_locomotiveGabriel Pérez-Cerezo2020-08-21
* Add command to split off locomotiveGabriel Pérez-Cerezo2020-07-28
* Complete Documentation on return value of split_at_fc()Gabriel Pérez-Cerezo2020-07-28
* Document new luaatc commandsGabriel Pérez-Cerezo2020-07-28
* add train_length command to luaatcGabriel Pérez-Cerezo2020-07-27
* Add function to step through freight codesGabriel Pérez-Cerezo2020-07-26
* add split_train_at_fc luaatc commandGabriel Pérez-Cerezo2020-07-26
* Make using the default tracks optional, even in submodsBlockhead2020-07-10
* Add "Fallback state" for freed routes, move p_mesecon_iface.lua to coreorwell962020-07-07
* fix typo in luaautomationGabriel Pérez-Cerezo2020-07-02
* Add autocouple modeGabriel Pérez-Cerezo2020-06-29
* document shunting mode, add unset_shunt to luaatcGabriel Pérez-Cerezo2020-06-08
* Apply minetest.formspec_escape() to prevent formspec injection (H#143)MT0.4Blockhead2020-01-04
* Fix RWT initialization when creating new world (H#142)orwell962019-12-18
* Fix scheduler crash (H#133)orwell962019-11-21
* Add "discard all" function to scheduler events and use it to clear schedules ...orwell962019-11-06
* atlatc: fix operation panel not in ndb, add warning when node is not found on...orwell962019-11-06
* Add lines scheduler for reliable railway-time scheduling(which is also safer ...orwell962019-08-26
* Shunting mode now couples trains on collision.Gabriel Pérez-Cerezo2019-08-11
* Document luaatc decouplingGabriel Pérez-Cerezo2019-08-11
* Add decoupling to luaatcGabriel Pérez-Cerezo2019-08-11
* RWTs can be specified in any form, unify converters, repeating time handlingorwell962019-06-19
> 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504
--atan2 counts angles clockwise, minetest does counterclockwise
local print=function(t) minetest.log("action", t) minetest.chat_send_all(t) end

local wagon={
	collisionbox = {-0.5,-0.5,-0.5, 0.5,0.5,0.5},
	--physical = true,
	visual = "mesh",
	mesh = "wagon.b3d",
	visual_size = {x=3, y=3},
	textures = {"black.png"},
	is_wagon=true,
	wagon_span=1,--how many index units of space does this wagon consume
	attach_offset={x=0, y=0, z=0},
	view_offset={x=0, y=0, z=0},
}



function wagon:on_rightclick(clicker)
	--print("[advtrains] wagon rightclick")
	if not clicker or not clicker:is_player() then
		return
	end
	if not self.initialized then
		print("[advtrains] not initiaalized")
		return
	end
	if clicker:get_player_control().sneak then
		advtrains.split_train_at_wagon(self)
		return
	end
	if clicker:get_player_control().aux1 then
		--advtrains.dumppath(self:train().path)
		--minetest.chat_send_all("at index "..(self:train().index or "nil"))
		--advtrains.invert_train(self.train_id)
		minetest.chat_send_all(dump(self:train()))
		return
	end	
	if self.driver and clicker == self.driver then
		advtrains.player_to_wagon_mapping[self.driver:get_player_name()]=nil
		advtrains.set_trainhud(self.driver:get_player_name(), "")
		self.driver = nil
		self.driver_name = nil
		clicker:set_detach()
		clicker:set_eye_offset({x=0,y=0,z=0}, {x=0,y=0,z=0})
	elseif not self.driver then
		self.driver = clicker
		advtrains.player_to_wagon_mapping[clicker:get_player_name()]=self
		clicker:set_attach(self.object, "", self.attach_offset, {x=0,y=0,z=0})
		clicker:set_eye_offset(self.view_offset, self.view_offset)
	end
end

function wagon:train()
	return advtrains.trains[self.train_id]
end

function wagon:on_activate(staticdata, dtime_s)
	--print("[advtrains][wagon "..(self.unique_id or "no-id").."] activated")
	self.object:set_armor_groups({immortal=1})
	if staticdata then
		local tmp = minetest.deserialize(staticdata)
		if tmp then
			self.unique_id=tmp.unique_id
			self.train_id=tmp.train_id
			self.wagon_flipped=tmp.wagon_flipped
			self.owner=tmp.owner
		end

	end
	self.old_pos = self.object:getpos()
	self.old_velocity = self.velocity
	self.initialized_pre=true
	self.entity_name=self.name
	
	--same code is in on_step
	--does this object already have an ID?
	if not self.unique_id then
		self.unique_id=os.time()..os.clock()--should be random enough.
	else
		for _,wagon in pairs(minetest.luaentities) do
			if wagon.is_wagon and wagon.initialized and wagon.unique_id==self.unique_id then--i am a duplicate!
				self.object:remove()
				return
			end
		end
	end
	--is my train still here
	if not self.train_id or not self:train() then
		if self.initialized then
			print("[advtrains][wagon "..self.unique_id.."] missing train_id, destroying")
			self.object:remove()
			return
		end
		print("[advtrains][wagon "..self.unique_id.."] missing train_id, but not yet initialized, returning")
		return
	elseif not self.initialized then
		self.initialized=true
	end
	advtrains.update_trainpart_properties(self.train_id)
end

function wagon:get_staticdata()
	--save to table before being unloaded