Skip to content

Commit 573850c

Browse files
author
-TanSo-
committed
Added 4 scripts
1 parent 60ae255 commit 573850c

5 files changed

Lines changed: 277 additions & 13 deletions

File tree

GeneralsMD/Code/GameEngine/Include/GameLogic/ScriptConditions.h

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,21 @@ class ScriptConditions : public ScriptConditionsInterface
178178
Bool evaluateSkirmishSupplySourceSafe(Condition *pCondition, Parameter *pSkirmishPlayerParm, Parameter *pMinAmountOfSupplies );
179179
Bool evaluateSkirmishSupplySourceAttacked(Parameter *pSkirmishPlayerParm );
180180
Bool evaluateSkirmishStartPosition(Parameter *pSkirmishPlayerParm, Parameter *startNdx );
181-
Bool evaluatePlayerRelation(const AsciiString& playerSrcName, Int relationType, const AsciiString& playerDstName);
182-
183181
// Stubs
184-
Bool evaluateMissionAttempts(Parameter *pPlayerParm, Parameter *pComparisonParm, Parameter *pAttemptsParm);
182+
Bool evaluateMissionAttempts(Parameter* pPlayerParm, Parameter* pComparisonParm, Parameter* pAttemptsParm);
185183

184+
//-------------------------------------------------------------------------------------------------
185+
//------------------------------- OUR SCRIPT CONDITION ADDITIONS --------------------------------
186+
//-------------------------------------------------------------------------------------------------
187+
188+
Bool evaluatePlayerRelation(const AsciiString& playerSrcName, Int relationType, const AsciiString& playerDstName);
189+
Bool evaluateEmptySpot(Parameter* pStartNdx);
190+
Bool evaluateNeighbouringSpot(Parameter* pPlayerParm, Parameter* pStartNdx);
191+
Bool evaluateNeighbouringSpotsEmpty(Parameter* pPlayerParm, Parameter* pComparisonParm, Int pCount);
192+
Bool evaluateClosestEnemyUnit(Parameter* pPlayerParm, Parameter* pComparisonParm, Int pDistanceParm);
193+
194+
//-------------------------------------------------------------------------------------------------
195+
//------------------------------ OUR SCRIPT CONDITION ADDITIONS END -------------------------------
196+
//-------------------------------------------------------------------------------------------------
186197

187198
};

GeneralsMD/Code/GameEngine/Include/GameLogic/Scripts.h

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -973,13 +973,20 @@ class Condition : public MemoryPoolObject // This is the conditional class.
973973

974974

975975

976-
977-
978-
RELATION_IS,
979-
980-
981-
982-
976+
//-------------------------------------------------------------------------------------------------
977+
//------------------------------- OUR SCRIPT CONDITION ADDITIONS --------------------------------
978+
//-------------------------------------------------------------------------------------------------
979+
980+
RELATION_IS, // True if the relation between two players is as specified.
981+
SPOT_EMPTY, // True if a specified spot is empty.
982+
SPOT_NEIGHBOURING, // True if the index of a specified spot is neighbouring the player.
983+
NEIGHBOURING_SPOTS_EMPTY, // True if <comparison> amount of neighbouring spots are empty.
984+
CLOSEST_ENEMY_UNIT_DISTANCE, // True if the distance to the closest enemy unit compares to a value.
985+
STARTING_CASH_COMPARE, // True if the player's starting cash compares to a value.
986+
987+
//-------------------------------------------------------------------------------------------------
988+
//------------------------------ OUR SCRIPT CONDITION ADDITIONS END -------------------------------
989+
//-------------------------------------------------------------------------------------------------
983990
NUM_ITEMS // Always the last condition.
984991
};
985992

GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptActions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6534,6 +6534,7 @@ void ScriptActions::doNamedSetTrainHeld( const AsciiString &locoName, const Bool
65346534
}
65356535

65366536

6537+
65376538
//-------------------------------------------------------------------------------------------------
65386539
/** Execute an action */
65396540
//-------------------------------------------------------------------------------------------------
@@ -7697,6 +7698,5 @@ void ScriptActions::executeAction( ScriptAction *pAction )
76977698
case ScriptAction::DISABLE_OBJECT_SOUND:
76987699
doEnableObjectSound(pAction->getParameter(0)->getString(), false);
76997700
return;
7700-
77017701
}
77027702
}

GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptConditions.cpp

Lines changed: 204 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2719,17 +2719,213 @@ Bool ScriptConditions::evaluatePlayerLostObjectType(Parameter *pPlayerParm, Para
27192719
}
27202720

27212721

