Author Topic: no-dynamic-goals sexp! Mindlessly narrow the AI's actions on the fly now!  (Read 3003 times)

0 Members and 1 Guest are viewing this topic.

Offline Axem

  • 211
no-dynamic-goals sexp! Mindlessly narrow the AI's actions on the fly now!
Quote
[17:30] <battuta> i'm really wanting to set up some retreat tactics for fighters in this mission
[17:31] <battuta> i thought about swapping some of the storm distractors to dracos and having them shoot some trebs/whatever and then run awaaay
[17:31] <@Axem> problem is they dont use afterburners :(
[17:31] <battuta> we could use an attack order...
[17:31] <battuta> ...but then we'd need no dynamic on...
[17:31] <battuta> and there's no sexp for that!
[17:31] <@Axem> can we switch off dynamic orders?
[17:31] <@Axem> hmm
[17:32] <@Axem> [17:31] <battuta> and there's no sexp for that!
[17:32] <@Axem> maybe there SHOULD be
[17:32] * @Axem opens visual studio

A few hours later, copy pasting existing code and getting karajorma's help on how to debug...

Huzzah!

Code: [Select]
Index: sexp.cpp
===================================================================
--- sexp.cpp (revision 9242)
+++ sexp.cpp (working copy)
@@ -362,6 +362,8 @@
  { "player-not-use-ai", OP_PLAYER_NOT_USE_AI, 0, 0 }, // Goober5000
  { "set-player-orders", OP_SET_PLAYER_ORDERS, 3, INT_MAX }, // Karajorma
  { "cap-waypoint-speed", OP_CAP_WAYPOINT_SPEED, 2, 2 },
+ { "dynamic-goals", OP_DYNAMIC_GOALS, 1, INT_MAX}, // Axem
+ { "no-dynamic-goals", OP_NO_DYNAMIC_GOALS, 1, INT_MAX}, // Axem
 
  //Ship Status Sub-Category
  { "protect-ship", OP_PROTECT_SHIP, 1, INT_MAX, },
@@ -13157,6 +13159,53 @@
  sexp_deal_with_ship_flag(n, true, 0, 0, 0, SF2_NO_ETS, 0, P2_SF2_NO_ETS, disable);
 }
 
+void sexp_ingame_ship_no_dynamic(ship *shipp, bool no_dynamic)
+{
+ Assert(shipp);
+
+ ai_info *aip = &Ai_info[shipp->ai_index];
+
+ if (no_dynamic)
+ {
+ aip->ai_flags |= AIF_NO_DYNAMIC;
+ }
+ else
+ {
+ aip->ai_flags &= ~AIF_NO_DYNAMIC;
+ }
+}
+
+// Axem - turns no dynamic goals on or off for a ship
+void sexp_no_dynamic_goals(int n, bool no_dynamic)
+ {
+ sexp_deal_with_ship_flag(n, true, 0, 0, 0, 0, P_AIF_NO_DYNAMIC, 0, no_dynamic);
+
+ for ( ; n != -1; n = CDR(n) )
+ {
+ object_ship_wing_point_team oswpt;
+ sexp_get_object_ship_wing_point_team(&oswpt, CTEXT(n));
+
+ switch (oswpt.type)
+ {
+ // change ingame ship
+ case OSWPT_TYPE_SHIP:
+ {
+ sexp_ingame_ship_no_dynamic(oswpt.shipp, no_dynamic);
+
+ break;
+ }
+
+ case OSWPT_TYPE_WING:
+ {
+ // current ships
+ for (int i = 0; i < oswpt.wingp->current_count; i++)
+ sexp_ingame_ship_no_dynamic(&Ships[oswpt.wingp->ship_index[i]], no_dynamic);
+
+ }
+ }
+ }
+}
+
 // Goober5000 - sets the vaporize flag on a list of ships
 void sexp_ships_vaporize(int n, bool vaporize)
 {
@@ -22807,6 +22856,12 @@
  sexp_set_thrusters(node);
  break;
 
+ case OP_NO_DYNAMIC_GOALS:
+ case OP_DYNAMIC_GOALS:
+ sexp_no_dynamic_goals(node, (op_num == OP_NO_DYNAMIC_GOALS));
+ sexp_val = SEXP_TRUE;
+ break;
+
  default:
  Error(LOCATION, "Looking for SEXP operator, found '%s'.\n", CTEXT(cur_node));
  break;
@@ -23757,6 +23812,8 @@
  case OP_SET_THRUSTERS:
  case OP_SET_PLAYER_THROTTLE_SPEED:
  case OP_DEBUG:
+ case OP_DYNAMIC_GOALS:
+ case OP_NO_DYNAMIC_GOALS:
  return OPR_NULL;
 
  case OP_AI_CHASE:
@@ -25749,6 +25806,10 @@
  else
  return OPF_SHIP;
 
+ case OP_DYNAMIC_GOALS:
+ case OP_NO_DYNAMIC_GOALS:
+ return OPF_SHIP_WING;
+
  default:
  Int3();
  }
