Question about the airplane plant

Question about the airplane plant

A dynamic game undergoing constant development and refinement, that attempts to balance playability with fresh and innovative features.

Moderator: Content Developer

Post Reply
thedude
Posts: 66
Joined: 21 Aug 2009, 12:47

Question about the airplane plant

Post by thedude » 19 Jan 2010, 18:32

Can someone tell me how the airplane plant in CA works? How does the plane get to know where to fly when the "Land at XX" limit is reached.
What I want to do is to make such a thing for landunits. So when a vehicle reached the "Return at XX" (like "Land at XX" for the airplanes) it will return to the repairpad of the nearest vehiclefactory (factory with a builtin repairpad).
0 x

User avatar
Licho
Zero-K Developer
Posts: 3803
Joined: 19 May 2006, 19:13

Re: Question about the airplane plant

Post by Licho » 19 Jan 2010, 19:47

It uses engine feature (with lots of side issues). I dont think it will work for land units. You have to code your own lua. When you have it done, let us know, it could be handy!
0 x

luckywaldo7
Posts: 1397
Joined: 17 Sep 2008, 04:36

Re: Question about the airplane plant

Post by luckywaldo7 » 19 Jan 2010, 19:59

Check out the retreat widget included in CA:

http://trac.caspring.org/wiki/Retreat
0 x

User avatar
Pxtl
Posts: 6112
Joined: 23 Oct 2004, 01:43

Re: Question about the airplane plant

Post by Pxtl » 19 Jan 2010, 22:12

I'm pretty sure Retreat is enabled by default (although that may have been changed because of anti-widget whiners). It's a very user-friendly and powerful widget, and is particularly useful for high-armor raiders like Zippers and Kodachis.
0 x

Saktoth
Zero-K Developer
Posts: 2665
Joined: 28 Nov 2006, 13:22

Re: Question about the airplane plant

Post by Saktoth » 20 Jan 2010, 08:15

Retreat is virtually useless, its only good on air units. Land units just mill into eachother and die and cause traffic jams.
0 x

User avatar
CarRepairer
Cursed Zero-K Developer
Posts: 3359
Joined: 07 Nov 2007, 21:48

Re: Question about the airplane plant

Post by CarRepairer » 20 Jan 2010, 17:44

Saktoth wrote:Retreat is virtually useless, its only good on air units. Land units just mill into eachother and die and cause traffic jams.
Have you tried it with...
Pxtl wrote:Zippers
Saktoth? It's easy and fun, don't forget to sprint. I think you aren't a fan of the zipper anyway.
0 x

thedude
Posts: 66
Joined: 21 Aug 2009, 12:47

Re: Question about the airplane plant

Post by thedude » 21 Jan 2010, 09:00

Can I get the position of a specific part of a building. Like I build a factory with a part called repairpad, how can I get the position of this part so I can send units there?
0 x

User avatar
Licho
Zero-K Developer
Posts: 3803
Joined: 19 May 2006, 19:13

Re: Question about the airplane plant

Post by Licho » 21 Jan 2010, 18:55

Look in lua wiki, you can get matrix of the piece for sure.
0 x

thedude
Posts: 66
Joined: 21 Aug 2009, 12:47

Re: Question about the airplane plant

Post by thedude » 13 Feb 2010, 19:36

OK, found some time to give it a try. But I guess I do it the wrong way.
I added a button so when this button is pressed the unit should be sent to a certain place (should be the repairpad (later)) but when the unit arrives Spring prints an error.

Code: Select all

function gadget:GetInfo()

	return {
		name = "tobase",
		desc = "tells a unit to move to a certain point",
		author = "thedude",
		date = "yesterday",
		license = "Public Domain",
		layer = 1,
		enabled = true

	}

end

local CMD_TOBASE = 30059

if (gadgetHandler:IsSyncedCode()) then


--SYNCED


local cmdTobase={

	id=CMD_TOBASE,
	type=CMDTYPE.ICON,
	name="movetopoint",
	cursor="moveto",
	action="moveto",
	tooltip="move to 200 200",

}