2722+
2723+
2724+
2725+
//-------------------------------------------------------------------------------------------------
2726+
//------------------------------- OUR SCRIPT CONDITION ADDITIONS --------------------------------
2727+
//-------------------------------------------------------------------------------------------------
2728+
2729+
27222730
Bool ScriptConditions::evaluatePlayerRelation(const AsciiString& playerSrcName, Int relationType, const AsciiString& playerDstName)
27232731
{
27242732
Player* pPlayerSrcName = TheScriptEngine->getPlayerFromAsciiString(playerSrcName);
27252733
Player* pPlayerDstName = TheScriptEngine->getPlayerFromAsciiString(playerDstName);
27262734

2735+
if (!pPlayerSrcName || !pPlayerDstName) {
2736+
return false;
2737+
}
2738+
//use the default team to get an indirect relationship between players
27272739
Team* pTeamDst = pPlayerDstName->getDefaultTeam();
27282740

2729-
if (pPlayerSrcName->getRelationship(pTeamDst) == relationType) { return true; }
2741+
return pPlayerSrcName->getRelationship(pTeamDst) == relationType;
2742+
}
2743+
2744+
//-------------------------------------------------------------------------------------------------
2745+
Bool ScriptConditions::evaluateEmptySpot(Parameter* pStartNdx)
2746+
{
2747+
Int ndx = pStartNdx->getInt() - 1;
2748+
if (ndx >= 0)
2749+
{
2750+
Int pPlayerCount = ThePlayerList->getPlayerCount();
2751+
//iterate through all players
2752+
// i=2 because player 0 is "neutral" & player 1 is "PlyrCivilian".
2753+
// playerCount-1 to skip any possible "observer" player at the end.
2754+
for (int i = 2; i < pPlayerCount - 1; i++)
2755+
{
2756+
Player* pPlayers = ThePlayerList->getNthPlayer(i);
2757+
if (pPlayers->getMpStartIndex() == ndx)
2758+
{
2759+
return false;
2760+
}
2761+
}
2762+
return true;
2763+
}
27302764
return false;
27312765
}
27322766