@@ -26997,6 +27058,8 @@
  case OP_PLAYER_NOT_USE_AI:
  case OP_SET_PLAYER_ORDERS:
  case OP_CAP_WAYPOINT_SPEED:
+ case OP_DYNAMIC_GOALS:
+ case OP_NO_DYNAMIC_GOALS:
  return CHANGE_SUBCATEGORY_AI_CONTROL;
 
 
@@ -30856,6 +30919,17 @@
  "\t1:\tThe player ship to set the throttle of.\r\n"
  "\t2:\tThe percentage of the player's maximum speed to set their throttle to.\r\n"
  "\t\tThis is capped to either 0 or 100 if outside the valid range."
+ },
+ {OP_DYNAMIC_GOALS , "dynamic-orders\r\n"
+ "\tTells the AI to use dynamic orders\r\n\r\n"
+ "Takes at least 1 argument...\r\n"
+ "\tAll:\tList of ships this sexp applies to\r\n"
+ },
+
+ { OP_NO_DYNAMIC_GOALS, "no-dynamic-orders\r\n"
+ "\tTells the AI to not use dynamic orders\r\n\r\n"
+ "Takes at least 1 argument...\r\n"
+ "\tAll:\tList of ships this sexp applies to\r\n"
  }
 };
 
Index: sexp.h
===================================================================
--- sexp.h (revision 9242)
+++ sexp.h (working copy)
@@ -701,6 +701,8 @@
 #define OP_DESTROY_SUBSYS_INSTANTLY (0x0016 | OP_CATEGORY_CHANGE2 | OP_NONCAMPAIGN_FLAG) // Admiral MS
 #define OP_DEBUG (0x0017 | OP_CATEGORY_CHANGE2 | OP_NONCAMPAIGN_FLAG) // Karajorma
 #define OP_SET_MISSION_MOOD (0x0018 | OP_CATEGORY_CHANGE2 | OP_NONCAMPAIGN_FLAG) // Karajorma
+#define OP_DYNAMIC_GOALS (0x0019 | OP_CATEGORY_CHANGE2 | OP_NONCAMPAIGN_FLAG) // Axem
+#define OP_NO_DYNAMIC_GOALS (0x001a | OP_CATEGORY_CHANGE2 | OP_NONCAMPAIGN_FLAG) // Axem
 
 
 // defined for AI goals

If you didn't already guess, this is a sexp to turn the No Dynamic Goals flag on and off through sexps. Dynamic goals are things like fighters breaking off their attack on their target to pursue their own attacker. It can be used to make them single minded to do things like attack far away objects (make it look like they're retreating) or other fun things.

And here's a test mission for anyone brave enough to compile the patch!
http://lazymodders.fsmods.net/files/nodynamictest.rar

 

Offline General Battuta

  • Poe's Law In Action
  • 214
  • i wonder when my postcount will exceed my iq
Re: no-dynamic-goals sexp! Mindlessly narrow the AI's actions on the fly now!

 

