Skip to content

Commit

Permalink
1.3.12: aggressiveness options being effective with the new AI
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasvinbr committed Jul 9, 2018
1 parent 77f242e commit 3bad89d
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 22 deletions.
2 changes: 0 additions & 2 deletions GangAI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public override void Update()
//everyone tries to expand before anything else;
//that way, we don't end up with isolated gangs or some kind of peace
myZones = ZoneManager.instance.GetZonesControlledByGang(watchedGang.name);
myZones.Sort(ZoneManager.CompareZonesByValue);
TryExpand();

switch (watchedGang.upgradeTendency)
Expand Down Expand Up @@ -126,7 +125,6 @@ void TryUpgradeGuns()
{
watchedGang.moneyAvailable -= ModOptions.instance.GetBuyableWeaponByHash(chosenWeapon).price;
watchedGang.gangWeaponHashes.Add(chosenWeapon);
watchedGang.gangWeaponHashes.Sort(watchedGang.CompareGunsByPrice);
GangManager.instance.SaveGangData(false);
}
}
Expand Down
59 changes: 43 additions & 16 deletions GangManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,16 @@ public GangManager()
CreateNewEnemyGang();
}

SetUpGangRelations();
SetUpAllGangs();

timeLastReward = ModCore.curGameTime;

}
/// <summary>
/// basically makes all gangs hate each other
/// basically sets relationship groups for all gangs, makes them hate each other and starts the AI for enemy gangs.
/// also runs a few consistency checks on the gangs, like if their stats are conforming to the limits defined in modoptions
/// </summary>
void SetUpGangRelations()
void SetUpAllGangs()
{
//set up the relationshipgroups
for (int i = 0; i < gangData.gangs.Count; i++)
Expand Down Expand Up @@ -156,9 +157,7 @@ void SetUpGangRelations()
//aaaand check if our current stats still conform to the min/max statuses defined in ModOptions
gangData.gangs[i].AdjustStatsToModOptions();

//if we're not player owned, we hate the player!
World.SetRelationshipBetweenGroups(Relationship.Hate, gangData.gangs[i].relationGroupIndex, Game.Player.Character.RelationshipGroup);
World.SetRelationshipBetweenGroups(Relationship.Hate, Game.Player.Character.RelationshipGroup, gangData.gangs[i].relationGroupIndex);


//add this gang to the enemy gangs
//and start the AI for it
Expand All @@ -167,20 +166,48 @@ void SetUpGangRelations()

}

//and the relations themselves
for (int i = gangData.gangs.Count - 1; i > -1; i--)
{
for(int j = 0; j < i; j++)
{
World.SetRelationshipBetweenGroups(Relationship.Hate, gangData.gangs[i].relationGroupIndex, gangData.gangs[j].relationGroupIndex);
World.SetRelationshipBetweenGroups(Relationship.Hate, gangData.gangs[j].relationGroupIndex, gangData.gangs[i].relationGroupIndex);
}
}

//set gang relations...
SetGangRelationsAccordingToAggrLevel(ModOptions.instance.gangMemberAggressiveness);
//all gangs hate cops if set to very aggressive
SetCopRelations(ModOptions.instance.gangMemberAggressiveness == ModOptions.GangMemberAggressivenessMode.veryAgressive);
}

/// <summary>
/// sets relations between gangs to a certain level according to the aggressiveness
/// </summary>
/// <param name="aggrLevel"></param>
public void SetGangRelationsAccordingToAggrLevel(ModOptions.GangMemberAggressivenessMode aggrLevel) {
Relationship targetRelationLevel = Relationship.Hate;
Gang excludedGang = null;
if (GangWarManager.instance.isOccurring) {
excludedGang = GangWarManager.instance.enemyGang;
}
switch (aggrLevel) {
case ModOptions.GangMemberAggressivenessMode.veryAgressive:
targetRelationLevel = Relationship.Hate;
break;
case ModOptions.GangMemberAggressivenessMode.agressive:
targetRelationLevel = Relationship.Dislike;
break;
case ModOptions.GangMemberAggressivenessMode.defensive:
targetRelationLevel = Relationship.Neutral;
break;
}
for (int i = gangData.gangs.Count - 1; i > -1; i--) {
for (int j = 0; j < i; j++) {
if((gangData.gangs[i] != excludedGang || gangData.gangs[j] != PlayerGang) &&
(gangData.gangs[j] != excludedGang || gangData.gangs[i] != PlayerGang)) {
World.SetRelationshipBetweenGroups(targetRelationLevel, gangData.gangs[i].relationGroupIndex, gangData.gangs[j].relationGroupIndex);
World.SetRelationshipBetweenGroups(targetRelationLevel, gangData.gangs[j].relationGroupIndex, gangData.gangs[i].relationGroupIndex);
}
}
if (!gangData.gangs[i].isPlayerOwned && gangData.gangs[i] != excludedGang) {
World.SetRelationshipBetweenGroups(targetRelationLevel, gangData.gangs[i].relationGroupIndex, Game.Player.Character.RelationshipGroup);
World.SetRelationshipBetweenGroups(targetRelationLevel, Game.Player.Character.RelationshipGroup, gangData.gangs[i].relationGroupIndex);
}
}
}

