Author Topic: Move orders?  (Read 1896 times)

0 Members and 1 Guest are viewing this topic.

Offline Aardwolf

  • 211
  • Posts: 16,384
One of the issues we (Nuke & I) had to worry about with the early development of the RTS Mod was move orders. The only way we had of giving them relied on waypoints, and each waypoint had to be the first (and only) point in a waypoint path. With this setup, we were quickly running out of waypoints. As far as I know, a better solution has yet to become available.

Would this require a bump to max waypoints, or could it be solved better some other way? If so, what?

For the case of the RTS Mod in particular, I think we would need to be able to have at least one waypoint (point/path) per ship, so that each ship could have a current move order, plus a list (handled by Lua) of points to use as move destinations, in the case of chained move/attack orders. And I'm pretty sure the waypoint paths limit is significantly less than the ships limit.

« Last Edit: November 02, 2009, 06:49:00 am by Aardwolf »

 

Offline Aardwolf

  • 211
  • Posts: 16,384
We still want to be able to issue move orders, and there have yet to be any responses, so...

:bump:

From the Lua-side, we have no way to create waypoint paths.

I wouldn't mind trying to implement something, if someone will confirm in advance that it's a valid solution and that there is a good chance of such a feature making it into trunk eventually.

Also on the subject of orders, there's no way to clear the orders a ship has. That's bad. I'd also like to try to implement that, if it's ok. It should be fairly simple to do.

I have managed to use the runSEXP function as a stand-in for a clearOrders function, but it's hackish, and it won't work for waypoints because there's no create-waypoint SEXP, and because waypoints created from Lua don't have names that I can reference in SEXP-notation.

 

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
There are SEXPs for clearing the orders a ship has. What do you mean?
Karajorma's Freespace FAQ. It's almost like asking me yourself.

[ Diaspora ] - [ Seeds Of Rebellion ] - [ Mind Games ]

 

Offline Aardwolf

  • 211
  • Posts: 16,384
I meant there's nothing that can be used in a script. Actually that's not quite true... it's doable, and I was able to do it, but it's needlessly complicated:

Code: [Select]
mn.runSEXP('( when true ( clear-goals "'..curShip.Name..'" ) )')
where curShip is the ship to clear the goals of. Having to look up the name of the ship and put quotation mark characters around it is a bit of a hack IMO. Something like this would be a lot nicer, if only it existed:

Code: [Select]
curShip:clearGoals()

Also, there's a shiporders type which I presume was meant to make it possible to add and/or remove orders, but there's nothing that uses it; there is no function/property that would give you a shiporders object. Similarly, there is no function/property giving back eyepoint objects, even though the eyepoint type is defined and has properties/functions.

As for the other part of the move order problem, this is what I've been trying to do:

Code: [Select]
for key,curShip in pairs(movers) do
local meta = getShipMETA(curShip)
if not(meta.moveDestination) then
meta.moveDestination = mn.createWaypoint(dest)
else
meta.moveDestination.Position = dest
end
mn.runSEXP('( when true ( clear-goals "'..curShip.Name..'" ) )')
curShip:giveOrder(ORDER_WAYPOINTS_ONCE, meta.moveDestination, nil, 100)
end

given movers is a list of ship handles. Unfortunately, this doesn't work--probably because meta.moveDestination is a waypoint and not a waypoint path like it expects. So I really have no way of doing this.

Also, it is not currently possible to create a waypoint path from within a script.

  

Offline Aardwolf

  • 211
  • Posts: 16,384
I have coded a function

Code: [Select]
ship:clearOrders()
and I have done a bit of testing. It appears to work as intended, but additional testing is probably necessary prior to a commit.

Patch file (also uploaded as an attachment)
Code: [Select]
Index: lua.cpp
===================================================================
--- lua.cpp (revision 5641)
+++ lua.cpp (working copy)
@@ -6048,6 +6048,20 @@
  return ade_set_args(L, "f", time_s);
 }
 
+ADE_FUNC(clearOrders, l_Ship, NULL, "Clears a ship's orders list", "boolean", "True if successful, otherwise false or nil")
+{
+ object_h *objh = NULL;
+ if(!ade_get_args(L, "o", l_Object.GetPtr(&objh)))
+ return ADE_RETURN_NIL;
+ if(!objh->IsValid())
+ return ade_set_error(L, "b", false);
+
+ //The actual clearing of the goals
+ ai_clear_ship_goals( &Ai_info[Ships[objh->objp->instance].ai_index]);
+
+ return ADE_RETURN_TRUE;
+}
+
 ADE_FUNC(giveOrder, l_Ship, "enumeration Order, [object Target=nil, subsystem TargetSubsystem=nil, number Priority=1.0]", "Uses the goal code to execute orders", "boolean", "True if order was given, otherwise false or nil")
 {
  object_h *objh = NULL;

We still have no means of giving move orders.

[attachment deleted by admin]