Unify the two completely different subsystems for droids picking up oil barrels and droids picking up artefacts.

Fixes a desynch on picking up artefacts.
master
Cyp 2010-12-08 17:29:39 +01:00
parent e39b23a437
commit f6867f8775
5 changed files with 75 additions and 82 deletions

View File

@ -529,14 +529,17 @@ bool removeFeature(FEATURE *psDel)
}
}
if(psDel->psStats->subType == FEAT_GEN_ARTE)
if (psDel->psStats->subType == FEAT_GEN_ARTE || psDel->psStats->subType == FEAT_OIL_DRUM)
{
pos.x = psDel->pos.x;
pos.z = psDel->pos.y;
pos.y = map_Height(pos.x,pos.z);
pos.y = map_Height(pos.x, pos.z) + 30;
addEffect(&pos,EFFECT_EXPLOSION,EXPLOSION_TYPE_DISCOVERY,false,NULL,0);
scoreUpdateVar(WD_ARTEFACTS_FOUND);
intRefreshScreen();
if (psDel->psStats->subType == FEAT_GEN_ARTE)
{
scoreUpdateVar(WD_ARTEFACTS_FOUND);
intRefreshScreen();
}
}
if (psDel->psStats->subType == FEAT_GEN_ARTE || psDel->psStats->subType == FEAT_OIL_RESOURCE)

View File

@ -176,6 +176,9 @@
// How fast vtols 'skid'
#define VTOL_SKID_DECEL 600
static uint32_t oilTimer = 0;
static unsigned drumCount = 0;
/* Function prototypes */
static void moveUpdatePersonModel(DROID *psDroid, SDWORD speed, uint16_t direction);
@ -202,6 +205,9 @@ const char *moveDescription(MOVE_STATUS status)
*/
BOOL moveInitialise(void)
{
oilTimer = 0;
drumCount = 0;
return true;
}
@ -2305,14 +2311,39 @@ static void movePlayAudio( DROID *psDroid, BOOL bStarted, BOOL bStoppedBefore, S
}
static bool pickupOilDrum(int toPlayer, int fromPlayer)
{
addPower(toPlayer, OILDRUM_POWER); // give power
if (toPlayer == selectedPlayer)
{
CONPRINTF(ConsoleString, (ConsoleString, _("You found %u power in an oil drum."), OILDRUM_POWER));
}
// TODO This code is weird. When should new oil drums actually be added?
// fromPlayer == ANYPLAYER seems to mean that the drum was not pre-placed on the map.
if (bMultiPlayer && fromPlayer == ANYPLAYER && toPlayer == selectedPlayer)
{
// when player finds oil, we init the timer, and flag that we need a drum
if (!oilTimer)
{
oilTimer = gameTime;
}
// if player finds more than one drum (before timer expires), then we tack on ~50 sec to timer.
if (drumCount++ == 0)
{
oilTimer += GAME_TICKS_PER_SEC * 50;
}
}
return true;
}
// called when a droid moves to a new tile.
// use to pick up oil, etc..
static void checkLocalFeatures(DROID *psDroid)
{
BASE_OBJECT *psObj;
static int oilTimer = 0;
static bool GenerateDrum = false;
static uint8_t drumCount = 0;
// NOTE: Why not do this for AI units also?
if (!isHumanPlayer(psDroid->player) || isVtolDroid(psDroid)) // VTOLs can't pick up features!
@ -2325,45 +2356,40 @@ static void checkLocalFeatures(DROID *psDroid)
gridStartIterate(psDroid->pos.x, psDroid->pos.y, DROIDDIST);
for (psObj = gridIterate(); psObj != NULL; psObj = gridIterate())
{
if (psObj->type != OBJ_FEATURE || ((FEATURE *)psObj)->psStats->subType != FEAT_OIL_DRUM || psObj->died)
bool pickedUp = false;
if (psObj->type == OBJ_FEATURE && !psObj->died)
{
// Object is not a living oil drum.
switch (((FEATURE *)psObj)->psStats->subType)
{
case FEAT_OIL_DRUM:
pickedUp = pickupOilDrum(psDroid->player, psObj->player);
break;
case FEAT_GEN_ARTE:
pickedUp = pickupArtefact(psDroid->player, psObj->player);
break;
default:
break;
}
}
if (!pickedUp)
{
// Object is not a living oil drum or artefact.
continue;
}
addPower(psDroid->player, OILDRUM_POWER); // give power
turnOffMultiMsg(true);
removeFeature((FEATURE *)psObj); // remove artifact+.
turnOffMultiMsg(false);
if (psDroid->player == selectedPlayer)
{
CONPRINTF(ConsoleString, (ConsoleString, _("You found %u power in an oil drum."), OILDRUM_POWER));
}
// TODO This code is weird. When should new oil drums actually be added?
if (bMultiPlayer && psObj->player == ANYPLAYER && psDroid->player == selectedPlayer)
{
// when player finds oil, we init the timer, and flag that we need a drum
if (!oilTimer)
{
oilTimer = gameTime2;
GenerateDrum = true;
}
// if player finds more than one drum (before timer expires), then we tack on ~50 sec to timer.
if(drumCount++)
{
oilTimer += GAME_TICKS_PER_SEC * 50;
}
}
}
// once they found a oil drum, we then wait ~600 secs before we pop up new one(s).
if (((oilTimer + GAME_TICKS_PER_SEC * 600u) < realTime) && GenerateDrum)
if (oilTimer + GAME_TICKS_PER_SEC * 600u < gameTime && drumCount > 0)
{
addOilDrum(drumCount);
oilTimer = 0;
drumCount = 0;
GenerateDrum = false;
}
}

