mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-23 05:49:37 +00:00
Improved the nation alliance request logic 🤝 Massive upgrade to singleplayer fun (#2606)
## Response to alliance requests Previously the way nations responded to alliance requests was quite simple / boring / exploitable. Basically you couldn't ally them if you had a bad relation with them, or if you had too many alliances. Otherwise they would just take it. Now there is a **complete decision tree which is based on the difficulty**. The nations should also feel more human now. For example, just like humans, nations will now consider to take an alliance even if you have a bad relation with them (If you are a threat). Also, nations no longer check if YOU have too many alliances. Now they do what humans do: Check if THEY have too many alliances (they want to be able to attack somebody). Another big change is the default case: Previously it was just `return true`. Now it's `return isAlliancePartnerSimilarlyStrong`. So they do what humans do: Take a quick look at their troop count before allying them. ## Sending alliance requests Previously alliance requests were sent randomly. Quite boring. Now we use the same decision tree as for responding. ## Alliance extension requests They also use the same decision tree. ## Tests Tested it a lot in singleplayer. I have planned to add unit tests for all the nation/bot stuff in the upcoming cleanup phase. ## Please complete the following: - [X] I have added screenshots for all UI updates - [X] I process any text displayed to the user through translateText() and I've added it to the en.json file - [X] I have added relevant tests to the test directory - [X] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced ## Please put your Discord username so you can be contacted if a bug or regression is found: FloPinguin
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import {
|
||||
AllianceRequest,
|
||||
Difficulty,
|
||||
Game,
|
||||
Player,
|
||||
@@ -14,7 +13,6 @@ import {
|
||||
calculateBoundingBoxCenter,
|
||||
flattenedEmojiTable,
|
||||
} from "../../Util";
|
||||
import { AllianceExtensionExecution } from "../alliance/AllianceExtensionExecution";
|
||||
import { AttackExecution } from "../AttackExecution";
|
||||
import { EmojiExecution } from "../EmojiExecution";
|
||||
import { TransportShipExecution } from "../TransportShipExecution";
|
||||
@@ -41,38 +39,6 @@ export class BotBehavior {
|
||||
private expandRatio: number,
|
||||
) {}
|
||||
|
||||
handleAllianceRequests() {
|
||||
for (const req of this.player.incomingAllianceRequests()) {
|
||||
if (shouldAcceptAllianceRequest(this.player, req)) {
|
||||
req.accept();
|
||||
} else {
|
||||
req.reject();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
handleAllianceExtensionRequests() {
|
||||
for (const alliance of this.player.alliances()) {
|
||||
// Alliance expiration tracked by Events Panel, only human ally can click Request to Renew
|
||||
// Skip if no expiration yet/ ally didn't request extension yet/ bot already agreed to extend
|
||||
if (!alliance.onlyOneAgreedToExtend()) continue;
|
||||
|
||||
// Nation is either Friendly or Neutral as an ally. Bot has no attitude
|
||||
// If Friendly or Bot, always agree to extend. If Neutral, have random chance decide
|
||||
const human = alliance.other(this.player);
|
||||
if (
|
||||
this.player.type() === PlayerType.FakeHuman &&
|
||||
this.player.relation(human) === Relation.Neutral
|
||||
) {
|
||||
if (!this.random.chance(1.5)) continue;
|
||||
}
|
||||
|
||||
this.game.addExecution(
|
||||
new AllianceExtensionExecution(this.player, human.id()),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private emoji(player: Player, emoji: number) {
|
||||
if (player.type() !== PlayerType.Human) return;
|
||||
this.game.addExecution(new EmojiExecution(this.player, player.id(), emoji));
|
||||
@@ -571,19 +537,3 @@ export class BotBehavior {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function shouldAcceptAllianceRequest(player: Player, request: AllianceRequest) {
|
||||
if (player.relation(request.requestor()) < Relation.Neutral) {
|
||||
return false; // Reject if hasMalice
|
||||
}
|
||||
if (request.requestor().isTraitor()) {
|
||||
return false; // Reject if isTraitor
|
||||
}
|
||||
if (request.requestor().numTilesOwned() > player.numTilesOwned() * 3) {
|
||||
return true; // Accept if requestorIsMuchLarger
|
||||
}
|
||||
if (request.requestor().alliances().length >= 3) {
|
||||
return false; // Reject if tooManyAlliances
|
||||
}
|
||||
return true; // Accept otherwise
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user