Skip to content

Commit

Permalink
Teleport units next to Nexus Links
Browse files Browse the repository at this point in the history
We have the technology to transmit vehicles and people through electronic data streams. Lets place them next to the attacker so absorbed units don't get blown up instantly from former friends.
  • Loading branch information
KJeff01 committed Dec 1, 2023
1 parent bb5d641 commit f4b5e19
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
22 changes: 18 additions & 4 deletions src/droid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2425,8 +2425,7 @@ static bool canFitDroid(UDWORD x, UDWORD y)
}

/// find a tile for which the function will return true
bool pickATileGen(UDWORD *x, UDWORD *y, UBYTE numIterations,
bool (*function)(UDWORD x, UDWORD y))
bool pickATileGen(UDWORD *x, UDWORD *y, UBYTE numIterations, bool (*function)(UDWORD x, UDWORD y))
{
return pickATileGenThreat(x, y, numIterations, -1, -1, function);
}
Expand Down Expand Up @@ -3198,7 +3197,7 @@ bool standardSensorDroid(const DROID *psDroid)
// Give a droid from one player to another - used in Electronic Warfare and multiplayer.
// Got to destroy the droid and build another since there are too many complications otherwise.
// Returns the droid created.
DROID *giftSingleDroid(DROID *psD, UDWORD to, bool electronic)
DROID *giftSingleDroid(DROID *psD, UDWORD to, bool electronic, Vector2i pos)
{
CHECK_DROID(psD);
ASSERT_OR_RETURN(nullptr, !isDead(psD), "Cannot gift dead unit");
Expand Down Expand Up @@ -3236,8 +3235,23 @@ DROID *giftSingleDroid(DROID *psD, UDWORD to, bool electronic)
// make the old droid vanish (but is not deleted until next tick)
adjustDroidCount(psD, -1);
vanishDroid(psD);
// Pick coordinates of the new droid if damaged electronically
Position newPos = Position(psD->pos.x, psD->pos.y, 0);
if (electronic)
{
unsigned int pickX = map_coord(pos.x);
unsigned int pickY = map_coord(pos.y);
if (pickATileGen(&pickX, &pickY, LOOK_FOR_EMPTY_TILE, zonedPAT) != NO_FREE_TILE)
{
newPos = Position(world_coord(pickX), world_coord(pickY), 0);
}
else
{
newPos = Position(pos.x, pos.y, 0); //Meld with the attacker if we must
}
}
// create a new droid
psNewDroid = reallyBuildDroid(&sTemplate, Position(psD->pos.x, psD->pos.y, 0), to, false, psD->rot);
psNewDroid = reallyBuildDroid(&sTemplate, newPos, to, false, psD->rot);
ASSERT_OR_RETURN(nullptr, psNewDroid, "Unable to build unit");

addDroid(psNewDroid, apsDroidLists);
Expand Down
2 changes: 1 addition & 1 deletion src/droid.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ bool cbSensorDroid(const DROID *psDroid);
bool standardSensorDroid(const DROID *psDroid);

// give a droid from one player to another - used in Electronic Warfare and multiplayer
DROID *giftSingleDroid(DROID *psD, UDWORD to, bool electronic = false);
DROID *giftSingleDroid(DROID *psD, UDWORD to, bool electronic = false, Vector2i pos = {0, 0});

/// Calculates the electronic resistance of a droid based on its experience level
SWORD droidResistance(const DROID *psDroid);
Expand Down
2 changes: 1 addition & 1 deletion src/structure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5685,7 +5685,7 @@ bool electronicDamage(BASE_OBJECT *psTarget, UDWORD damage, UBYTE attackPlayer)
addEffect(&pos, EFFECT_EXPLOSION, EXPLOSION_TYPE_FLAMETHROWER, false, nullptr, 0, gameTime - deltaGameTime);
}
}
if (!isDead(psDroid) && !giftSingleDroid(psDroid, attackPlayer, true))
if (!isDead(psDroid) && !giftSingleDroid(psDroid, attackPlayer, true, g_pProjLastAttacker->pos.xy()))
{
// droid limit reached, recycle
// don't check for transporter/mission coz multiplayer only issue.
Expand Down

0 comments on commit f4b5e19

Please sign in to comment.