Apply patch #1474 - Fix sync issues involving alt-orders.

git-svn-id: https://warzone2100.svn.sourceforge.net/svnroot/warzone2100/trunk@9777 4a71c877-e1ca-e34f-864e-861f7616d084
master
Guangcong Luo 2010-02-10 23:15:32 +00:00 committed by Git SVN Gateway
parent 88b7093f95
commit 815725c039
5 changed files with 55 additions and 81 deletions

View File

@ -1729,34 +1729,9 @@ static inline void dealWithLMBDroid(DROID* psDroid, SELECTION_TYPE selection)
else if ((keyDown(KEY_LALT) || keyDown(KEY_RALT)) && ownDroid)
{
// try to attack your own unit
DROID* psCurr;
for (psCurr = apsDroidLists[selectedPlayer]; psCurr; psCurr = psCurr->psNext)
{
if ((psCurr != psDroid) && // can't attack yourself
(psCurr->selected))
{
if ((psCurr->droidType == DROID_WEAPON) ||
(psCurr->droidType == DROID_CYBORG) ||
(psCurr->droidType == DROID_CYBORG_SUPER) ||
(psCurr->droidType == DROID_COMMAND))
{
orderDroidObj(psCurr, DORDER_ATTACK, (BASE_OBJECT*)psDroid);
FeedbackOrderGiven();
}
else if (psCurr->droidType == DROID_SENSOR)
{
orderDroidObj(psCurr, DORDER_OBSERVE, (BASE_OBJECT*)psDroid);
FeedbackOrderGiven();
}
else if (psCurr->droidType == DROID_REPAIR ||
psCurr->droidType == DROID_CYBORG_REPAIR)
{
orderDroidObj(psCurr, DORDER_DROIDREPAIR, (BASE_OBJECT*)psDroid);
FeedbackOrderGiven();
}
}
}
orderSelectedObjAdd(selectedPlayer, (BASE_OBJECT*)psDroid, ctrlShiftDown());
FeedbackOrderGiven();
driveDisableTactical();
}
else if (psDroid->droidType == DROID_TRANSPORTER)
{
@ -1949,7 +1924,7 @@ static inline void dealWithLMBStructure(STRUCTURE* psStructure, SELECTION_TYPE s
if (!bRightClickOrders) printStructureInfo(psStructure);
/* Got to be built. Also, you can't 'select' derricks */
if ( (psStructure->status == SS_BUILT) &&
if (!keyDown(KEY_LALT) && !keyDown(KEY_RALT) && (psStructure->status == SS_BUILT) &&
(psStructure->pStructureType->type != REF_RESOURCE_EXTRACTOR) && ownStruct)
{
if (bRightClickOrders)
@ -2016,39 +1991,13 @@ static inline void dealWithLMBStructure(STRUCTURE* psStructure, SELECTION_TYPE s
/* Establish new one */
psStructure->selected = true;
}
if ((keyDown(KEY_LALT) || keyDown(KEY_RALT)) && ownStruct)
bSensorAssigned = false;
orderSelectedObjAdd(selectedPlayer, (BASE_OBJECT*)psStructure, ctrlShiftDown());
FeedbackOrderGiven();
if (bSensorAssigned)
{
DROID* psCurr;
// try to attack your own structure
for (psCurr = apsDroidLists[selectedPlayer]; psCurr; psCurr = psCurr->psNext)
{
if (psCurr->selected)
{
if ((psCurr->droidType == DROID_WEAPON) || cyborgDroid(psCurr) ||
(psCurr->droidType == DROID_COMMAND))
{
orderDroidObj(psCurr, DORDER_ATTACK, (BASE_OBJECT*)psStructure);
FeedbackOrderGiven();
}
else if (psCurr->droidType == DROID_SENSOR)
{
orderDroidObj(psCurr, DORDER_OBSERVE, (BASE_OBJECT*)psStructure);
FeedbackOrderGiven();
}
}
}
}
else
{
bSensorAssigned = false;
orderSelectedObjAdd(selectedPlayer, (BASE_OBJECT*)psStructure, ctrlShiftDown());
FeedbackOrderGiven();
if (bSensorAssigned)
{
clearSelection();
assignSensorTarget((BASE_OBJECT *)psStructure);
}
clearSelection();
assignSensorTarget((BASE_OBJECT *)psStructure);
}
driveDisableTactical();
@ -2583,7 +2532,7 @@ static void dealWithRMB( void )
for (psDroid = apsDroidLists[selectedPlayer]; psDroid; psDroid=psDroid->psNext)
{
if (psDroid->selected &&
chooseOrderObj(psDroid, psClickedOn) == DORDER_DEMOLISH)
chooseOrderObj(psDroid, psClickedOn, false) == DORDER_DEMOLISH)
{
bDemolish = true;
break;

View File

@ -46,7 +46,8 @@
#include "multirecv.h"
#define ANYPLAYER 99
#define UNKNOWN 99
#define DORDER_UNKNOWN 99
#define DORDER_UNKNOWN_ALT 100
// ////////////////////////////////////////////////////////////////////////////
// Local Prototypes
@ -642,14 +643,14 @@ typedef enum {
* Droid Group/selection orders.
* Minimises comms by sending orders for whole groups, rather than each droid
*/
BOOL SendGroupOrderSelected(uint8_t player, uint32_t x, uint32_t y, const BASE_OBJECT* psObj)
BOOL SendGroupOrderSelected(uint8_t player, uint32_t x, uint32_t y, const BASE_OBJECT* psObj, BOOL altOrder)
{
if (!bMultiMessages)
return true;
NETbeginEncode(NET_GROUPORDER, NET_ALL_PLAYERS);
{
DROID_ORDER order = UNKNOWN;
DROID_ORDER order = (altOrder?DORDER_UNKNOWN_ALT:DORDER_UNKNOWN);
BOOL subType = (psObj) ? true : false, cmdOrder = false;
DROID* psDroid;
uint8_t droidCount;
@ -844,7 +845,7 @@ BOOL recvGroupOrder()
NETend();
/* Check if the order is valid */
if (order != UNKNOWN && ((subType && !validOrderForObj(order)) || (!subType && !validOrderForLoc(order))))
if (order != DORDER_UNKNOWN && order != DORDER_UNKNOWN_ALT && ((subType && !validOrderForObj(order)) || (!subType && !validOrderForLoc(order))))
{
debug(LOG_ERROR, "Invalid group order received from %d, [%s : p%d]", NETgetSource(),
isHumanPlayer(player) ? "Human" : "AI", player);
@ -1026,9 +1027,13 @@ static void ProcessDroidOrder(DROID *psDroid, DROID_ORDER order, uint32_t x, uin
}
// If no specific order was passed work one out based on the location
if (order == UNKNOWN)
if (order == DORDER_UNKNOWN)
{
order = chooseOrderLoc(psDroid, x, y);
order = chooseOrderLoc(psDroid, x, y, false);
}
else if (order == DORDER_UNKNOWN_ALT)
{
order = chooseOrderLoc(psDroid, x, y, true);
}
turnOffMultiMsg(true);
@ -1072,11 +1077,14 @@ static void ProcessDroidOrder(DROID *psDroid, DROID_ORDER order, uint32_t x, uin
}
// If we didn't sepcify an order, then pick one
if (order == UNKNOWN)
if (order == DORDER_UNKNOWN)
{
order = chooseOrderObj(psDroid, psObj);
order = chooseOrderObj(psDroid, psObj, false);
}
else if (order == DORDER_UNKNOWN_ALT)
{
order = chooseOrderObj(psDroid, psObj, true);
}
turnOffMultiMsg(true);
orderDroidObj(psDroid, order, psObj);
turnOffMultiMsg(false);

View File

@ -171,7 +171,7 @@ extern BOOL SendDestroyDroid (const DROID* psDroid);
extern BOOL SendDemolishFinished(STRUCTURE *psS,DROID *psD);
extern BOOL SendDroidInfo (const DROID* psDroid, DROID_ORDER order, uint32_t x, uint32_t y, const BASE_OBJECT* psObj);
extern BOOL SendDroidMove (const DROID* psDroid, uint32_t x, uint32_t y, BOOL formation);
extern BOOL SendGroupOrderSelected(uint8_t player, uint32_t x, uint32_t y, const BASE_OBJECT* psObj);
extern BOOL SendGroupOrderSelected(uint8_t player, uint32_t x, uint32_t y, const BASE_OBJECT* psObj, BOOL altOrder);
extern BOOL SendCmdGroup (DROID_GROUP *psGroup, UWORD x, UWORD y, BASE_OBJECT *psObj);
extern BOOL SendGroupOrderGroup(const DROID_GROUP* psGroup, DROID_ORDER order, uint32_t x, uint32_t y, const BASE_OBJECT* psObj);

View File

@ -2695,7 +2695,7 @@ static BOOL orderDroidObjAdd(DROID *psDroid, DROID_ORDER order, BASE_OBJECT *psO
}
/* Choose an order for a droid from a location */
DROID_ORDER chooseOrderLoc(DROID *psDroid, UDWORD x,UDWORD y)
DROID_ORDER chooseOrderLoc(DROID *psDroid, UDWORD x,UDWORD y, BOOL altOrder)
{
DROID_ORDER order = DORDER_NONE;
PROPULSION_TYPE propulsion = getPropulsionStats(psDroid)->propulsionType;
@ -2718,7 +2718,7 @@ DROID_ORDER chooseOrderLoc(DROID *psDroid, UDWORD x,UDWORD y)
}
// scout if alt was pressed
if (keyDown(KEY_LALT) || keyDown(KEY_RALT))
if (altOrder)
{
order = DORDER_SCOUT;
if (isVtolDroid(psDroid))
@ -2769,7 +2769,7 @@ void orderSelectedLoc(uint32_t player, uint32_t x, uint32_t y, bool add)
return;
}
if (!add && bMultiMessages && SendGroupOrderSelected((UBYTE)player,x,y,NULL) )
if (!add && bMultiMessages && SendGroupOrderSelected((UBYTE)player,x,y,NULL,keyDown(KEY_LALT) || keyDown(KEY_RALT)) )
{ // turn off multiplay messages,since we've send a group one instead.
turnOffMultiMsg(true);
}
@ -2798,7 +2798,7 @@ void orderSelectedLoc(uint32_t player, uint32_t x, uint32_t y, bool add)
continue;
}
order = chooseOrderLoc(psCurr, x, y);
order = chooseOrderLoc(psCurr, x, y, (keyDown(KEY_LALT) || keyDown(KEY_RALT)));
// see if the order can be added to the list
if (order != DORDER_NONE && !(add && orderDroidLocAdd(psCurr, order, x, y)))
{
@ -2813,7 +2813,7 @@ void orderSelectedLoc(uint32_t player, uint32_t x, uint32_t y, bool add)
/* Choose an order for a droid from an object */
DROID_ORDER chooseOrderObj(DROID *psDroid, BASE_OBJECT *psObj)
DROID_ORDER chooseOrderObj(DROID *psDroid, BASE_OBJECT *psObj, BOOL altOrder)
{
DROID_ORDER order;
STRUCTURE *psStruct;
@ -2840,6 +2840,23 @@ DROID_ORDER chooseOrderObj(DROID *psDroid, BASE_OBJECT *psObj)
return DORDER_NONE;
}
if (altOrder && (psObj->type == OBJ_DROID || psObj->type == OBJ_STRUCTURE) && psDroid->player == psObj->player)
{
if ((psDroid->droidType == DROID_WEAPON) || cyborgDroid(psDroid) ||
(psDroid->droidType == DROID_COMMAND))
{
return DORDER_ATTACK;
}
else if (psDroid->droidType == DROID_SENSOR)
{
return DORDER_OBSERVE;
}
else if ((psDroid->droidType == DROID_REPAIR ||
psDroid->droidType == DROID_CYBORG_REPAIR) && psObj->type == OBJ_DROID)
{
return DORDER_REPAIR;
}
}
//check for transporters first
if (psObj->type == OBJ_DROID && ((DROID *)psObj)->droidType == DROID_TRANSPORTER
&& psObj->player == psDroid->player)
@ -3123,7 +3140,7 @@ void orderSelectedObjAdd(UDWORD player, BASE_OBJECT *psObj, BOOL add)
DROID *psCurr, *psDemolish;
DROID_ORDER order;
if (!add && bMultiMessages && SendGroupOrderSelected((UBYTE)player,0,0,psObj) )
if (!add && bMultiMessages && SendGroupOrderSelected((UBYTE)player,0,0,psObj,keyDown(KEY_LALT) || keyDown(KEY_RALT)) )
{ // turn off multiplay messages,since we've send a group one instead.
turnOffMultiMsg(true);
}
@ -3146,7 +3163,7 @@ void orderSelectedObjAdd(UDWORD player, BASE_OBJECT *psObj, BOOL add)
{
if (psCurr->selected)
{
order = chooseOrderObj(psCurr, psObj);
order = chooseOrderObj(psCurr, psObj, (keyDown(KEY_LALT) || keyDown(KEY_RALT)));
if (order == DORDER_DEMOLISH && player == selectedPlayer)
{
psDemolish = psCurr;

View File

@ -268,8 +268,8 @@ static inline void removeDroidOrderTarget(DROID *psDroid, SDWORD idx)
psDroid->asOrderList[idx].psOrderTarget = NULL;
}
extern DROID_ORDER chooseOrderLoc(DROID *psDroid, UDWORD x,UDWORD y);
extern DROID_ORDER chooseOrderObj(DROID *psDroid, BASE_OBJECT *psObj);
extern DROID_ORDER chooseOrderLoc(DROID *psDroid, UDWORD x,UDWORD y, BOOL altOrder);
extern DROID_ORDER chooseOrderObj(DROID *psDroid, BASE_OBJECT *psObj, BOOL altOrder);
#ifdef __cplusplus
}