mobile factory revisited

mobile factory revisited

Discuss game development here, from a distinct game project to an accessible third-party mutator, down to the interaction and design of individual units if you like.

Moderators: Moderators, Moderators

User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

mobile factory revisited

Post 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.
0 x

User avatar
PicassoCT
Journeywar Developer & Mapper
Posts: 10260
Joined: 24 Jan 2006, 21:12

Re: mobile factory revisited

Post by PicassoCT »

well, i asked for that... months ago, and then dirtworked around that..
still thx, ill try to use it
0 x

User avatar
Wombat
Posts: 3379
Joined: 15 Dec 2008, 15:53

Re: mobile factory revisited

Post by Wombat »

This with toilet model = WIN
0 x

User avatar
PicassoCT
Journeywar Developer & Mapper
Posts: 10260
Joined: 24 Jan 2006, 21:12

Re: mobile factory revisited

Post 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.
0 x

User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: mobile factory revisited

Post by knorke »

Image

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

User avatar
bobthedinosaur
Blood & Steel Developer
Posts: 2695
Joined: 25 Aug 2004, 13:31

Re: mobile factory revisited

Post by bobthedinosaur »

Can it be turned off for the duration of the move?
0 x

User avatar
KaiserJ
Community Representative
Posts: 3113
Joined: 08 Sep 2008, 22:59

Re: mobile factory revisited

Post by KaiserJ »

"impossible" is not in knorkes vocabulary
0 x

User avatar
PicassoCT
Journeywar Developer & Mapper
Posts: 10260
Joined: 24 Jan 2006, 21:12

Re: mobile factory revisited

Post by PicassoCT »

factory keeps catapulting my unit underground once built
0 x

User avatar
Das Bruce
Posts: 3544
Joined: 23 Nov 2005, 06:16

Re: mobile factory revisited

Post by Das Bruce »

KaiserJ wrote:"impossible" is not in knorkes vocabulary
That is a very important word to be unaware of.
0 x

User avatar
PicassoCT
Journeywar Developer & Mapper
Posts: 10260
Joined: 24 Jan 2006, 21:12

Re: mobile factory revisited

Post by PicassoCT »

well i went back to the mobile metallextractor sollution.. as everything.. from knorke..
0 x

User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: mobile factory revisited

Post 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.
0 x

User avatar
Cubex
Posts: 56
Joined: 11 Jul 2012, 00:07

Re: mobile factory revisited

Post 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)
0 x

User avatar
PicassoCT
Journeywar Developer & Mapper
Posts: 10260
Joined: 24 Jan 2006, 21:12

Re: mobile factory revisited

Post by PicassoCT »

sometimes i think the engine should come with this sort of lua allready packed in as a lib..
0 x

gajop
Moderator
Posts: 3023
Joined: 05 Aug 2009, 20:42

Re: mobile factory revisited

Post 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).
0 x

User avatar
PicassoCT
Journeywar Developer & Mapper
Posts: 10260
Joined: 24 Jan 2006, 21:12

Re: mobile factory revisited

Post 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.
0 x

User avatar
Cubex
Posts: 56
Joined: 11 Jul 2012, 00:07

Re: mobile factory revisited

Post 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"
0 x

User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6112
Joined: 29 Apr 2005, 01:14

Re: mobile factory revisited

Post 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
0 x


yanom
Posts: 323
Joined: 10 Jul 2009, 23:34

Re: mobile factory revisited

Post 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? :-)
0 x

User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: mobile factory revisited

Post 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.
0 x

Post Reply

Return to “Game Development”