Skip to content

Commit

Permalink
synch: Add some temporary debug info.
Browse files Browse the repository at this point in the history
Refs ticket:4785.
  • Loading branch information
Cyp committed Sep 9, 2018
1 parent 93a457c commit 99222df
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 55 deletions.
11 changes: 6 additions & 5 deletions doc/js-campaign.md
Expand Up @@ -146,6 +146,8 @@ artifact will be placed instantly. Artifact description is a JavaScript
object with the following fields:

* ```tech``` The technology to grant when the artifact is recovered.
Note that this can be made into an array to make artifacts give out
more than one technology, if desired.
On __let me win__ cheat, all technologies stored in the artifacts
managed by this function are automatically granted.
Additionally, this function would call special event callbacks if they are
Expand Down Expand Up @@ -339,10 +341,6 @@ or a POSITION-like object.

Print campaign order as string, useful for debugging.

## camSortByHealth(object 1, object 2)

Use this to sort an array of objects by health value.

## camSetFactories(factories)

Tell ```libcampaign.js``` to manage a certain set of enemy factories.
Expand Down Expand Up @@ -479,7 +477,10 @@ A means to not auto group some droids.
## camPlayVideos(videos)

If videos is an array, queue up all of them for immediate playing. This
function will play one video sequence should one be provided.
function will play one video sequence should one be provided. Also,
should a sound file be in a string (pcvX.ogg) __camEnqueueVideos() will recognize it
as a sound to play before a video. Of which is only supported when passed as
an array.

## camAreaEvent(label, function(droid))

Expand Down
5 changes: 5 additions & 0 deletions doc/js-events.md
Expand Up @@ -126,6 +126,11 @@ An event that is run every time a structure is produced. The droid parameter is
if the structure was built by a droid. It is not triggered for building theft
(check ```eventObjectTransfer``` for that).

## eventStructureDemolish(structure[, droid])

An event that is run every time a structure begins to be demolished. This does
not trigger again if the structure is partially demolished.

## eventStructureReady(structure)

