Skip to content

Commit a1368d3

Browse files
committed
addition of more scripts, most importantly Bool evaluateRelationPlayerValueArea
1 parent 16d9b35 commit a1368d3

9 files changed

Lines changed: 604 additions & 12 deletions

File tree

GeneralsMD/Code/GameEngine/Include/Common/Player.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,7 @@ class Player : public Snapshot
451451
std::vector<const ThingTemplate*> m_lastFrameKills;
452452
std::vector<const ThingTemplate*> m_lastFrameDeaths;
453453
Bool m_lostUnitThisFrame;
454+
454455
virtual Bool computeSuperweaponTargetEconomy(const SpecialPowerTemplate* power, Coord3D* retPos, Int playerNdx, Real weaponRadius);
455456
void buildBySuppliesAngle(Int minimumCash, const AsciiString& thingName, Real angle);
456457
void buildSpecificBuildingNearestTeamAngle(const AsciiString& thingName, const Team* team, Real angle);

GeneralsMD/Code/GameEngine/Include/Common/Team.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ typedef struct {
115115
AsciiString unitThingName;
116116
} TCreateUnitsInfo;
117117

118-
enum { MAX_GENERIC_SCRIPTS = 16 };
118+
enum { MAX_GENERIC_SCRIPTS = 32 };
119119

120120
// ------------------------------------------------------------------------
121121
/// This is the info for creating reinforcement and AI teams.
@@ -345,7 +345,16 @@ class Team : public MemoryPoolObject,
345345
Bool noneInside(PolygonTrigger *pTrigger, UnsignedInt whichToConsider) const; ///< No members are in the area.
346346

347347
Object * tryToRecruit(const ThingTemplate *, const Coord3D *teamHome, Real maxDist); ///< Try to recruit the closest unit of this thing type. Return true if successful.
348+
//-------------------------------------------------------------------------------------------------
349+
//------------------------------------ @CLP_AI TEAM ADDITIONS -------------------------------------
350+
//-------------------------------------------------------------------------------------------------
348351

