Move random oil drum placement to rules.js
parent
904edbd94e
commit
d289598813
|
@ -8,6 +8,7 @@
|
|||
|
||||
var lastHitTime = 0;
|
||||
var cheatmode = false;
|
||||
var maxOilDrums = 0;
|
||||
|
||||
function setupGame()
|
||||
{
|
||||
|
@ -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++)
|
||||
{
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -977,12 +977,6 @@ bool stageOneInitialise(void)
|
|||
return false;
|
||||
}
|
||||
|
||||
/* Initialise the movement system */
|
||||
if (!moveInitialise())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!proj_InitSystem())
|
||||
{
|
||||
return false;
|
||||
|
|
36
src/move.cpp
36
src/move.cpp
|
@ -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);
|
||||
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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!
|
||||
|
||||
|
|
Loading…
Reference in New Issue