Skip to main content

Overview

OpenFront’s alliance system enables temporary cooperation between players. Alliances are time-limited, require mutual consent, can be extended, and affect various game mechanics including attacks, trades, and diplomacy.

Core Concepts

Alliance Properties

  • Time-Limited: Alliances expire after a configured duration
  • Bilateral: Require acceptance from both players
  • Extensible: Can be renewed if both parties agree
  • Breakable: Either player can break the alliance
  • Embargo-Creating: Attacking creates automatic embargo

Alliance Implementation

The AllianceImpl class manages alliance state and lifecycle:
src/core/game/AllianceImpl.ts
Player
The player who initiated the alliance request
Player
The player who received and accepted the request
Tick
The game tick when the alliance was formed
Tick
The game tick when the alliance will expire if not extended
number
Unique identifier for this alliance

Alliance Lifecycle

1. Request Phase

A player creates an alliance request:
src/core/game/AllianceRequestImpl.ts

2. Acceptance/Rejection

The recipient can accept or reject:
  • Accept: Creates an AllianceImpl object
  • Reject: Removes the request, no alliance formed

3. Active Alliance

Once accepted, the alliance is active until expiration or break:

4. Extension System

Alliances can be extended if both players agree:
src/core/game/AllianceImpl.ts
Both players must request extension for it to succeed. If only one requests, the alliance expires normally.

5. Expiration

When an alliance expires:
src/core/game/AllianceImpl.ts
The game removes the alliance and updates both players’ alliance lists.

Alliance Executions

Alliance actions are implemented as executions:

AllianceRequestExecution

src/core/execution/alliance/AllianceRequestExecution.ts

AllianceRejectExecution

src/core/execution/alliance/AllianceRejectExecution.ts

AllianceExtensionExecution

src/core/execution/alliance/AllianceExtensionExecution.ts

BreakAllianceExecution

src/core/execution/alliance/BreakAllianceExecution.ts
All alliance executions are single-tick operations that complete immediately in their init() method.

Friendship System

Alliances are part of a broader “friendship” concept:

Game Mechanics Affected by Alliances

Attack Restrictions

Players cannot attack friendly players:
src/core/execution/AttackExecution.ts
If an alliance is formed while an attack is in progress, the attack immediately retreats with no penalty.

Trade and Donations

Alliances enable resource sharing:

Embargoes

Attacking a player creates an automatic embargo:
src/core/execution/AttackExecution.ts
Bots don’t participate in embargoes since they can’t trade anyway.

Incoming Request Rejection

Attacking auto-rejects pending alliance requests:
src/core/execution/AttackExecution.ts

Player Actions

The GameRunner provides alliance-related actions:
src/core/GameRunner.ts
boolean
Whether the player can send an alliance request to the other player
boolean
Whether the player can break an existing alliance
AllianceInfo | undefined
Information about the current alliance status, if any

Configuration

Alliance behavior is configured through the game config:
Typical values:
  • Short: 3000 ticks (~5 minutes at 10 ticks/second)
  • Medium: 6000 ticks (~10 minutes)
  • Long: 12000 ticks (~20 minutes)

Best Practices

For Players

  1. Request Early: Alliance requests take time to accept
  2. Communicate: Use emojis/quick chat to coordinate
  3. Watch Expiration: Request extension before alliance expires
  4. Plan Breaks: Breaking alliances has diplomatic consequences

For Developers

  1. Check Friendship: Use isFriendly() not just isAlliedWith()
  2. Handle Timing: Alliances can form/break mid-attack
  3. Update UI: Show alliance status clearly
  4. Test Edge Cases: Alliance + team, alliance + embargo, etc.