352+
std::vector<const ThingTemplate*> m_lastFrameDeaths;
353+
Bool m_lostUnitThisFrame;
354+
355+
//-------------------------------------------------------------------------------------------------
356+
//---------------------------------- @CLP_AI TEAM ADDITIONS END -----------------------------------
357+
//-------------------------------------------------------------------------------------------------
349358
/**
350359
return our relationship with the other team.
351360
this is done as follows:

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,8 @@ class ScriptActions : public ScriptActionsInterface
408408
void doTeamMeet(const AsciiString& teamName);
409409
void doTeamMeetKindOf(const AsciiString& teamName, Int kindOf);
410410
void doTeamMeetType(const AsciiString& teamName, const AsciiString& objectType);
411+
void doTeamMeetTeam(const AsciiString& teamNameA, const AsciiString& teamNameB);
412+
void doTeamMoveToTeam(const AsciiString& teamNameA, const AsciiString& teamNameB);
411413
void doTeamMoveAwayFromRelation(const AsciiString& teamName, Real feet, Int relationType);
412414
void doTeamMoveTowardsRelation(const AsciiString& teamName, Real feet, Int relationType);
413415
void doUnitMoveAwayFromRelation(const AsciiString& unitName, Real feet, Int relationType);
@@ -432,10 +434,11 @@ class ScriptActions : public ScriptActionsInterface
432434
void doTeamGarrisonMaxEach(const AsciiString& teamName, Int maxAmount);
433435
void doPlayerGarrisonEqually(const AsciiString& playerName, Int amount);
434436
void doTeamGarrisonEqually(const AsciiString& teamName, Int amount);
437+
void doTeamLoadAllTransportsEvenly(const AsciiString& teamName);
435438

436439
void doSkirmishFireSpecialPowerAtMostCostEconomy(const AsciiString& player, const AsciiString& specialPower);
437440

438-
441+
// @-TanSo-: 42 additions
439442
//-------------------------------------------------------------------------------------------------
440443
//----------------------------- @CLP_AI SCRIPT ACTION ADDITIONS END -------------------------------
441444
//-------------------------------------------------------------------------------------------------

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,13 @@ class ScriptConditions : public ScriptConditionsInterface
205205
Bool evaluatePointControlled(Player* player, const Coord3D& point, Real radius); //@-TanSo-: helper method for evaluate(Relation)MapControl.
206206
Bool evaluateMapControl(Parameter* pPlayerParm, Parameter* pComparisonParm, Real value);
207207
Bool evaluateRelationMapControl(Parameter* pPlayerParm, Int relationType, Parameter* pComparisonParm, Real value);
208+
Bool evaluateTeamLostType(Parameter* pTeamParm, Parameter* objectType);
209+
Bool evaluateTeamLostUnit(Parameter* pTeamParm);
210+
Bool evaluatePlayerSightedRelationType(Parameter* pPlayerParm, Int relationType, Parameter* pObjectType);
211+
Bool evaluateRelationPlayerSightedRelationType(Parameter* pPlayerParm, Int playerRelationType, Int relationType, Parameter* pObjecType);
212+
Bool evaluateRelationPlayerValueArea(Condition* pCondition, Parameter* pPlayerParm, Int relationType, Parameter* pComparisonParm, Int value, Parameter* pTriggerParm);
208213

214+
// @-TanSo-: 24 additions, 1 helper method
209215
//-------------------------------------------------------------------------------------------------
210216
//---------------------------- @CLP_AI SCRIPT CONDITION ADDITIONS END -----------------------------
211217
//-------------------------------------------------------------------------------------------------

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

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ class ScriptAction : public MemoryPoolObject // This is the action class.
597597
TEAM_MOVE_AWAY_FROM_RELATION_TYPE, ///< A team moves <Real> feet into the opposite direction of a <relation> <objectType>.
598598
TEAM_MOVE_TOWARDS_RELATION, ///< A team moves <Real> feet towards a <relation> unit.
599599
TEAM_MOVE_TOWARDS_RELATION_TYPE, ///< A team moves <Real> feet towards a <relation> <objectType>.
600-
TEAM_MEET, ///< Set a team to meet at their center point.
600+
TEAM_MEET, ///< Set a team to meet at its center point.
601601
TEAM_MEET_AT_KINDOF, ///< Set a team to meet at the center point of all units with <kindOf>.
602602
TEAM_MEET_AT_TYPE, ///< Set a team to meet at the center point of all units with <objectType>.
603603
TEAM_USE_COMMAND_BUTTON_ABILITY_WITH_TYPE, ///< Set all units with an object type in a team to use a command button ability.
@@ -610,6 +610,9 @@ class ScriptAction : public MemoryPoolObject // This is the action class.
610610
/*TODO*/TEAM_USE_SECONDARY_WEAPON, ///< A team starts using their secondary weapon.
611611
TEAM_GARRISON_BUILDINGS_WITH_MAX_NUMBER, ///< A team garrisons nearby buildings with <int> infrantry each.
612612
TEAM_GARRISON_NUMBER_BUILDINGS, ///< A team equally garrisons <int> buildings with all available infantry.
613+
TEAM_MOVE_TO_TEAM, ///< Set a team to move towards another team.
614+
TEAM_MEET_TEAM, ///< Set a team to meet at the center point of another team.
615+
TEAM_LOAD_EVENLY, ///< A team loads evenly into their transport units.
613616

614617
UNIT_MOVE_RELATIVE, ///< Set a unit to move relative to its own position.
615618
UNIT_MOVE_NEAREST_BELONGING_TO_PLAYER, ///< Set a unit to move towards the nearest object type belonging to a player.
@@ -1085,7 +1088,7 @@ class Condition : public MemoryPoolObject // This is the conditional class.
10851088
//-------------------------------------------------------------------------------------------------
10861089
//------------------------------ @CLP_AI SCRIPT CONDITION ADDITIONS -------------------------------
10871090
//-------------------------------------------------------------------------------------------------
1088-
KD_RATIO, // True if the KD Ratio is <comparison> a value
1091+
KD_RATIO, // True if the KD Ratio is <comparison> a value.
10891092
COMPARE_COUNTERS, // True if Counter A is <comparison> Counter B.
10901093

