Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/core/configuration/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export interface Config {
tradeShipGold(dist: number): Gold;
tradeShipSpawnRate(
tradeShipSpawnRejections: number,
numTradeShips: number,
numPlayerPorts: number,
): number;
trainGold(rel: "self" | "team" | "ally" | "other"): Gold;
trainSpawnRate(numPlayerFactories: number): number;
Expand Down
31 changes: 11 additions & 20 deletions src/core/configuration/DefaultConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { PlayerView } from "../game/GameView";
import { UserSettings } from "../game/UserSettings";
import { GameConfig, GameID, TeamCountConfig } from "../Schemas";
import { NukeType } from "../StatsSchemas";
import { assertNever, sigmoid, simpleHash, within } from "../Util";
import { assertNever, sigmoid, simpleHash, toInt, within } from "../Util";
import { Config, GameEnv, NukeMagnitude, ServerConfig, Theme } from "./Config";
import { Env } from "./Env";
import { PastelTheme } from "./PastelTheme";
Expand Down Expand Up @@ -299,28 +299,24 @@ export class DefaultConfig implements Config {
}

tradeShipGold(dist: number): Gold {
// Sigmoid: concave start, sharp S-curve middle, linear end - heavily punishes trades under range debuff.
const debuff = this.tradeShipShortRangeDebuff();
const baseGold =
50_000 / (1 + Math.exp(-0.03 * (dist - debuff))) + 50 * dist;
const multiplier = this.goldMultiplier();
return BigInt(Math.floor(baseGold * multiplier));
return toInt(10000 + 150 * Math.pow(dist, 1.1));
}

// Probability of trade ship spawn = 1 / tradeShipSpawnRate
tradeShipSpawnRate(
tradeShipSpawnRejections: number,
numTradeShips: number,
numPlayerPorts: number,
): number {
const decayRate = Math.LN2 / 50;

// Approaches 0 as numTradeShips increase
const baseSpawnRate = 1 - sigmoid(numTradeShips, decayRate, 200);
if (numPlayerPorts <= 3) return 18;
if (numPlayerPorts <= 5) return 25;
if (numPlayerPorts <= 8) return 35;
if (numPlayerPorts <= 10) return 40;
if (numPlayerPorts <= 12) return 45;

// Pity timer: increases spawn chance after consecutive rejections
const rejectionModifier = 1 / (tradeShipSpawnRejections + 1);

return Math.floor((100 * rejectionModifier) / baseSpawnRate);
return Math.floor((100 * rejectionModifier) / 50);
}

unitInfo(type: UnitType): UnitInfo {
Expand Down Expand Up @@ -379,13 +375,8 @@ export class DefaultConfig implements Config {
};
break;
case UnitType.MIRV:
info = {
cost: (game: Game, player: Player) => {
if (player.type() === PlayerType.Human && this.infiniteGold()) {
return 0n;
}
return 25_000_000n + game.stats().numMirvsLaunched() * 15_000_000n;
},
return {
cost: this.costWrapper(() => 35_000_000),
};
break;
case UnitType.MIRVWarhead:
Expand Down
4 changes: 2 additions & 2 deletions src/core/execution/PortExecution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ export class PortExecution implements Execution {
}

shouldSpawnTradeShip(): boolean {
const numTradeShips = this.mg.unitCount(UnitType.TradeShip);
const numPlayerPorts = this.port!.owner().unitCount(UnitType.Port);
const spawnRate = this.mg
.config()
.tradeShipSpawnRate(this.tradeShipSpawnRejections, numTradeShips);
.tradeShipSpawnRate(this.tradeShipSpawnRejections, numPlayerPorts);
for (let i = 0; i < this.port!.level(); i++) {
if (this.random.chance(spawnRate)) {
this.tradeShipSpawnRejections = 0;
Expand Down
2 changes: 1 addition & 1 deletion startup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export CLOUDFLARE_TUNNEL_TOKEN=${TUNNEL_TOKEN}

# Start supervisord
if [ "$DOMAIN" = openfront.dev ] && [ "$SUBDOMAIN" != main ]; then
exec timeout 18h /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf
exec /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf
else
exec /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf
Comment on lines 88 to 91
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

# First, find and read the startup.sh file
find . -name "startup.sh" -type f

Repository: openfrontio/OpenFrontIO

Length of output: 79


🏁 Script executed:

# Get the startup.sh file location and read the relevant section
git ls-files | grep startup.sh

Repository: openfrontio/OpenFrontIO

Length of output: 77


🏁 Script executed:

# Read the startup.sh file around lines 88-91
if [ -f startup.sh ]; then
  cat -n startup.sh | sed -n '80,100p'
fi

Repository: openfrontio/OpenFrontIO

Length of output: 623


🏁 Script executed:

# Check git log and diff to see what was removed/changed
git log --oneline -10 -- startup.sh
git diff HEAD~1 HEAD -- startup.sh || git show HEAD:startup.sh > /tmp/current.sh 2>/dev/null

Repository: openfrontio/OpenFrontIO

Length of output: 152


🏁 Script executed:

# Check if we can see more git history
git log --all --oneline | head -20
git log --all --graph --oneline | head -20

Repository: openfrontio/OpenFrontIO

Length of output: 2485


🏁 Script executed:

# Try to see the full diff for startup.sh across all branches
git diff --name-only | grep startup.sh

Repository: openfrontio/OpenFrontIO

Length of output: 49


🏁 Script executed:

# Check git status to understand current state
git status
git branch -a

Repository: openfrontio/OpenFrontIO

Length of output: 230


🏁 Script executed:

# Find commits that modified startup.sh
git log --all --oneline -- startup.sh | head -20

Repository: openfrontio/OpenFrontIO

Length of output: 639


🏁 Script executed:

# Show the diff of the most recent change to startup.sh
git log -p --all -- startup.sh | head -200

Repository: openfrontio/OpenFrontIO

Length of output: 49


🏁 Script executed:

# Search for "timeout" or "wrapper" in the file history
git log -p --all -- startup.sh | grep -A 5 -B 5 "timeout\|wrapper" | head -100

Repository: openfrontio/OpenFrontIO

Length of output: 49


🏁 Script executed:

# Try to see the previous version of startup.sh
git show HEAD:startup.sh 2>/dev/null | grep -A 10 -B 10 "DOMAIN.*openfront.dev" || echo "Current HEAD version:"
cat startup.sh | grep -A 10 -B 10 "DOMAIN.*openfront.dev"

Repository: openfrontio/OpenFrontIO

Length of output: 1314


🏁 Script executed:

# Show the commit that mentions "18h" timeout
git show ad045c4a | head -100

Repository: openfrontio/OpenFrontIO

Length of output: 716


🏁 Script executed:

# Show the most recent change to startup.sh (commit 1f05e222)
git show 1f05e222:startup.sh | grep -A 15 "Start supervisord" || git show 1f05e222 -- startup.sh | head -150

Repository: openfrontio/OpenFrontIO

Length of output: 319


🏁 Script executed:

# Get full diff of the Traefik commit
git show 1f05e222 -- startup.sh

Repository: openfrontio/OpenFrontIO

Length of output: 4307


Remove redundant conditional - both branches now run the same command.

The if statement at line 88 no longer serves a purpose because both branches execute the exact same supervisord command. The 18-hour timeout that previously distinguished the dev environment branch has been removed, making this conditional dead code.

Simplify the code by removing the conditional and running supervisord directly:

Suggested fix
-if [ "$DOMAIN" = openfront.dev ] && [ "$SUBDOMAIN" != main ]; then
-    exec /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf
-else
-    exec /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf
-fi
+exec /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf

If the timeout behavior should be preserved for dev deployments, restore the timeout wrapper before applying this simplification.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if [ "$DOMAIN" = openfront.dev ] && [ "$SUBDOMAIN" != main ]; then
exec timeout 18h /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf
exec /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf
else
exec /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf
exec /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@startup.sh` around lines 88 - 91, The if/else conditional checking DOMAIN and
SUBDOMAIN is redundant because both branches call the same command; remove the
entire if block and simply execute the supervisord command (exec
/usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf) once,
referencing the existing DOMAIN/SUBDOMAIN logic only if you intend to
reintroduce the previous timeout behavior for dev (restore the timeout wrapper
around supervisord then).

fi
Loading