Offline Spoon

  • 212
  • ヾ(´︶`♡)ノ
Re: no-dynamic-goals sexp! Mindlessly narrow the AI's actions on the fly now!

Urutorahappī!!

[02:42] <@Axem> spoon somethings wrong
[02:42] <@Axem> critically wrong
[02:42] <@Axem> im happy with these missions now
[02:44] <@Axem> well
[02:44] <@Axem> with 2 of them

 

Offline Aardwolf

  • 211
  • Posts: 16,384
Re: no-dynamic-goals sexp! Mindlessly narrow the AI's actions on the fly now!
Marginally related: why is it that FreeSpace SEXPs come in pairs, e.g. "dynamic-goals" and "no-dynamic-goals", instead of having a single SEXP which takes a Boolean argument? Is that something mission designers aren't good at? Or what?

 

Offline Axem

  • 211
Re: no-dynamic-goals sexp! Mindlessly narrow the AI's actions on the fly now!
I've wondered the same thing. It seems to be mostly when dealing with ship flag related options that there's a sexp pair, but others there's a true/false and then the list...

As someone just copy pasting other sexps to get my own, I dare not get too "creative". :p

 

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Re: no-dynamic-goals sexp! Mindlessly narrow the AI's actions on the fly now!
To be honest, I think it would be better to move over to using a boolean system simply because it doesn't take up so much space on the screen in FRED.
Karajorma's Freespace FAQ. It's almost like asking me yourself.

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

 

Offline mjn.mixael

  • Cutscene Master
  • 212
  • Chopped liver
    • Steam
    • Twitter
Re: no-dynamic-goals sexp! Mindlessly narrow the AI's actions on the fly now!
This is awesome. I needed this for sure.
Cutscene Upgrade Project - Mainhall Remakes - Between the Ashes
Youtube Channel - P3D Model Box
Between the Ashes is looking for committed testers, PM me for details.
Freespace Upgrade Project See what's happening.

 

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Re: no-dynamic-goals sexp! Mindlessly narrow the AI's actions on the fly now!
It's probably not going in.

I'll probably add something to the alter-ship-flag stuff I added in Test Builds instead.
Karajorma's Freespace FAQ. It's almost like asking me yourself.

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

 

Offline Droid803

  • Trusted poster of legit stuff
  • 213
  • /人 ◕ ‿‿ ◕ 人\ Do you want to be a Magical Girl?
    • Skype
    • Steam
Re: no-dynamic-goals sexp! Mindlessly narrow the AI's actions on the fly now!
On a somewhat related note, any specific reason why turret/beam-lock/free-all only takes a single argument and can't list multiple ships?
(´・ω・`)
=============================================================

 

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Re: no-dynamic-goals sexp! Mindlessly narrow the AI's actions on the fly now!
On a somewhat related note, any specific reason why turret/beam-lock/free-all only takes a single argument and can't list multiple ships?

Cause they take multiple turrets/beams as arguments.

The way the SEXP system works is that every argument except the last one must be constant. So you can have a SEXP like

SEXP Name
-Ship Name
-Turret
-<more turrets>

but not one like

SEXP Name
-Ship Name
-More Ship Names
-Turrets

Technically you might be able to do the above by checking the return type but it would probably be very messy. What might be possible is to fix the SEXPs to accept a single ship name, wing name, or a team name (friendly, hostile, etc). Not much use in the case of this SEXP though but there are other examples where it might work.

In the end though, it's a lot of work for something you can solve just by using <argument>.
Karajorma's Freespace FAQ. It's almost like asking me yourself.

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

 

Offline Droid803

  • Trusted poster of legit stuff
  • 213
  • /人 ◕ ‿‿ ◕ 人\ Do you want to be a Magical Girl?
    • Skype
    • Steam
Re: no-dynamic-goals sexp! Mindlessly narrow the AI's actions on the fly now!
The one to lock/free all turrets takes additional arguments? O_o
What for?
Which ones not to lock/free?
(´・ω・`)
=============================================================

 

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Re: no-dynamic-goals sexp! Mindlessly narrow the AI's actions on the fly now!
Okay Beam/Turret-lock/free-all takes a list of ships already. Beam/Turret-free/lock can't for the reason I gave above. I assumed you meant the latter cause the former can already take a list of ships.

However, looking into it more deeply, it does appear that the SEXP documentation was never updated to reflect that the former can accept multiple ships, try an add-data though. It should work.
« Last Edit: October 10, 2012, 01:15:26 am by karajorma »
Karajorma's Freespace FAQ. It's almost like asking me yourself.

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

 

Offline Droid803

  • Trusted poster of legit stuff
  • 213
  • /人 ◕ ‿‿ ◕ 人\ Do you want to be a Magical Girl?
    • Skype
    • Steam
Re: no-dynamic-goals sexp! Mindlessly narrow the AI's actions on the fly now!
Last time I tried doing that it threw me errors, which was why I asked, maybe it got changed somewhere along the line though, without me ever noticing O_o.
(´・ω・`)
=============================================================

  

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Re: no-dynamic-goals sexp! Mindlessly narrow the AI's actions on the fly now!
I remember adding loops to one (or more) of those SEXPs years ago. So if there is a bug, it's probably still there. I'd appreciate it if someone checked.
Karajorma's Freespace FAQ. It's almost like asking me yourself.

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