Skip to content

Commit

Permalink
Move random oil drum placement to rules.js
Browse files Browse the repository at this point in the history
  • Loading branch information
haoNoQ committed Dec 22, 2013
1 parent 904edbd commit d289598
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 94 deletions.
64 changes: 64 additions & 0 deletions data/mp/multiplay/skirmish/rules.js
Expand Up @@ -8,6 +8,7 @@

var lastHitTime = 0;
var cheatmode = false;
var maxOilDrums = 0;

function setupGame()
{
Expand Down Expand Up @@ -47,6 +48,14 @@ function eventGameInit()
receiveAllEvents(true);
setupGame();

// always at least one oil drum, and one more for every 64x64 tiles of map area
maxOilDrums = (mapWidth * mapHeight) >> 12; // replace float division with shift for sync-safety
for (var i = 0; i < maxOilDrums; ++i)
{
queue("placeOilDrum", 10000 * i);
}


hackNetOff();
for (var playnum = 0; playnum < maxPlayers; playnum++)
{
Expand Down Expand Up @@ -397,3 +406,58 @@ function eventChat(from, to, message)
console("Made player " + from + "'s units SUPERIOR!");
}
}

function placeOilDrum()
{
var drums = enumFeature(-1, "OilDrum").length;
if (drums >= maxOilDrums)
{
return;
}

var x = syncRandom(mapWidth - 20) + 10;
var y = syncRandom(mapHeight - 20) + 10;

// see if the random position is valid
var occupied = (enumRange(x, y, 2, ALL_PLAYERS, false).length > 0);
var unreachable = true;
for (var i = 0; i < maxPlayers; ++i)
{
if (propulsionCanReach("wheeled01", x, y, startPositions[i].x, startPositions[i].y))
{
unreachable = false;
break;
}
}
var terrain = terrainType(x, y);
if (terrain == TER_WATER || terrain == TER_CLIFFFACE)
{
unreachable = true;
}
if (occupied || unreachable)
{
// try again in a different position after 1 second
queue("placeOilDrum", 1000);
return;
}

addFeature("OilDrum", x, y);
}

function eventPickup(feature, droid)
{
if (feature.stattype == OIL_DRUM)
{
var delay;
// generate Geom(1/6) distribution for oil drum respawn delay
for (delay = 0; ; ++delay)
{
if (syncRandom(6) == 0)
{
break;
}
}
// amounts to 10 minutes average respawn time
queue("placeOilDrum", delay * 120000);
}
}
6 changes: 0 additions & 6 deletions src/init.cpp
Expand Up @@ -977,12 +977,6 @@ bool stageOneInitialise(void)
return false;
}

/* Initialise the movement system */
if (!moveInitialise())
{
return false;
}

if (!proj_InitSystem())
{
return false;
Expand Down
36 changes: 0 additions & 36 deletions src/move.cpp
Expand Up @@ -104,9 +104,6 @@
#define EXTRA_PRECISION (1 << EXTRA_BITS)


static uint32_t oilTimer = 0;
static unsigned drumCount = 0;

/* Function prototypes */
static void moveUpdatePersonModel(DROID *psDroid, SDWORD speed, uint16_t direction);

Expand All @@ -128,16 +125,6 @@ const char *moveDescription(MOVE_STATUS status)
return "Error"; // satisfy compiler
}

/** Initialise the movement system
*/
bool moveInitialise(void)
{
oilTimer = 0;
drumCount = 0;

return true;
}

/** Set a target location in world coordinates for a droid to move to
* @return true if the routing was successful, if false then the calling code
* should not try to route here again for a while
Expand Down Expand Up @@ -2077,21 +2064,6 @@ static bool pickupOilDrum(int toPlayer, int fromPlayer)
CONPRINTF(ConsoleString, (ConsoleString, _("You found %u power in an oil drum."), OILDRUM_POWER));
}

// fromPlayer == ANYPLAYER seems to mean that the drum was not pre-placed on the map.
if (bMultiPlayer && fromPlayer == ANYPLAYER)
{
// 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;
}

Expand Down Expand Up @@ -2141,14 +2113,6 @@ static void checkLocalFeatures(DROID *psDroid)
removeFeature((FEATURE *)psObj); // remove artifact+.
turnOffMultiMsg(false);
}

// 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 < gameTime && drumCount > 0)
{
addOilDrum(drumCount);
oilTimer = 0;
drumCount = 0;
}
}


Expand Down
3 changes: 0 additions & 3 deletions src/move.h
Expand Up @@ -27,9 +27,6 @@
#include "objectdef.h"
#include "fpath.h"

/* Initialise the movement system */
extern bool moveInitialise(void);

/* Set a target location for a droid to move to - returns a bool based on if there is a path to the destination (true if there is a path)*/
extern bool moveDroidTo(DROID *psDroid, UDWORD x, UDWORD y, FPATH_MOVETYPE moveType = FMT_MOVE);

Expand Down
47 changes: 0 additions & 47 deletions src/multigifts.cpp
Expand Up @@ -663,53 +663,6 @@ void recvMultiPlayerFeature(NETQUEUE queue)
}
}

bool addOilDrum(uint8_t count)
{
syncDebug("Adding %d oil drums.", count);

int featureIndex;
for (featureIndex = 0; featureIndex < numFeatureStats && asFeatureStats[featureIndex].subType != FEAT_OIL_DRUM; ++featureIndex) {}
if (featureIndex >= numFeatureStats)
{
debug(LOG_WARNING, "No oil drum feature!");
return false; // Return value ignored.
}

for (unsigned n = 0; n < count; ++n)
{
uint32_t x, y;
for (int i = 0; i < 3; ++i) // try three times
{
// Between 10 and mapwidth - 10
x = gameRand(mapWidth - 20) + 10;
y = gameRand(mapHeight - 20) + 10;

if (pickATileGen(&x, &y, LOOK_FOR_EMPTY_TILE, zonedPAT))
{
break;
}
x = INVALID_XY;
}
if (x == INVALID_XY)
{
syncDebug("Did not find location for oil drum.");
debug(LOG_FEATURE, "Unable to find a free location.");
continue;
}
FEATURE *pF = buildFeature(&asFeatureStats[featureIndex], world_coord(x), world_coord(y), false);
if (pF)
{
pF->player = ANYPLAYER;
syncDebugFeature(pF, '+');
}
else
{
debug(LOG_ERROR, "Couldn't build oil drum?");
}
}
return true;
}

// ///////////////////////////////////////////////////////////////
bool pickupArtefact(int toPlayer, int fromPlayer)
{
Expand Down
1 change: 0 additions & 1 deletion src/multigifts.h
Expand Up @@ -39,7 +39,6 @@ extern void recvMultiPlayerFeature (NETQUEUE queue);
extern void sendMultiPlayerFeature(FEATURE_TYPE type, uint32_t x, uint32_t y, uint32_t id);

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);

Expand Down
1 change: 0 additions & 1 deletion src/multiopt.cpp
Expand Up @@ -394,7 +394,6 @@ static bool gameInit(void)
{
playerCount += NetPlay.players[index].ai >= 0 || NetPlay.players[index].allocated;
}
addOilDrum(playerCount * 2); // Calculating playerCount instead of using NetPlay.playercount, since the latter seems to be 0 for non-hosts.

playerResponding(); // say howdy!

Expand Down

0 comments on commit d289598

Please sign in to comment.