function gadget:UnitCreated(u,ud,team)

	if UnitDefs[ud].name=="tank" then
		Spring.InsertUnitCmdDesc(u,CMD_TOBASE,cmdTobase)

	end

end


function gadget:UnitDestroyed(u,ud,team)

end


function gadget:CommandFallback(u,ud,team,cmd,param,opt)

	if cmd == CMD_TOBASE then
		--Spring.GiveOrderToUnit(u,CMD.MOVE,{200,0,200},0)
		Spring.GiveOrderToUnit(u, CMD.INSERT, { 0, CMD.MOVE, CMD.OPT_INTERNAL, 200, 0, 200}, CMD.OPT_ALT) -- ALT makes the 0 positional

	end

	return false

end


function gadget:Initialize()
Spring.SetCustomCommandDrawData(CMD_TOBASE,"Moveto",{1,1,.2,1})

end

else

--UNSYNCED

end

the error: "LuaRules::RunCallIn: error = 2, CommandFallback, [string "LuaRules/Gadgets/tobase_3.lua"]:51: GiveOrderToUnit() recursion is not permitted"

I guess Spring tells me that it is not allowed to use an existing command with my new command :?
When I use "Spring.GiveOrderToUnit(u,CMD.MOVE,{200,0,200},0)" I get no error but the unit just moves a little and than moves back.
0 x

SirMaverick
Posts: 834
Joined: 19 May 2009, 21:10

Re: Question about the airplane plant

Post by SirMaverick » 13 Feb 2010, 23:33

thedude wrote: the error: "LuaRules::RunCallIn: error = 2, CommandFallback, [string "LuaRules/Gadgets/tobase_3.lua"]:51: GiveOrderToUnit() recursion is not permitted"

I guess Spring tells me that it is not allowed to use an existing command with my new command :?
Spring tells you that recursion is not permitted. You can't give commands within CommandFallback.

(Even if: CommandFallback is called 2 times a second and you add a command each time.)
0 x

thedude
Posts: 66
Joined: 21 Aug 2009, 12:47

Re: Question about the airplane plant

Post by thedude » 16 Feb 2010, 14:58

What would be a better way to do that?
0 x

thedude
Posts: 66
Joined: 21 Aug 2009, 12:47

Re: Question about the airplane plant

Post by thedude » 20 Feb 2010, 19:55

What about this version?
What I was thinking it does:
I start the game.
build the unit wich should have this command
select that unit
press the moveto button
gadget:AllowCommand is triggert
cheks if my command is triggert
yes-> execute the goto function
==>unit moves to {200,200}

Code: Select all

function gadget:GetInfo()

	return {
		name = "tobase",
		desc = "tells a unit to move to a certain point",
		author = "thedude",
		date = "yesterday",
		license = "Public Domain",
		layer = 1,
		enabled = true
	}

end

local CMD_TOBASE = 30059

if (gadgetHandler:IsSyncedCode()) then

--SYNCED

local cmdTobase={

	id=CMD_TOBASE,
	type=CMDTYPE.ICON,
	name="movetopoint",
	cursor="moveto",
	action="moveto",
	tooltip="move to 200 200",

}


local function goto(unitID)
	Spring.GiveOrderToUnit(unitID,CMD.MOVE,{200,0,200},0)

end

function gadget:UnitCreated(u,ud,team)

	if UnitDefs[ud].name=="tank" then
		Spring.InsertUnitCmdDesc(u,CMD_TOBASE,cmdTobase)
	end
end

function gadget:UnitDestroyed(u,ud,team)

end

function gadget:AllowCommand(u, ud, team, cmd, param, opt)

	if cmd == CMD_TOBASE then
		Spring.Echo("here comes my command");
		goto(u)
	return true
	end

	return true

end

function gadget:Initialize()

Spring.SetCustomCommandDrawData(CMD_TOBASE,"Moveto",{1,1,.2,1})

end

else

--UNSYNCED

end

