Page 1 of 2

mobile factory revisited

Posted: 20 Jan 2012, 17:12
by knorke
forgot who asked about it some days ago in lobby:
This is some quick&dirty way to get mobile factories.
Image
The factory gets movectrl'd and thus follows the mobile unit.
The built units fly out of the factory because my factory already was like that:
Image
So it is not that funny bug.
But I guess that is not even needed. (maybe tweak yardmap a bit)

When the factory dies, it is recreated. (could also just make it superstrong or block damage or w/e)
Put this into the script of the mobile unit:

Code: Select all

function script.Create()
	newFactory ()
	StartThread (moveFactory)	
end

function newFactory ()
	local x,y,z = Spring.GetUnitPosition (unitID)
	teamID = Spring.GetUnitTeam (unitID)
	factoryID = Spring.CreateUnit ("NAME_OF_FACTORY", x,y,z+100, 0, teamID)
	Spring.MoveCtrl.Enable (factoryID)
end

function moveFactory ()
	while (true) do
		if (not Spring.ValidUnitID (factoryID)) then newFactory () end
		local x,y,z = Spring.GetUnitPosition (unitID)
		Spring.SetUnitPosition (factoryID, x, y, z+100)
		Sleep (33)
	end
end
The factory script stays as is.

Killing the factory along with the mobile unit like

Code: Select all

function script.Killed(recentDamage, maxHealth)
--	if (Spring.ValidUnitID (factoryID)) then 
		Spring.DestroyUnit (factoryID) 
	--end
end
does not seem to work.
So that might need a gadget or the factory has to kill itself.

Due to lazy SetUnitPosition (factoryID, x, y, z+100) the factory does not really turn with the mobile unit, use math for that.

Re: mobile factory revisited

Posted: 20 Jan 2012, 18:54
by PicassoCT
well, i asked for that... months ago, and then dirtworked around that..
still thx, ill try to use it

Re: mobile factory revisited

Posted: 21 Jan 2012, 17:11
by Wombat
This with toilet model = WIN

Re: mobile factory revisited

Posted: 21 Jan 2012, 17:43
by PicassoCT
oh, come on, its win allready. Look at those little guys, trying to keep up with moma, while getting newborn soldiers into there faces.

Re: mobile factory revisited

Posted: 11 Aug 2012, 14:38
by knorke
Image

if the building has a grounddecal, it leaves a trail:
Image
its a snail!

Re: mobile factory revisited

Posted: 11 Aug 2012, 17:54
by bobthedinosaur
Can it be turned off for the duration of the move?

Re: mobile factory revisited

Posted: 11 Aug 2012, 19:22
by KaiserJ
"impossible" is not in knorkes vocabulary

Re: mobile factory revisited

Posted: 16 Aug 2012, 15:41
by PicassoCT
factory keeps catapulting my unit underground once built

Re: mobile factory revisited

Posted: 16 Aug 2012, 17:28
by Das Bruce
KaiserJ wrote:"impossible" is not in knorkes vocabulary
That is a very important word to be unaware of.

Re: mobile factory revisited

Posted: 16 Aug 2012, 21:46
by PicassoCT
well i went back to the mobile metallextractor sollution.. as everything.. from knorke..

Re: mobile factory revisited

Posted: 17 Aug 2012, 00:52
by knorke
bobthedinosaur wrote:Can it be turned off for the duration of the move?
yes, by adding a invisible third unit that you create/destroy to turn the trail on/off.

Re: mobile factory revisited

Posted: 09 Sep 2012, 14:36
by Cubex

Code: Select all

function UpdateUnitPosition(ParentID, UnitID, attach)
	local px, py, pz, _, _, _ = spGetUnitPiecePosDir(ParentID, attach)
	local rx, ry, rz = GetUnitPieceRotation(ParentID, attach)
	mcSetPhysics(UnitID, px, py, pz, 0, 0, 0, rx, ry, rz)
end
		
