mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-02 03:28:27 +00:00
teams (#349)
This commit is contained in:
@@ -54,7 +54,7 @@ export class BotExecution implements Execution {
|
||||
.filter((n) => n.isPlayer() && n.isTraitor()) as Player[];
|
||||
if (traitors.length > 0) {
|
||||
const toAttack = this.random.randElement(traitors);
|
||||
const odds = this.bot.isAlliedWith(toAttack) ? 6 : 3;
|
||||
const odds = this.bot.isFriendly(toAttack) ? 6 : 3;
|
||||
if (this.random.chance(odds)) {
|
||||
this.sendAttack(toAttack);
|
||||
return;
|
||||
@@ -85,7 +85,7 @@ export class BotExecution implements Execution {
|
||||
const owner = this.mg.owner(toAttack);
|
||||
|
||||
if (owner.isPlayer()) {
|
||||
if (this.bot.isAlliedWith(owner)) {
|
||||
if (this.bot.isFriendly(owner)) {
|
||||
return;
|
||||
}
|
||||
if (owner.type() == PlayerType.FakeHuman) {
|
||||
|
||||
@@ -192,7 +192,7 @@ export class FakeHumanExecution implements Execution {
|
||||
}
|
||||
|
||||
private shouldAttack(other: Player): boolean {
|
||||
if (this.player.isAlliedWith(other)) {
|
||||
if (this.player.isFriendly(other)) {
|
||||
if (this.shouldDiscourageAttack(other)) {
|
||||
return this.random.chance(200);
|
||||
}
|
||||
@@ -271,12 +271,11 @@ export class FakeHumanExecution implements Execution {
|
||||
}
|
||||
}
|
||||
|
||||
if (this.player.isAlliedWith(this.enemy)) {
|
||||
this.enemy = null;
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.enemy) {
|
||||
if (this.player.isFriendly(this.enemy)) {
|
||||
this.enemy = null;
|
||||
return;
|
||||
}
|
||||
this.maybeSendNuke(this.enemy);
|
||||
if (this.player.sharesBorderWith(this.enemy)) {
|
||||
this.sendAttack(this.enemy);
|
||||
@@ -537,7 +536,7 @@ export class FakeHumanExecution implements Execution {
|
||||
}
|
||||
if (
|
||||
this.mg.owner(dst).isPlayer() &&
|
||||
this.player.isAlliedWith(this.mg.owner(dst) as Player)
|
||||
this.player.isFriendly(this.mg.owner(dst) as Player)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ export class PlayerExecution implements Execution {
|
||||
const main = clusters.shift();
|
||||
this.player.largestClusterBoundingBox = calculateBoundingBox(this.mg, main);
|
||||
const surroundedBy = this.surroundedBySamePlayer(main);
|
||||
if (surroundedBy && !this.player.isAlliedWith(surroundedBy)) {
|
||||
if (surroundedBy && !this.player.isFriendly(surroundedBy)) {
|
||||
this.removeCluster(main);
|
||||
}
|
||||
|
||||
|
||||
@@ -72,8 +72,7 @@ export class SAMLauncherExecution implements Execution {
|
||||
])
|
||||
.filter(
|
||||
({ unit }) =>
|
||||
unit.owner() !== this.player &&
|
||||
!unit.owner().isAlliedWith(this.player),
|
||||
unit.owner() !== this.player && !this.player.isFriendly(unit.owner()),
|
||||
);
|
||||
|
||||
this.target =
|
||||
|
||||
@@ -152,7 +152,7 @@ export class TransportShipExecution implements Execution {
|
||||
this.active = false;
|
||||
return;
|
||||
}
|
||||
if (this.target.isPlayer() && this.attacker.isAlliedWith(this.target)) {
|
||||
if (this.target.isPlayer() && this.attacker.isFriendly(this.target)) {
|
||||
this.target.addTroops(this.troops);
|
||||
} else {
|
||||
this.attacker.conquer(this.dst);
|
||||
|
||||
@@ -146,7 +146,7 @@ export class WarshipExecution implements Execution {
|
||||
({ unit }) =>
|
||||
unit.owner() !== this.warship.owner() &&
|
||||
unit !== this.warship &&
|
||||
!unit.owner().isAlliedWith(this.warship.owner()) &&
|
||||
!unit.owner().isFriendly(this.warship.owner()) &&
|
||||
!this.alreadySentShell.has(unit) &&
|
||||
(unit.type() !== UnitType.TradeShip || hasPort) &&
|
||||
(unit.type() !== UnitType.TradeShip ||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { EventBus, GameEvent } from "../EventBus";
|
||||
import { Execution, Game, Player, PlayerID } from "../game/Game";
|
||||
import { Execution, Game, GameMode, Player, Team } from "../game/Game";
|
||||
|
||||
export class WinEvent implements GameEvent {
|
||||
constructor(public readonly winner: Player) {}
|
||||
@@ -20,6 +20,14 @@ export class WinCheckExecution implements Execution {
|
||||
if (ticks % 10 != 0) {
|
||||
return;
|
||||
}
|
||||
if (this.mg.config().gameConfig().gameMode == GameMode.FFA) {
|
||||
this.checkWinnerFFA();
|
||||
} else {
|
||||
this.checkWinnerTeam();
|
||||
}
|
||||
}
|
||||
|
||||
checkWinnerFFA(): void {
|
||||
const sorted = this.mg
|
||||
.players()
|
||||
.sort((a, b) => b.numTilesOwned() - a.numTilesOwned());
|
||||
@@ -39,6 +47,30 @@ export class WinCheckExecution implements Execution {
|
||||
}
|
||||
}
|
||||
|
||||
checkWinnerTeam(): void {
|
||||
const teamToTiles = new Map<Team, number>();
|
||||
for (const player of this.mg.players()) {
|
||||
teamToTiles.set(
|
||||
player.team(),
|
||||
(teamToTiles.get(player.team()) ?? 0) + player.numTilesOwned(),
|
||||
);
|
||||
}
|
||||
const sorted = Array.from(teamToTiles.entries()).sort(
|
||||
(a, b) => b[1] - a[1],
|
||||
);
|
||||
if (sorted.length == 0) {
|
||||
return;
|
||||
}
|
||||
const max = sorted[0];
|
||||
const numTilesWithoutFallout =
|
||||
this.mg.numLandTiles() - this.mg.numTilesWithFallout();
|
||||
const percentage = (max[1] / numTilesWithoutFallout) * 100;
|
||||
if (percentage > this.mg.config().percentageTilesOwnedToWin()) {
|
||||
this.mg.setWinner(max[0].name, this.mg.stats().stats());
|
||||
console.log(`${max[0].name} has won the game`);
|
||||
this.active = false;
|
||||
}
|
||||
}
|
||||
owner(): Player {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ export class AllianceRequestExecution implements Execution {
|
||||
}
|
||||
|
||||
tick(ticks: number): void {
|
||||
if (this.requestor.isAlliedWith(this.recipient)) {
|
||||
if (this.requestor.isFriendly(this.recipient)) {
|
||||
consolex.warn("already allied");
|
||||
} else if (!this.requestor.canSendAllianceRequest(this.recipient)) {
|
||||
consolex.warn("recent or pending alliance request");
|
||||
|
||||
@@ -40,7 +40,7 @@ export class AllianceRequestReplyExecution implements Execution {
|
||||
}
|
||||
|
||||
tick(ticks: number): void {
|
||||
if (this.requestor.isAlliedWith(this.recipient)) {
|
||||
if (this.requestor.isFriendly(this.recipient)) {
|
||||
consolex.warn("already allied");
|
||||
} else {
|
||||
const request = this.requestor
|
||||
|
||||
Reference in New Issue
Block a user