2767+
//-------------------------------------------------------------------------------------------------
2768+
Bool ScriptConditions::evaluateNeighbouringSpot(Parameter* pPlayerParm, Parameter* pStartNdx)
2769+
{
2770+
Player* player = playerFromParam(pPlayerParm);
2771+
if (!player || pStartNdx->getInt() < 1 || pStartNdx->getInt() == player->getMpStartIndex() + 1) { return false; }
2772+
2773+
//format the waypoint name for this player's start position
2774+
AsciiString pSpot;
2775+
pSpot.format("Player_%d_Start", player->getMpStartIndex() + 1);
2776+
2777+
Waypoint* pWay = TheTerrainLogic->getWaypointByName(pSpot);
2778+
if (!pWay) { return false; }
2779+
2780+
//iterate through all player start waypoints to find the closest one
2781+
Coord3D pCoords = *pWay->getLocation();
2782+
Real minDist = FLT_MAX;
2783+
2784+
for (Waypoint* iWay = TheTerrainLogic->getFirstWaypoint(); iWay; iWay = iWay->getNext())
2785+
{
2786+
const AsciiString& name = iWay->getName();
2787+
if (name.startsWith("Player_") && name.endsWith("_Start"))
2788+
{
2789+
if (iWay != pWay)
2790+
{
2791+
Coord3D cCoords = *iWay->getLocation();
2792+
Real dx = pCoords.x - cCoords.x;
2793+
Real dy = pCoords.y - cCoords.y;
2794+
Real dist = sqrtf(dx * dx + dy * dy);
2795+
2796+
if (dist < minDist) { minDist = dist; }
2797+
}
2798+
}
2799+
}
2800+
//if the closest distance still is FLT_MAX, then this is no skirmish map.
2801+
if (minDist == FLT_MAX) { return false; }
2802+
2803+
// consider neighbouring if within 1.5 times the closest distance.
2804+
minDist *= 1.5f;
2805+
2806+
//create a Waypoint for the start position to check against
2807+
AsciiString targetName;
2808+
targetName.format("Player_%d_Start", pStartNdx->getInt());
2809+
Waypoint* target = TheTerrainLogic->getWaypointByName(targetName);
2810+
if (!target) { return false; }
2811+
2812+
Coord3D tCoords = *target->getLocation();
2813+
Real cX = pCoords.x - tCoords.x;
2814+
Real cY = pCoords.y - tCoords.y;
2815+
Real targetDist = sqrtf(cX * cX + cY * cY);
2816+
2817+
return targetDist <= minDist;
2818+
}
2819+
2820+
//-------------------------------------------------------------------------------------------------
2821+
Bool ScriptConditions::evaluateNeighbouringSpotsEmpty(Parameter* pPlayerParm, Parameter* pComparisonParm, Int pCountParm)
2822+
{
2823+
Player* player = playerFromParam(pPlayerParm);
2824+
Int playerCount = ThePlayerList->getPlayerCount();
2825+
if (!player || !playerCount) { return false; }
2826+
2827+
AsciiString pSpot;
2828+
pSpot.format("Player_%d_Start", player->getMpStartIndex() + 1);
2829+
Waypoint* pWay = TheTerrainLogic->getWaypointByName(pSpot);
2830+
if (!pWay) { return false; }
2831+
2832+
2833+
Coord3D pCoords = *pWay->getLocation();
2834+
Real minDist = FLT_MAX;
2835+
//iterate through all player start waypoints to find the closest one
2836+
for (Waypoint* iWay = TheTerrainLogic->getFirstWaypoint(); iWay; iWay = iWay->getNext())
2837+
{
2838+
const AsciiString& name = iWay->getName();
2839+
if (name.startsWith("Player_") && name.endsWith("_Start"))
2840+
{
2841+
if (iWay != pWay)
2842+
{
2843+
Coord3D cCoords = *iWay->getLocation();
2844+
Real dx = pCoords.x - cCoords.x;
2845+
Real dy = pCoords.y - cCoords.y;
2846+
Real dist = sqrtf(dx * dx + dy * dy);
2847+
if (dist < minDist)
2848+
{
2849+
minDist = dist;
2850+
}
2851+
}
2852+
}
2853+
}
2854+
2855+
std::vector<Waypoint*> neighbouringWaypoints;
2856+
2857+
// if the closest distance still is FLT_MAX, then this is no skirmish map.
2858+
if (minDist == FLT_MAX) { return false; }
2859+
2860+
// consider neighbouring if within 1.5 times the closest distance.
2861+
minDist *= 1.5f;
2862+
2863+
//find all neighbouring waypoints
2864+
for (Waypoint* iWay = TheTerrainLogic->getFirstWaypoint(); iWay; iWay = iWay->getNext())
2865+
{
2866+
const AsciiString& name = iWay->getName();
2867+
if (name.startsWith("Player_") && name.endsWith("_Start"))
2868+
{
2869+
if (iWay != pWay)
2870+
{
2871+
Coord3D cCoords = *iWay->getLocation();
2872+
Real dx = pCoords.x - cCoords.x;
2873+
Real dy = pCoords.y - cCoords.y;
2874+
Real dist = sqrtf(dx * dx + dy * dy);
2875+
if (dist <= minDist)
2876+
{
2877+
neighbouringWaypoints.push_back(iWay);
2878+
}
2879+
}
2880+
}
2881+
}
2882+
2883+
// Make sure that the newly found neighbouring starting points are *indeed* empty.
2884+
// i=2 because player 0 is "neutral" & player 1 is "PlyrCivilian".
2885+
// playerCount-1 to skip any possible "observer" player at the end.
2886+
for (int i = 2; i < playerCount - 1; i++) {
2887+
Int pIndex = ThePlayerList->getNthPlayer(i)->getMpStartIndex() + 1;
2888+
AsciiString tName;
2889+
tName.format("Player_%d_Start", pIndex);
2890+
2891+
for (int j = neighbouringWaypoints.size() - 1; j >= 0; j--) {
2892+
AsciiString sName = neighbouringWaypoints[j]->getName();
2893+
if (sName == tName) {
2894+
neighbouringWaypoints.erase(neighbouringWaypoints.begin() + j);
2895+
}
2896+
}
2897+
}
2898+
2899+
//compare the new size of the neighbouring EMPTY waypoints with the given count
2900+
switch (pComparisonParm->getInt())
2901+
{
2902+
case Parameter::LESS_THAN: return neighbouringWaypoints.size() < pCountParm;
2903+
case Parameter::LESS_EQUAL: return neighbouringWaypoints.size() <= pCountParm;
2904+
case Parameter::EQUAL: return neighbouringWaypoints.size() == pCountParm;
2905+
case Parameter::GREATER_EQUAL: return neighbouringWaypoints.size() >= pCountParm;
2906+
case Parameter::GREATER: return neighbouringWaypoints.size() > pCountParm;
2907+
case Parameter::NOT_EQUAL: return neighbouringWaypoints.size() != pCountParm;
2908+
}
2909+
return false;
2910+
}
2911+
2912+
//-------------------------------------------------------------------------------------------------
2913+
Bool ScriptConditions::evaluateClosestEnemyUnit(Parameter* pPlayerParm, Parameter* pComparisonParm, Int pDistanceParm)
2914+
{
2915+
Player* player = playerFromParam(pPlayerParm);
2916+
if (!player) { return false; }
2917+
return false;
2918+
}
2919+
2920+
2921+
//-------------------------------------------------------------------------------------------------
2922+
//------------------------------ OUR SCRIPT CONDITION ADDITIONS END -------------------------------
2923+
//-------------------------------------------------------------------------------------------------
2924+
2925+
2926+
2927+
2928+
27332929
//-------------------------------------------------------------------------------------------------
27342930
/** Evaluate a condition */
27352931
//-------------------------------------------------------------------------------------------------
@@ -2997,7 +3193,13 @@ Bool ScriptConditions::evaluateCondition( Condition *pCondition )
29973193