function GetUnitPieceRotation(unitID, piece)
	local rx, ry, rz = Spring.UnitScript.CallAsUnit(unitID, spGetPieceRotation, piece)
	local Heading = spGetUnitHeading(unitID) --COB format
	local dy = rad(Heading / 182)
	return rx, dy + ry, rz
end
You can use this for rotating the unit relative to its parent 8)

Re: mobile factory revisited

Posted: 09 Sep 2012, 15:41
by PicassoCT
sometimes i think the engine should come with this sort of lua allready packed in as a lib..

Re: mobile factory revisited

Posted: 09 Sep 2012, 15:46
by gajop
PicassoCT wrote:sometimes i think the engine should come with this sort of lua allready packed in as a lib..
+1
I want to make a "Common Lua Libraries" section in Lua Development part of the wiki, but I'm not sure what to add except chili (which already has a sparse page somewhere).

Re: mobile factory revisited

Posted: 09 Sep 2012, 16:32
by PicassoCT
well some basic toolkit stuff, the basic philosophy for such stuff to have only as basic functions as possible.. so cubex rotation stuff would be a excellent example.. or the transportable factory.. all stuff so that it can still be modified.

The other end approach is to add scripts which would take weeks too port, make them slightly modifyable and add them. If you dont know which one to put in, make a list, and make a vote.

Re: mobile factory revisited

Posted: 09 Sep 2012, 17:32
by Cubex
gajop wrote:I want to make a "Common Lua Libraries" section in Lua Development part of the wiki, but I'm not sure what to add except chili (which already has a sparse page somewhere).

Code: Select all

function InsertOrder(unitID, cmdID, cmdParams, cmdOptions, cmdPos)
	if not cmdPos then
		cmdPos = -1 --put it in the end of queue
	end
	local IntParams = {cmdPos, cmdID, cmdOptions}
	for i = 1, #cmdParams do --insert params from cmdParams
		IntParams[i+3] = cmdParams[i]
	end
	local IntOptions = {"alt"} --treat IntParam[0] as position instead of tag
	spGiveOrderToUnit(unitID, CMD_INSERT, IntParams, IntOptions)
end
Sorry for offtopic :P but i have to present another friendly func for your collection, this one will insert a command in the queue in the desired position, this saves you alot of overhead reading and understanding about CMD_INSERT use :mrgreen:, but options needs to be like CMD.OPT_SHIFT instead of "shift"

Re: mobile factory revisited

Posted: 09 Sep 2012, 19:09
by FLOZi
gajop wrote:
PicassoCT wrote:sometimes i think the engine should come with this sort of lua allready packed in as a lib..
+1
I want to make a "Common Lua Libraries" section in Lua Development part of the wiki, but I'm not sure what to add except chili (which already has a sparse page somewhere).
http://trac.caspring.org/browser/trunk/ ... /Utilities

Re: mobile factory revisited

Posted: 11 Sep 2012, 15:54
by knorke

Re: mobile factory revisited

Posted: 12 Sep 2012, 23:47
by yanom
is it possible to make the build options of the factory show up when you click the main unit (the one that's movecontrolling the factory)? I want to make a big assault walker that also has an airplane factory on top. The factory would be a small round platform hovering just above the top of the walker, and thus hard to manually select without selecting the walker. So... is there a workaround here.

Sidenote, knorke - Sanada shut down development of CT, but this year at school I have a "computer independent study" class. I'm forking CT under the name "Frontier" for my class project. Wanna join in? :-)

Re: mobile factory revisited

Posted: 13 Sep 2012, 03:26
by knorke
is it possible to make the build options of the factory show up when you click the main unit
quickest way is probally to add the factory-unit to selection as soon player selects the walker-unit.
(and other way around)
Since with lua you can read and control which units are selected, that should be doable.
http://springrts.com/wiki/Lua_UnsyncedC ... _Selection
http://springrts.com/wiki/Lua_UnsyncedR ... cted_Units

There are some others ways..what would work best would have to be tested.

Maybe you want to allow players to give seperate waypoints for movement and factory-rallyepoint? Then they would need to be able to select both units independently.

I do not want to commit myself to other projects at the moment..but good luck ofc.