View File

@ -733,13 +733,12 @@ void recvMultiPlayerRandomArtifacts(NETQUEUE queue)
}
// ///////////////////////////////////////////////////////////////
void giftArtifact(UDWORD owner, UDWORD x, UDWORD y)
bool pickupArtefact(int toPlayer, int fromPlayer)
{
PLAYER_RESEARCH *pR = asPlayerResList[selectedPlayer];
if (owner < MAX_PLAYERS)
if (fromPlayer < MAX_PLAYERS && bMultiPlayer)
{
PLAYER_RESEARCH *pO = asPlayerResList[owner];
PLAYER_RESEARCH *pR = asPlayerResList[toPlayer];
PLAYER_RESEARCH *pO = asPlayerResList[fromPlayer];
int topic;
for (topic = numResearch - 1; topic >= 0; topic--)
@ -752,8 +751,10 @@ void giftArtifact(UDWORD owner, UDWORD x, UDWORD y)
&& asResearch[topic].researchPoints)
{
MakeResearchPossible(&pR[topic]);
CONPRINTF(ConsoleString,(ConsoleString,_("You Discover Blueprints For %s"),
getName(asResearch[topic].pName)));
if (toPlayer == selectedPlayer)
{
CONPRINTF(ConsoleString,(ConsoleString,_("You Discover Blueprints For %s"), getName(asResearch[topic].pName)));
}
break;
}
// Invalid topic
@ -763,48 +764,13 @@ void giftArtifact(UDWORD owner, UDWORD x, UDWORD y)
}
}
}
audio_QueueTrack(ID_SOUND_ARTIFACT_RECOVERED);
return true;
}
}
// ///////////////////////////////////////////////////////////////
void processMultiPlayerArtifacts(void)
{
static UDWORD lastCall;
FEATURE *pF,*pFN;
UDWORD x,y,pl;
Position position;
BOOL found=false;
// only do this every now and again.
if(lastCall > gameTime)lastCall= 0;
if ( (gameTime - lastCall) <2000)
{
return;
}
lastCall = gameTime;
for(pF = apsFeatureLists[0]; pF ; pF = pFN)
{
pFN = pF->psNext;
// artifacts
if(pF->psStats->subType == FEAT_GEN_ARTE)
{
found = objectInRange((BASE_OBJECT *)apsDroidLists[selectedPlayer], pF->pos.x, pF->pos.y, (TILE_UNITS+(TILE_UNITS/3)) );
if(found)
{
position = pF->pos; // Add an effect
addEffect(&position,EFFECT_EXPLOSION,EXPLOSION_TYPE_DISCOVERY,false,NULL,false);
x = pF->pos.x;
y = pF->pos.y;
pl= pF->player;
removeFeature(pF); // remove artifact+ send info.
giftArtifact(pl,x,y); // reward player.
pF->player = 0;
audio_QueueTrack( ID_SOUND_ARTIFACT_RECOVERED );
}
}
}
return false;
}
/* Ally team members with each other */

View File

@ -42,11 +42,10 @@ extern BOOL recvGift (NETQUEUE queue);
extern void technologyGiveAway (const STRUCTURE* pS);
extern void recvMultiPlayerRandomArtifacts (NETQUEUE queue);
extern void addMultiPlayerRandomArtifacts (uint8_t quantity, FEATURE_TYPE type);
extern void processMultiPlayerArtifacts (void);
extern void recvMultiPlayerFeature (NETQUEUE queue);
extern void sendMultiPlayerFeature(FEATURE_TYPE type, uint32_t x, uint32_t y, uint32_t id);
extern void giftArtifact (UDWORD owner,UDWORD x,UDWORD y);
bool pickupArtefact(int toPlayer, int fromPlayer);
extern BOOL addOilDrum (uint8_t count);
void giftPower (uint8_t from, uint8_t to, uint32_t amount, BOOL send);
extern void giftRadar (uint8_t from, uint8_t to, BOOL send);

View File

@ -207,7 +207,6 @@ BOOL multiPlayerLoop(void)
UBYTE joinCount;
sendCheck(); // send some checking info if possible
processMultiPlayerArtifacts(); // process artifacts
joinCount =0;
for(i=0;i<MAX_PLAYERS;i++)