An event that is run every time a structure is ready to perform some
Expand Down
10 changes: 8 additions & 2 deletions doc/js-functions.md
Expand Up @@ -757,9 +757,15 @@ take care only to define sync requests that can be validated against cheating. (
Replace one texture with another. This can be used to for example give buildings on a specific tileset different
looks, or to add variety to the looks of droids in campaign missions. (3.2+ only)

## fireWeaponAtLoc(x, y, weapon_name)
## fireWeaponAtLoc(weapon, x, y[, player])

Fires a weapon at the given coordinates (3.3+ only).
Fires a weapon at the given coordinates (3.3+ only). The player is who owns the projectile.
Please use fireWeaponAtObj() to damage objects as multiplayer and campaign
may have different friendly fire logic for a few weapons (like the lassat).

## fireWeaponAtObj(weapon, game object[, player])

Fires a weapon at a game object (3.3+ only). The player is who owns the projectile.

## changePlayerColour(player, colour)

Expand Down
83 changes: 35 additions & 48 deletions src/structure.cpp
Expand Up @@ -236,7 +236,7 @@ bool isBlueprint(const BASE_OBJECT *psObject)

void initStructLimits()
{
for (int i = 0; i < numStructureStats; i++)
for (unsigned i = 0; i < numStructureStats; ++i)
{
memset(asStructureStats[i].curCount, 0, sizeof(asStructureStats[i].curCount));
}
Expand Down Expand Up @@ -420,13 +420,13 @@ size_t sizeOfArray(const T(&)[ N ])
bool loadStructureStats(WzConfig &ini)
{
std::map<WzString, STRUCTURE_TYPE> structType;
for (int i = 0; i < sizeOfArray(map_STRUCTURE_TYPE); i++)
for (unsigned i = 0; i < sizeOfArray(map_STRUCTURE_TYPE); ++i)
{
structType.emplace(WzString::fromUtf8(map_STRUCTURE_TYPE[i].string), map_STRUCTURE_TYPE[i].value);
}

std::map<WzString, STRUCT_STRENGTH> structStrength;
for (int i = 0; i < sizeOfArray(map_STRUCT_STRENGTH); i++)
for (unsigned i = 0; i < sizeOfArray(map_STRUCT_STRENGTH); ++i)
{
structStrength.emplace(WzString::fromUtf8(map_STRUCT_STRENGTH[i].string), map_STRUCT_STRENGTH[i].value);
}
Expand Down Expand Up @@ -551,7 +551,7 @@ bool loadStructureStats(WzConfig &ini)
std::vector<WzString> weapons = ini.value("weapons").toWzStringList();
ASSERT_OR_RETURN(false, weapons.size() <= MAX_WEAPONS, "Too many weapons are attached to structure '%s'. Maximum is %d", getID(psStats), MAX_WEAPONS);
psStats->numWeaps = weapons.size();
for (int j = 0; j < psStats->numWeaps; j++)
for (unsigned j = 0; j < psStats->numWeaps; ++j)
{
WzString weaponsID = weapons[j].trimmed();
int weapon = getCompFromName(COMP_WEAPON, weaponsID);
Expand All @@ -572,7 +572,7 @@ bool loadStructureStats(WzConfig &ini)

/* get global dummy stat pointer - GJ */
g_psStatDestroyStruct = nullptr;
for (int iID = 0; iID < numStructureStats; iID++)
for (unsigned iID = 0; iID < numStructureStats; ++iID)
{
if (asStructureStats[iID].type == REF_DEMOLISH)
{
Expand Down Expand Up @@ -782,7 +782,7 @@ void structureBuild(STRUCTURE *psStruct, DROID *psDroid, int buildPoints, int bu
psStruct->body = std::max<int>(psStruct->body + deltaBody, 1);

//check if structure is built
if (buildPoints > 0 && psStruct->currentBuildPts >= (SDWORD)psStruct->pStructureType->buildPoints)
if (buildPoints > 0 && psStruct->currentBuildPts >= psStruct->pStructureType->buildPoints)
{
buildingComplete(psStruct);

Expand Down Expand Up @@ -2374,6 +2374,7 @@ static bool structPlaceDroid(STRUCTURE *psStructure, DROID_TEMPLATE *psTempl, DR
}
else
{
syncDebug("Droid placement failed");
*ppsDroid = nullptr;
}
return false;
Expand Down Expand Up @@ -2452,7 +2453,7 @@ int getMaxConstructors(int player)

bool IsPlayerDroidLimitReached(int player)
{
unsigned int numDroids = getNumDroids(player) + getNumMissionDroids(player) + getNumTransporterDroids(player);
int numDroids = getNumDroids(player) + getNumMissionDroids(player) + getNumTransporterDroids(player);
return numDroids >= getMaxDroids(player);
}

Expand Down Expand Up @@ -2507,7 +2508,6 @@ bool CheckHaltOnMaxUnitsReached(STRUCTURE *psStructure)

static void aiUpdateStructure(STRUCTURE *psStructure, bool isMission)
{
BASE_STATS *pSubject = nullptr;
UDWORD pointsToAdd;//, iPower;
RESEARCH *pResearch;
UDWORD structureMode = 0;
Expand Down Expand Up @@ -2695,6 +2695,7 @@ static void aiUpdateStructure(STRUCTURE *psStructure, bool isMission)
* determine the subject stats (for research or manufacture)
* or base object (for repair) or update power levels for resourceExtractor
*/
BASE_STATS *pSubject = nullptr;
switch (psStructure->pStructureType->type)
{
case REF_RESEARCH:
Expand Down Expand Up @@ -3036,12 +3037,9 @@ static void aiUpdateStructure(STRUCTURE *psStructure, bool isMission)
}

//electronic warfare affects the functionality of some structures in multiPlayer
if (bMultiPlayer)
if (bMultiPlayer && psStructure->resistance < (int)structureResistance(psStructure->pStructureType, psStructure->player))
{
if (psStructure->resistance < structureResistance(psStructure->pStructureType, psStructure->player))
{
return;
}
return;
}

int researchIndex = pSubject->ref - REF_RESEARCH_START;
Expand Down Expand Up @@ -3124,50 +3122,44 @@ static void aiUpdateStructure(STRUCTURE *psStructure, bool isMission)
psFactory = &psStructure->pFunctionality->factory;

//if on hold don't do anything
syncDebug("timeStartHold = %u", psFactory->timeStartHold); //TODO Remove after #4785 is fixed.
if (psFactory->timeStartHold)
{
return;
}

//electronic warfare affects the functionality of some structures in multiPlayer
if (bMultiPlayer)
syncDebug("resistance = %d", psStructure->resistance); //TODO Remove after #4785 is fixed.
if (bMultiPlayer && psStructure->resistance < (int)structureResistance(psStructure->pStructureType, psStructure->player))
{
if (psStructure->resistance < structureResistance(psStructure->pStructureType, psStructure->player))
{
return;
}
return;
}

syncDebug("timeStarted = %d", psFactory->timeStarted); //TODO Remove after #4785 is fixed.
if (psFactory->timeStarted == ACTION_START_TIME)
{
// also need to check if a command droid's group is full

// If the factory commanders group is full - return
if (IsFactoryCommanderGroupFull(psFactory))
{
return;
}

if (CheckHaltOnMaxUnitsReached(psStructure) == true)
if (IsFactoryCommanderGroupFull(psFactory) || CheckHaltOnMaxUnitsReached(psStructure))
{
return;
}
}

/*must be enough power so subtract that required to build*/
if (psFactory->timeStarted == ACTION_START_TIME)
{
//set the time started
psFactory->timeStarted = gameTime;
}

syncDebug("buildPointsRemaining = %d", psFactory->buildPointsRemaining); //TODO Remove after #4785 is fixed.
if (psFactory->buildPointsRemaining > 0)
{
int progress = gameTimeAdjustedAverage(getBuildingProductionPoints(psStructure));
if (psFactory->buildPointsRemaining == calcTemplateBuild(psFactory->psSubject) && progress > 0)
syncDebug("calcTemplateBuild(psSubject) = %d", calcTemplateBuild(psFactory->psSubject)); //TODO Remove after #4785 is fixed.
if ((unsigned)psFactory->buildPointsRemaining == calcTemplateBuild(psFactory->psSubject) && progress > 0)
{
// We're just starting to build, check for power.
bool haveEnoughPower = requestPowerFor(psStructure, calcTemplatePower(psFactory->psSubject));
syncDebug("haveEnoughPower = %d", haveEnoughPower); //TODO Remove after #4785 is fixed.
if (!haveEnoughPower)
{
progress = 0;
Expand All @@ -3177,8 +3169,11 @@ static void aiUpdateStructure(STRUCTURE *psStructure, bool isMission)
}

//check for manufacture to be complete
syncDebug("IsFactoryCommanderGroupFull(psFactory) = %d", IsFactoryCommanderGroupFull(psFactory)); //TODO Remove after #4785 is fixed.
syncDebug("CheckHaltOnMaxUnitsReached(psStructure) = %d", CheckHaltOnMaxUnitsReached(psStructure)); //TODO Remove after #4785 is fixed.
if ((psFactory->buildPointsRemaining <= 0) && !IsFactoryCommanderGroupFull(psFactory) && !CheckHaltOnMaxUnitsReached(psStructure))
{
syncDebug("isMission = %d", isMission); //TODO Remove after #4785 is fixed.
if (isMission)
{
// put it in the mission list
Expand Down Expand Up @@ -3240,13 +3235,10 @@ static void aiUpdateStructure(STRUCTURE *psStructure, bool isMission)
}

//don't do anything if the resistance is low in multiplayer
if (bMultiPlayer)
if (bMultiPlayer && psStructure->resistance < (int)structureResistance(psStructure->pStructureType, psStructure->player))
{
if (psStructure->resistance < structureResistance(psStructure->pStructureType, psStructure->player))
{
objTrace(psStructure->id, "Resistance too low for repair");
return;
}
objTrace(psStructure->id, "Resistance too low for repair");
return;
}

psDroid->body += gameTimeAdjustedAverage(getBuildingRepairPoints(psStructure));
Expand Down Expand Up @@ -5922,15 +5914,10 @@ void repairFacilityReward(UBYTE losingPlayer, UBYTE rewardPlayer)
/*makes the losing players tiles/structures/features visible to the reward player*/
void hqReward(UBYTE losingPlayer, UBYTE rewardPlayer)
{
STRUCTURE *psStruct;
FEATURE *psFeat;
DROID *psDroid;
UDWORD x, y, i;

// share exploration info - pretty useless but perhaps a nice touch?
for (x = 0; x < mapWidth; x++)
for (int y = 0; y < mapHeight; ++y)
{
for (y = 0; y < mapHeight; y++)
for (int x = 0; x < mapWidth; ++x)
{
MAPTILE *psTile = mapTile(x, y);
if (TEST_TILE_VISIBLE(losingPlayer, psTile))
Expand All @@ -5941,9 +5928,9 @@ void hqReward(UBYTE losingPlayer, UBYTE rewardPlayer)
}

//struct
for (i = 0; i < MAX_PLAYERS; i++)
for (int i = 0; i < MAX_PLAYERS; ++i)
{
for (psStruct = apsStructLists[i]; psStruct != nullptr; psStruct = psStruct->psNext)
for (STRUCTURE *psStruct = apsStructLists[i]; psStruct != nullptr; psStruct = psStruct->psNext)
{
if (psStruct->visible[losingPlayer] && !psStruct->died)
{
Expand All @@ -5952,7 +5939,7 @@ void hqReward(UBYTE losingPlayer, UBYTE rewardPlayer)
}

//feature
for (psFeat = apsFeatureLists[i]; psFeat != nullptr; psFeat = psFeat->psNext)
for (FEATURE *psFeat = apsFeatureLists[i]; psFeat != nullptr; psFeat = psFeat->psNext)
{
if (psFeat->visible[losingPlayer])
{
Expand All @@ -5961,7 +5948,7 @@ void hqReward(UBYTE losingPlayer, UBYTE rewardPlayer)
}

//droids.
for (psDroid = apsDroidLists[i]; psDroid != nullptr; psDroid = psDroid->psNext)
for (DROID *psDroid = apsDroidLists[i]; psDroid != nullptr; psDroid = psDroid->psNext)
{
if (psDroid->visible[losingPlayer] || psDroid->player == losingPlayer)
{
Expand Down Expand Up @@ -6770,7 +6757,7 @@ STRUCTURE *giftSingleStructure(STRUCTURE *psStructure, UBYTE attackPlayer, bool
STRUCTURE_STATS *psType, *psModule;
UDWORD x, y;
UBYTE capacity = 0, originalPlayer;
SWORD buildPoints = 0, i;
SWORD buildPoints = 0;
bool bPowerOn;
UWORD direction;

Expand Down Expand Up @@ -6811,7 +6798,7 @@ STRUCTURE *giftSingleStructure(STRUCTURE *psStructure, UBYTE attackPlayer, bool
orderDroid(psCurr, DORDER_STOP, ModeImmediate);
break;
}
for (i = 0; i < psCurr->numWeaps; i++)
for (unsigned i = 0; i < psCurr->numWeaps; ++i)
{
if (psCurr->psActionTarget[i] == psStructure)
{
Expand Down

0 comments on commit 99222df

Please sign in to comment.