10911094
PLAYER_RELATION_FACTION, // True if one or more of the player's <relation> co-players are a faction.
@@ -1101,17 +1104,24 @@ class Condition : public MemoryPoolObject // This is the conditional class.
11011104
STARTING_CASH_COMPARE, // True if the player's starting cash is <comparison> <Int>.
11021105
CLOSEST_ENEMY_DISTANCE, // True if the enemy's closest unit is <comparison> feet away.
11031106
PLAYER_HUNTED, // True if the player has construction units || command center || supply stash.
1104-
PLAYER_LOST_TYPE_AREA, // True if the player has lost an object of <type> in <area>
1107+
PLAYER_LOST_TYPE_AREA, // True if the player has lost an object of <type> in <area>.
11051108
PLAYER_LOST_UNIT, // True if the player has lost a unit.
1106-
TEAM_SIGHTED_RELATION_TYPE, // True if a team has sighted a <relation> unit of <type>
1109+
TEAM_SIGHTED_RELATION_TYPE, // True if a team has sighted a <relation> unit of <type>.
1110+
TEAM_LOST_TYPE, // True if a team has lost an object of <type>.
1111+
TEAM_LOST_UNIT, // True if a team has lost a unit.
11071112

1108-
PLAYER_DESTROYED_ENEMY_TYPE, // True if a player has destroyed an enemy unit of <type>
1113+
PLAYER_DESTROYED_ENEMY_TYPE, // True if a player has destroyed an enemy unit of <type>.
11091114
PLAYER_DESTROYED_ENEMY_UNIT, // True if a player has destroyed an enemy unit.
11101115

11111116
/*TODO*/RELATION_UNDER_ATTACK, // True if a(n) <relation> player is under attack.
11121117

11131118
PLAYER_MAPCONTROL, // True if a player's map control is <comparison> <Real>.
11141119
PLAYER_RELATION_MAPCONTROL, // True if all <relation> player's map control is <comparison> <Real>.
1120+
1121+
PLAYER_SIGHTED_RELATION_TYPE, // True if a player has sighted a <relation> unit of <type>.
1122+
RELATION_PLAYER_SIGHTED_RELATION_TYPE, // True if a <relation> player has sighted a <relation> unit of <type>.
1123+
RELATION_PLAYER_VALUE_AREA, // True if the value of a <relation> player in an area is <comparison> <Int>.
1124+
11151125
//-------------------------------------------------------------------------------------------------
11161126
//---------------------------- @CLP_AI SCRIPT CONDITION ADDITIONS END -----------------------------
11171127
//-------------------------------------------------------------------------------------------------

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2977,7 +2977,6 @@ void Object::scoreTheKill( const Object *victim )
29772977
if (victimController)
29782978
{
29792979
victimController->getScoreKeeper()->addObjectLost(victim);
2980-
victimController->m_lostUnitThisFrame = TRUE;
29812980
}
29822981

29832982
Relationship r = getRelationship(victim);
@@ -3014,7 +3013,14 @@ void Object::scoreTheKill( const Object *victim )
30143013
// @-TanSo-: Add the kills and deaths to our vectors so we can check on them in scripts
30153014
controller->m_lastFrameKills.push_back(tt);
30163015
victimController->m_lastFrameDeaths.push_back(tt);
3016+
victimController->m_lostUnitThisFrame = TRUE;
30173017

3018+
Team* team = const_cast<Team*>(victim->getTeam());
3019+
if (team)
3020+
{
3021+
team->m_lastFrameDeaths.push_back(tt);
3022+
team->m_lostUnitThisFrame = TRUE;
3023+
}
30183024
}
30193025

30203026
//-------------------------------------------------------------------------------------------------

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

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7352,6 +7352,115 @@ void ScriptActions::doTeamMeetType(const AsciiString& teamName, const AsciiStrin
73527352
theGroup->groupMoveToPosition(&pos, false, CMD_FROM_SCRIPT);
73537353
}
73547354