public void SetCopRelations(bool hate)
{
int copHash = Function.Call<int>(Hash.GET_HASH_KEY, "COP");
Expand Down
16 changes: 15 additions & 1 deletion GangWarManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ public bool StartWar(Gang enemyGang, TurfZone warZone, WarType theWarType, Attac
}
}

SetHateRelationsBetweenGangs();

return true;
}
else
Expand Down Expand Up @@ -341,6 +343,9 @@ public void EndWar(bool playerVictory)
enemySpawnBlip.Remove();
}

//reset relations to whatever is set in modoptions
GangManager.instance.SetGangRelationsAccordingToAggrLevel(ModOptions.instance.gangMemberAggressiveness);

}

public bool CanStartWarAgainstPlayer
Expand Down Expand Up @@ -537,7 +542,6 @@ void CheckIfBattleWasUnfair()
if (RandoMath.RandomBool())
{
enemyGang.gangWeaponHashes.Add(RandoMath.GetRandomElementFromList(ModOptions.instance.driveByWeapons));
enemyGang.gangWeaponHashes.Sort(enemyGang.CompareGunsByPrice);
GangManager.instance.SaveGangData(false);
}
}
Expand Down Expand Up @@ -736,6 +740,16 @@ public bool IsPlayerCloseToWar()
ModOptions.instance.maxDistToWarBlipBeforePlayerLeavesWar);
}

/// <summary>
/// forces the hate relation level between the involved gangs (includes the player)
/// </summary>
public void SetHateRelationsBetweenGangs() {
World.SetRelationshipBetweenGroups(Relationship.Hate, enemyGang.relationGroupIndex, GangManager.instance.PlayerGang.relationGroupIndex);
World.SetRelationshipBetweenGroups(Relationship.Hate, GangManager.instance.PlayerGang.relationGroupIndex, enemyGang.relationGroupIndex);
World.SetRelationshipBetweenGroups(Relationship.Hate, enemyGang.relationGroupIndex, Game.Player.Character.RelationshipGroup);
World.SetRelationshipBetweenGroups(Relationship.Hate, Game.Player.Character.RelationshipGroup, enemyGang.relationGroupIndex);
}

void OnTick(object sender, EventArgs e)
{
if (isOccurring)
Expand Down
4 changes: 1 addition & 3 deletions MenuScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1404,7 +1404,6 @@ void AddGangWeaponsMenu()
if (playerGang.gangWeaponHashes.Contains(kvp.Key.wepHash))
{
playerGang.gangWeaponHashes.Remove(kvp.Key.wepHash);
playerGang.gangWeaponHashes.Sort(playerGang.CompareGunsByPrice);
GangManager.instance.AddOrSubtractMoneyToProtagonist(kvp.Key.price);
GangManager.instance.SaveGangData();
UI.ShowSubtitle("Weapon Removed!");
Expand All @@ -1415,7 +1414,6 @@ void AddGangWeaponsMenu()
if (GangManager.instance.AddOrSubtractMoneyToProtagonist(-kvp.Key.price))
{
playerGang.gangWeaponHashes.Add(kvp.Key.wepHash);
playerGang.gangWeaponHashes.Sort(playerGang.CompareGunsByPrice);
GangManager.instance.SaveGangData();
UI.ShowSubtitle("Weapon Bought!");
item.Checked = true;
Expand Down Expand Up @@ -1634,7 +1632,7 @@ void AddMemberAggressivenessControl()

void AddEnableFightingToggle()
{
UIMenuCheckboxItem fightingToggle = new UIMenuCheckboxItem("Gang Fights Enabled?", ModOptions.instance.fightingEnabled, "If unchecked, members from different gangs won't attack each other (including the player). Gang wars also won't happen.");
UIMenuCheckboxItem fightingToggle = new UIMenuCheckboxItem("Gang Wars Enabled?", ModOptions.instance.fightingEnabled, "If unchecked, Gang wars won't happen.");

modSettingsSubMenu.AddItem(fightingToggle);
modSettingsSubMenu.OnCheckboxChange += (sender, item, checked_) =>
Expand Down
1 change: 1 addition & 0 deletions ModOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ public void SetKey(MenuScript.ChangeableKeyBinding keyToChange, Keys newKey)
public void SetMemberAggressiveness(GangMemberAggressivenessMode newMode)
{
gangMemberAggressiveness = newMode;
GangManager.instance.SetGangRelationsAccordingToAggrLevel(newMode);
//makes everyone hate cops if set to very aggressive
GangManager.instance.SetCopRelations(newMode == GangMemberAggressivenessMode.veryAgressive);
MenuScript.instance.aggOption.Index = (int)newMode;
Expand Down

0 comments on commit 3bad89d

Please sign in to comment.