From 59b5478d836640f77470aacc6f908d1efd9a88ce Mon Sep 17 00:00:00 2001 From: Per Inge Mathisen Date: Mon, 17 May 2010 17:52:55 +0000 Subject: [PATCH] Add new trigger CALL_VTOL_RETARGET that is fired off whenever a VTOL detects that its designated target no longer exists. This allows an AI script to give it a new target while in-flight instead of waiting for it to return to base, saving precious time. git-svn-id: https://warzone2100.svn.sourceforge.net/svnroot/warzone2100/trunk@10841 4a71c877-e1ca-e34f-864e-861f7616d084 --- src/order.c | 13 ++++++++++--- src/scriptcb.c | 31 +++++++++++++++++++++++++++++++ src/scriptcb.h | 4 ++++ src/scripttabs.c | 7 +++++-- src/scripttabs.h | 1 + 5 files changed, 51 insertions(+), 5 deletions(-) diff --git a/src/order.c b/src/order.c index f41b44712..2f9709fd6 100644 --- a/src/order.c +++ b/src/order.c @@ -767,14 +767,21 @@ void orderUpdateDroid(DROID *psDroid) { if (!orderDroidList(psDroid)) { - psDroid->order = DORDER_NONE; + psDroid->order = DORDER_NONE; moveToRearm(psDroid); + if (!vtolEmpty(psDroid)) + { + // VTOL droid can do more work, let scripts handle it + psScrVtolRetarget = psDroid; + eventFireCallbackTrigger((TRIGGER_TYPE)CALL_VTOL_RETARGET); + psScrVtolRetarget = NULL; + } } } else { - psDroid->order = DORDER_NONE; - actionDroid(psDroid, DACTION_NONE); + psDroid->order = DORDER_NONE; + actionDroid(psDroid, DACTION_NONE); } } else if ( ((psDroid->action == DACTION_MOVE) || diff --git a/src/scriptcb.c b/src/scriptcb.c index 1c5231675..c643c658f 100644 --- a/src/scriptcb.c +++ b/src/scriptcb.c @@ -57,6 +57,8 @@ STRUCTURE *psScrCBNewDroidFact; // id of factory that built it. // the attacker and target for a CALL_ATTACKED BASE_OBJECT *psScrCBAttacker, *psScrCBTarget; +// vtol target +DROID *psScrVtolRetarget = NULL; // alliance details UDWORD CBallFrom,CBallTo; @@ -184,6 +186,35 @@ BOOL scrCBStructAttacked(void) return true; } +BOOL scrCBVTOLRetarget(void) +{ + SDWORD player; + DROID **ppsDroid; + + if (!stackPopParams(2, VAL_INT, &player, VAL_REF|ST_DROID, &ppsDroid)) + { + return false; + } + ASSERT_OR_RETURN(false, player < MAX_PLAYERS && player >= 0, "Invalid player %d", player); + + if (player == psScrVtolRetarget->player) + { + *ppsDroid = psScrVtolRetarget; + scrFunctionResult.v.bval = true; + } + else + { + *ppsDroid = NULL; + scrFunctionResult.v.bval = false; + } + if (!stackPushResult(VAL_BOOL, &scrFunctionResult)) + { + return false; + } + + return true; +} + // Deal with a CALL_DROID_ATTACKED BOOL scrCBDroidAttacked(void) { diff --git a/src/scriptcb.h b/src/scriptcb.h index c9e58600b..ebcfac0dd 100644 --- a/src/scriptcb.h +++ b/src/scriptcb.h @@ -52,6 +52,7 @@ extern DROID *psScrCBNewDroid; extern STRUCTURE *psScrCBNewDroidFact; extern DROID *psScrCBOrderDroid; extern SDWORD psScrCBOrder; +extern DROID *psScrVtolRetarget; //Script key event callback extern SDWORD cbPressedMetaKey; @@ -138,6 +139,9 @@ extern BOOL scrCBResCompleted(void); /* when a player leaves the game*/ extern BOOL scrCBPlayerLeft(void); +/* when a VTOL runs out of things to do while mid-air */ +extern BOOL scrCBVTOLRetarget(void); + // alliance offered. extern BOOL scrCBAllianceOffer(void); extern UDWORD CBallFrom,CBallTo; diff --git a/src/scripttabs.c b/src/scripttabs.c index 4ef204ad5..97259b2d8 100644 --- a/src/scripttabs.c +++ b/src/scripttabs.c @@ -2257,8 +2257,11 @@ CALLBACK_SYMBOL asCallbackTable[] = { "CALL_DROID_REACH_LOCATION",(TRIGGER_TYPE)CALL_DROID_REACH_LOCATION, scrCBDorderReachedLocation,3, { VAL_INT, VAL_REF|(INTERP_TYPE)ST_DROID, VAL_REF | VAL_INT } }, - { "CALL_KEY_PRESSED", (TRIGGER_TYPE)CALL_KEY_PRESSED, - scrCBProcessKeyPress,2, { VAL_REF | VAL_INT, VAL_REF| VAL_INT} }, + { "CALL_KEY_PRESSED", (TRIGGER_TYPE)CALL_KEY_PRESSED, + scrCBProcessKeyPress, 2, { VAL_REF | VAL_INT, VAL_REF| VAL_INT} }, + + { "CALL_VTOL_RETARGET", (TRIGGER_TYPE)CALL_VTOL_RETARGET, + scrCBVTOLRetarget, 2, { VAL_INT, VAL_REF| (INTERP_TYPE)ST_DROID } }, /* This entry marks the end of the callback list */ { "CALLBACK LIST END", 0, NULL, 0, {VAL_VOID} } diff --git a/src/scripttabs.h b/src/scripttabs.h index db2aafe54..a87274689 100644 --- a/src/scripttabs.h +++ b/src/scripttabs.h @@ -102,6 +102,7 @@ typedef enum _scr_callback_types CALL_DORDER_STOP, // Fired when droid is forced to stop via user interface CALL_DROID_REACH_LOCATION, // Fired when droid reached the destination and stopped on its own CALL_KEY_PRESSED, // Allows to process key presses, mainly for debug purposes + CALL_VTOL_RETARGET, // VTOL is out of targets } SCR_CALLBACK_TYPES; // The table of user types for the compiler