7355+
//-------------------------------------------------------------------------------------------------
7356+
void ScriptActions::doTeamMeetTeam(const AsciiString& teamNameA, const AsciiString& teamNameB)
7357+
{
7358+
Team* pTeamA = TheScriptEngine->getTeamNamed(teamNameA);
7359+
if (!pTeamA) return;
7360+
7361+
Team* pTeamB = TheScriptEngine->getTeamNamed(teamNameB);
7362+
if (!pTeamB) return;
7363+
7364+
AIGroupPtr theGroupA = TheAI->createGroup();
7365+
if (!theGroupA) {
7366+
return;
7367+
}
7368+
7369+
AIGroupPtr theGroupB = TheAI->createGroup();
7370+
if (!theGroupB) {
7371+
return;
7372+
}
7373+
7374+
#if RETAIL_COMPATIBLE_AIGROUP
7375+
pTeamA->getTeamAsAIGroup(theGroupA);
7376+
pTeamB->getTeamAsAIGroup(theGroupB);
7377+
#else
7378+
pTeamA->getTeamAsAIGroup(theGroupA.Peek());
7379+
pTeamB->getTeamAsAIGroup(theGroupB.Peek());
7380+
#endif
7381+
7382+
Int count = 0;
7383+
Coord3D pos;
7384+
pos.x = pos.y = pos.z = 0;
7385+
7386+
//@-TanSo-: Get the center point for each of the two teams and average them together
7387+
for (DLINK_ITERATOR<Object> iter = pTeamA->iterate_TeamMemberList(); !iter.done(); iter.advance())
7388+
{
7389+
Object* obj = iter.cur();
7390+
if (!obj) continue;
7391+
7392+
Coord3D objPos = *obj->getPosition();
7393+
pos.x += objPos.x;
7394+
pos.y += objPos.y;
7395+
pos.z += objPos.z;
7396+
count++;
7397+
}
7398+
for (DLINK_ITERATOR<Object> iter = pTeamB->iterate_TeamMemberList(); !iter.done(); iter.advance())
7399+
{
7400+
Object* obj = iter.cur();
7401+
if (!obj) continue;
7402+
7403+
Coord3D objPos = *obj->getPosition();
7404+
pos.x += objPos.x;
7405+
pos.y += objPos.y;
7406+
pos.z += objPos.z;
7407+
count++;
7408+
}
7409+
7410+
if (count == 0) return; // empty team.
7411+
pos.x /= count;
7412+
pos.y /= count;
7413+
pos.z /= count;
7414+
7415+
theGroupA->groupMoveToPosition(&pos, false, CMD_FROM_SCRIPT);
7416+
theGroupB->groupMoveToPosition(&pos, false, CMD_FROM_SCRIPT);
7417+
}
7418+
7419+
//-------------------------------------------------------------------------------------------------
7420+
void ScriptActions::doTeamMoveToTeam(const AsciiString& teamNameA, const AsciiString& teamNameB)
7421+
{
7422+
Team* pTeamA = TheScriptEngine->getTeamNamed(teamNameA);
7423+
if (!pTeamA) return;
7424+
7425+
Team* pTeamB = TheScriptEngine->getTeamNamed(teamNameB);
7426+
if (!pTeamB) return;
7427+
7428+
AIGroupPtr theGroupA = TheAI->createGroup();
7429+
if (!theGroupA) {
7430+
return;
7431+
}
7432+
7433+
#if RETAIL_COMPATIBLE_AIGROUP
7434+
pTeamA->getTeamAsAIGroup(theGroupA);
7435+
#else
7436+
pTeamA->getTeamAsAIGroup(theGroupA.Peek());
7437+
#endif
7438+
7439+
Int count = 0;
7440+
Coord3D pos;
7441+
pos.x = pos.y = pos.z = 0;
7442+
7443+
//@-TanSo-: Get the center point of the team
7444+
for (DLINK_ITERATOR<Object> iter = pTeamB->iterate_TeamMemberList(); !iter.done(); iter.advance())
7445+
{
7446+
Object* obj = iter.cur();
7447+
if (!obj) continue;
7448+
7449+
Coord3D objPos = *obj->getPosition();
7450+
pos.x += objPos.x;
7451+
pos.y += objPos.y;
7452+
pos.z += objPos.z;
7453+
count++;
7454+
}
7455+
7456+
if (count == 0) return; // empty team.
7457+
pos.x /= count;
7458+
pos.y /= count;
7459+
pos.z /= count;
7460+
7461+
theGroupA->groupMoveToPosition(&pos, false, CMD_FROM_SCRIPT);
7462+
}
7463+
73557464
//-------------------------------------------------------------------------------------------------
73567465
void ScriptActions::doTeamUseCommandButtonAbilityOnType(const AsciiString& teamName, const AsciiString& ability, const AsciiString& objectType)
73577466
{
@@ -8885,6 +8994,68 @@ void ScriptActions::doUnitMoveTowardsRelation(const AsciiString& unitName, Real
88858994
ai->aiMoveToPosition(&targetPos, CMD_FROM_SCRIPT);
88868995
}
88878996

8997+
//-------------------------------------------------------------------------------------------------
8998+
void ScriptActions::doTeamLoadAllTransportsEvenly(const AsciiString& teamName)
8999+
{
9000+
Team* theTeam = TheScriptEngine->getTeamNamed(teamName);
9001+
if (!theTeam) return;
9002+
9003+
std::vector<Object*> transports;
9004+
std::vector<Object*> units;
9005+
9006+
// collect transports and units
9007+
for (DLINK_ITERATOR<Object> iter = theTeam->iterate_TeamMemberList();
9008+
!iter.done();
9009+
iter.advance())
9010+
{
9011+
Object* obj = iter.cur();
9012+
if (!obj) continue;
9013+
9014+
if (obj->isKindOf(KINDOF_TRANSPORT))
9015+
{
9016+
ContainModuleInterface* cmi = obj->getContain();
9017+
if (cmi && cmi->getContainCount() < cmi->getContainMax())
9018+
transports.push_back(obj);
9019+
}
9020+
else if (obj->isKindOf(KINDOF_INFANTRY))
9021+
{
9022+
if (!obj->getContain())
9023+
units.push_back(obj);
9024+
}
9025+
}
9026+
9027+
if (transports.empty() || units.empty())
9028+
return;
9029+
9030+
// round robin assignment
9031+
size_t transportIndex = 0;
9032+
9033+
for (size_t i = 0; i < units.size(); ++i)
9034+
{
9035+
Object* unit = units[i];
9036+
9037+
// find next transport with free space
9038+
size_t attempts = 0;
9039+
while (attempts < transports.size())
9040+
{
9041+
Object* transport = transports[transportIndex];
9042+
ContainModuleInterface* cmi = transport->getContain();
9043+
9044+
if (cmi && cmi->getContainCount() < cmi->getContainMax())
9045+
{
9046+
AIUpdateInterface* ai = unit->getAIUpdateInterface();
9047+
if (ai)
9048+
ai->aiEnter(transport, CMD_FROM_SCRIPT);
9049+
9050+
transportIndex = (transportIndex + 1) % transports.size();
9051+
break;
9052+
}
9053+
9054+
transportIndex = (transportIndex + 1) % transports.size();
9055+
attempts++;
9056+
}
9057+
}
9058+
}
88889059
//-------------------------------------------------------------------------------------------------
88899060
//----------------------------- @CLP_AI SCRIPT ACTION ADDITIONS END -------------------------------
88909061
//-------------------------------------------------------------------------------------------------
@@ -10181,5 +10352,14 @@ void ScriptActions::executeAction( ScriptAction *pAction )
1018110352
case ScriptAction::UNIT_MOVE_TOWARDS_RELATION_TYPE:
1018210353
doUnitMoveTowardsRelationType(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getReal(), pAction->getParameter(2)->getInt(), pAction->getParameter(3)->getString());
1018310354
return;
10355+
case ScriptAction::TEAM_MOVE_TO_TEAM:
10356+
doTeamMoveToTeam(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString());
10357+
return;
10358+
case ScriptAction::TEAM_MEET_TEAM:
10359+
doTeamMeetTeam(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString());
10360+
return;
10361+
case ScriptAction::TEAM_LOAD_EVENLY:
10362+
doTeamLoadAllTransportsEvenly(pAction->getParameter(0)->getString());
10363+
return;
1018410364
}
1018510365
}

0 commit comments

Comments
 (0)