The problem is when I push the button the unit starts to move but then turns and moves back to the place where it was before. :|
(Even if: CommandFallback is called 2 times a second and you add a command each time.)
Ooops didn't know that.
0 x

SirMaverick
Posts: 834
Joined: 19 May 2009, 21:10

Re: Question about the airplane plant

Post by SirMaverick » 20 Feb 2010, 21:01

thedude wrote:press the moveto button
gadget:AllowCommand is triggert
cheks if my command is triggert
yes-> execute the goto function
Recursion again. You cannot call GiveOrder within AllowCommand.
Save the information (into a variable etc.) that you want to give an order and give the order the next GameFrame().
0 x

thedude
Posts: 66
Joined: 21 Aug 2009, 12:47

Re: Question about the airplane plant

Post by thedude » 23 Feb 2010, 09:15

This one works for me. But I don't know if that is a good way to do that. What happens if I select 100 units and save each unitID into one array (buttonof[100]) and after that I select only one unit and save the unitID to the first element of my array are the other IDs still there? Should I better make a for loop and delete the whole array and then save the new ID/IDs ?

Code: Select all

function gadget:GetInfo()
	return {
		name = "tobase",
		desc = "tells a unit to move to a certain point",
		author = "thedude",
		date = "yesterday",
		license = "Public Domain",
		layer = 1,
		enabled = true
	}
end

local CMD_TOBASE = 30059
local yeswecan=false
local newclick=false
local a=0
local buttonof={}

if (gadgetHandler:IsSyncedCode()) then

--SYNCED

local cmdTobase={
	id=CMD_TOBASE,
	type=CMDTYPE.ICON,
	name="movetopoint",
	cursor="moveto",
	action="moveto",
	tooltip="move to 200 200",
	}


local function goto(unitID)
	
	yeswecan=true

	if newclick==true then

		a=1
		buttonof[a]= unitID
	end
	if newclick==false then
		a=a+1
		buttonof[a]= unitID
	end
	newclick=false
end


function gadget:UnitCreated(u,ud,team)
	
	if UnitDefs[ud].name=="tank" then

		Spring.InsertUnitCmdDesc(u,CMD_TOBASE,cmdTobase)

	end

end

function gadget:UnitDestroyed(u,ud,team)

end

function gadget:AllowCommand(u, ud, team, cmd, param, opt)
	if cmd == CMD_TOBASE then
	
		Spring.Echo("here comes my command");
		goto(u)
		
	return true
	end
	return true
end

function gadget:GameFrame(f)

    if f %32<1 then
		if yeswecan==true then
			for i=1,#buttonof do
			Spring.GiveOrderToUnit(buttonof[i],CMD.MOVE,{200,0,200},0)
			end
			yeswecan=false
			newclick=true
		end
	end
end


function gadget:Initialize()
 	Spring.SetCustomCommandDrawData(CMD_TOBASE,"Moveto",{1,1,.2,1})

end


else
--UNSYNCED


end

Another question. I found in XOTA v1.61 the same command but only for planes/vtols. Problem is I don't get how this one works cause there is no move command to make the planes move to the airpad. The only thing I can find is "Spring.CallCOBScript(unitID, "Refuel", 0)". I thought this is a command to look for a tag/function in the bos file and to execute that but after descripting the bos file I could not find a function called "Refuel" :?:
Attachments
cobandbosfile.7z
This is the cob and the descripted bos file of the plane "Fighter".
(2.36 KiB) Downloaded 16 times
unit_refuel.lua
This is the gadget which adds the command (I think).
(4.61 KiB) Downloaded 110 times
0 x

thedude
Posts: 66
Joined: 21 Aug 2009, 12:47

Re: Question about the airplane plant

Post by thedude » 16 May 2010, 19:38

I have a problem. If I use the CommandFallBack function my gadget doesn't work but when using AlowCommand it seems to work (little buggy but works). Can't find the problem :evil: . Please help.

http://sharetext.org/AKQ2
0 x

Post Reply

Return to “Zero-K”