#include "app/trade_raid.h" namespace sots::app { namespace { // The chance helper with its word cost reported rather than assumed: the two early-outs // return WITHOUT drawing, so a probability outside (0, 1) costs nothing. Counting the draws // instead of the calls is what keeps the ledger honest if a loaded tuning table ever pushes // one of the three odds to 0 or 1. bool ChanceCounted(sots::sim::IRandom& rng, float p, int& words) { if (p <= 0.f) return false; if (p >= 1.f) return true; ++words; return p > rng.NextFloat(); } } // namespace bool Chance(sots::sim::IRandom& rng, float p) { int ignored = 0; return ChanceCounted(rng, p, ignored); } TradeRaidResult RollTradeRaids(sots::sim::IRandom& rng, int players, const TradeRaidOdds& odds, const TradeRaidGates& gates) { TradeRaidResult r; if (players <= 0) return r; r.players = players; for (int i = 0; i < players; ++i) { if (ChanceCounted(rng, odds.player, r.words)) ++r.playerRaidHits; if (gates.npcRaids && ChanceCounted(rng, odds.npc, r.words)) ++r.npcRaidHits; if (gates.refugeeRaids && ChanceCounted(rng, odds.refugee, r.words)) ++r.refugeeRaidHits; } return r; } } // namespace sots::app