29983194
case Condition::RELATION_IS:
29993195
return evaluatePlayerRelation(pCondition->getParameter(0)->getString(), pCondition->getParameter(1)->getInt(), pCondition->getParameter(2)->getString());
3000-
3196+
case Condition::SPOT_EMPTY:
3197+
return evaluateEmptySpot(pCondition->getParameter(0));
3198+
case Condition::SPOT_NEIGHBOURING:
3199+
return evaluateNeighbouringSpot(pCondition->getParameter(0), pCondition->getParameter(1));
3200+
case Condition::NEIGHBOURING_SPOTS_EMPTY:
3201+
return evaluateNeighbouringSpotsEmpty(pCondition->getParameter(0), pCondition->getParameter(1), pCondition->getParameter(2)->getInt());
3202+
30013203
}
30023204
}
30033205

GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptEngine.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5236,6 +5236,14 @@ void ScriptEngine::init( void )
52365236
curTemplate->m_numUiStrings = 1;
52375237
curTemplate->m_uiStrings[0] = "Show Weather = ";
52385238

5239+
5240+
5241+
5242+
5243+
//-------------------------------------------------------------------------------------------------
5244+
//------------------------------- OUR SCRIPT CONDITION ADDITIONS --------------------------------
5245+
//-------------------------------------------------------------------------------------------------
5246+
52395247
curTemplate = &m_conditionTemplates[Condition::RELATION_IS];
52405248
curTemplate->m_internalName = "RELATION_IS";
52415249
curTemplate->m_uiName = "Alliance/Check the relation of two players.";
@@ -5248,6 +5256,42 @@ void ScriptEngine::init( void )
52485256
curTemplate->m_uiStrings[1] = "'s relation is ";
52495257
curTemplate->m_uiStrings[2] = " to ";
52505258

5259+
curTemplate = &m_conditionTemplates[Condition::SPOT_EMPTY];
5260+
curTemplate->m_internalName = "SPOT_EMPTY";
5261+
curTemplate->m_uiName = "Skirmish/Check whether spot is empty.";
5262+
curTemplate->m_numParameters = 1;
5263+
curTemplate->m_parameters[0] = Parameter::INT;
5264+
curTemplate->m_numUiStrings = 2;
5265+
curTemplate->m_uiStrings[0] = "Spot (Player_N_Start) ";
5266+
curTemplate->m_uiStrings[1] = " is not a starting point for any player.";
5267+
5268+
curTemplate = &m_conditionTemplates[Condition::SPOT_NEIGHBOURING];
5269+
curTemplate->m_internalName = "SPOT_NEIGHBOURING";
5270+
curTemplate->m_uiName = "Skirmish/Check whether spot is neighbouring the player.";
5271+
curTemplate->m_numParameters = 2;
5272+
curTemplate->m_parameters[0] = Parameter::SIDE;
5273+
curTemplate->m_parameters[1] = Parameter::INT;
5274+
curTemplate->m_numUiStrings = 2;
5275+
curTemplate->m_uiStrings[0] = "Player ";
5276+
curTemplate->m_uiStrings[1] = " is neighbouring spot (Player_N_Start) ";
5277+
5278+
curTemplate = &m_conditionTemplates[Condition::NEIGHBOURING_SPOTS_EMPTY];
5279+
curTemplate->m_internalName = "NEIGHBOURING_SPOTS_EMPTY";
5280+
curTemplate->m_uiName = "Skirmish/Check if N number of neighbouring spots are empty.";
5281+
curTemplate->m_numParameters = 3;
5282+
curTemplate->m_parameters[0] = Parameter::SIDE;
5283+
curTemplate->m_parameters[1] = Parameter::COMPARISON;
5284+
curTemplate->m_parameters[2] = Parameter::INT;
5285+
curTemplate->m_numUiStrings = 4;
5286+
curTemplate->m_uiStrings[0] = "Player ";
5287+
curTemplate->m_uiStrings[1] = " has ";
5288+
curTemplate->m_uiStrings[2] = " ";
5289+
curTemplate->m_uiStrings[3] = " empty neighbouring spots.";
5290+
5291+
//-------------------------------------------------------------------------------------------------
5292+
//------------------------------ OUR SCRIPT CONDITION ADDITIONS END -------------------------------
5293+
//-------------------------------------------------------------------------------------------------
5294+
52515295

52525296
Int i;
52535297
for (i=0; i<Condition::NUM_ITEMS; i++) {

0 commit comments

Comments
 (0)