Player12
An open source football management simulator
Loading...
Searching...
No Matches
StoryEngine Class Reference

Detects story triggers for the managed club and posts them. More...

#include <stories.h>

Public Member Functions

 StoryEngine (std::shared_ptr< GameData > gamedata)
 
void setCareerProvider (std::function< CareerTotals(PlayerID)> provider)
 
void onDayAdvanced (const GameDateValue &date, TeamID managed_team_id, const InteractionSystem &interactions, Inbox &inbox, const StoryDayContext &context={})
 
void onMatchPlayed (const MatchReport &report, TeamID managed_team_id, const std::string &recent_form, Inbox &inbox)
 
void onTransferBid (const GameDateValue &date, PlayerID player_id, TeamID bidder_id, bool key_player, TeamID managed_team_id, Inbox &inbox)
 
void onPlayerLeft (PlayerID player_id)
 
void onSeasonStart ()
 
std::optional< TeamID > rivalOf (TeamID team_id) const
 
std::optional< StoryChoice > choiceFor (PlayerID player_id, std::int32_t today) const
 
void resolveChoice (PlayerID player_id)
 
const Dilemma * openDilemma () const
 
const Dilemma * dilemmaOn (std::int32_t day) const
 
std::optional< DilemmaEffects > previewDilemma (int option, TeamID managed_team_id) const
 
bool resolveDilemma (int option, const GameDateValue &date, TeamID managed_team_id, InteractionSystem &interactions, Inbox &inbox)
 
bool follow (PlayerID player_id, const GameDateValue &date)
 
bool unfollow (PlayerID player_id)
 
bool isFollowed (PlayerID player_id) const
 
const std::vector< FollowedPlayer > & getFollows () const
 
const StoryState & getState () const
 
void restore (StoryState restored)
 
void load (const std::shared_ptr< DatabaseConnection > &db_conn)
 
void save (const std::shared_ptr< DatabaseConnection > &db_conn) const
 

Private Member Functions

bool fired (StoryKind kind, std::uint32_t entity, std::uint32_t key) const
 
bool firedSince (StoryKind kind, std::uint32_t entity, std::int32_t since_day) const
 
bool post (const GameDateValue &date, StoryKind kind, std::uint32_t entity, std::uint32_t key, const char *title_key, const char *body_key, std::vector< std::string > args, std::optional< PlayerID > player_id, std::optional< TeamID > team_id, Inbox &inbox, bool with_choice=false)
 
CareerTotals careerBefore (PlayerID player_id)
 
void trackFollows (const GameDateValue &date, TeamID managed_team_id, const AwardSystem *awards, Inbox &inbox)
 
void followMatch (const MatchReport &report, TeamID managed_team_id, Inbox &inbox)
 
void raiseDilemma (const GameDateValue &date, TeamID managed_team_id, const InteractionSystem &interactions, const StoryDayContext &context, Inbox &inbox)
 

Private Attributes

std::shared_ptr< GameData > gamedata
 
StoryState state
 
std::function< CareerTotals(PlayerID)> career_provider
 
std::unordered_map< PlayerID, CareerTotals > career_cache
 
std::unordered_map< TeamID, std::optional< TeamID > > rivals
 

Detailed Description

Detects story triggers for the managed club and posts them.

Constructor & Destructor Documentation

◆ StoryEngine()

StoryEngine::StoryEngine ( std::shared_ptr< GameData >  gamedata)
explicit

Member Function Documentation

◆ careerBefore()

CareerTotals StoryEngine::careerBefore ( PlayerID  player_id)
private

◆ choiceFor()

std::optional< StoryChoice > StoryEngine::choiceFor ( PlayerID  player_id,
std::int32_t  today 
) const

Open decision for a player, if any.

◆ dilemmaOn()

const Dilemma * StoryEngine::dilemmaOn ( std::int32_t  day) const

The moment raised on day (open or not).

◆ fired()

bool StoryEngine::fired ( StoryKind  kind,
std::uint32_t  entity,
std::uint32_t  key 
) const
private

◆ firedSince()

bool StoryEngine::firedSince ( StoryKind  kind,
std::uint32_t  entity,
std::int32_t  since_day 
) const
private

◆ follow()

bool StoryEngine::follow ( PlayerID  player_id,
const GameDateValue &  date 
)

Starts following player_id (false if unknown, followed or full).

◆ followMatch()

void StoryEngine::followMatch ( const MatchReport &  report,
TeamID  managed_team_id,
Inbox &  inbox 
)
private

◆ getFollows()

const std::vector< FollowedPlayer > & StoryEngine::getFollows ( ) const
inline

◆ getState()

const StoryState & StoryEngine::getState ( ) const
inline

◆ isFollowed()

bool StoryEngine::isFollowed ( PlayerID  player_id) const

◆ load()

void StoryEngine::load ( const std::shared_ptr< DatabaseConnection > &  db_conn)

◆ onDayAdvanced()

void StoryEngine::onDayAdvanced ( const GameDateValue &  date,
TeamID  managed_team_id,
const InteractionSystem &  interactions,
Inbox &  inbox,
const StoryDayContext &  context = {} 
)

Daily: long-injury tracking, captain disputes (weekly), expiries, followed players' news and decision moments (never on match day).

◆ onMatchPlayed()

void StoryEngine::onMatchPlayed ( const MatchReport &  report,
TeamID  managed_team_id,
const std::string &  recent_form,
Inbox &  inbox 
)

Debut, breakout, milestones, comeback, poor run and rivalry of the managed club; big matches of followed players anywhere.

◆ onPlayerLeft()

void StoryEngine::onPlayerLeft ( PlayerID  player_id)

A player left: his open choices lapse.

◆ onSeasonStart()

void StoryEngine::onSeasonStart ( )

Rivals are recomputed at the start of each season.

◆ onTransferBid()

void StoryEngine::onTransferBid ( const GameDateValue &  date,
PlayerID  player_id,
TeamID  bidder_id,
bool  key_player,
TeamID  managed_team_id,
Inbox &  inbox 
)

Transfer saga: a second bid within a month for a key player.

◆ openDilemma()

const Dilemma * StoryEngine::openDilemma ( ) const

The open decision moment, if any.

◆ post()

bool StoryEngine::post ( const GameDateValue &  date,
StoryKind  kind,
std::uint32_t  entity,
std::uint32_t  key,
const char *  title_key,
const char *  body_key,
std::vector< std::string >  args,
std::optional< PlayerID >  player_id,
std::optional< TeamID >  team_id,
Inbox &  inbox,
bool  with_choice = false 
)
private

Posts when the weekly cap allows; records the story either way.

◆ previewDilemma()

std::optional< DilemmaEffects > StoryEngine::previewDilemma ( int  option,
TeamID  managed_team_id 
) const

Effects of option for the open moment of managed_team_id.

◆ raiseDilemma()

void StoryEngine::raiseDilemma ( const GameDateValue &  date,
TeamID  managed_team_id,
const InteractionSystem &  interactions,
const StoryDayContext &  context,
Inbox &  inbox 
)
private

◆ resolveChoice()

void StoryEngine::resolveChoice ( PlayerID  player_id)

The manager answered (or dismissed) the player's story.

◆ resolveDilemma()

bool StoryEngine::resolveDilemma ( int  option,
const GameDateValue &  date,
TeamID  managed_team_id,
InteractionSystem &  interactions,
Inbox &  inbox 
)

Answers the open moment with option (0 or 1): applies its effects to the players, their trust (through interactions) and the club's ledger, records the answer and files a note. False when nothing is open or the option is invalid.

◆ restore()

void StoryEngine::restore ( StoryState  restored)

◆ rivalOf()

std::optional< TeamID > StoryEngine::rivalOf ( TeamID  team_id) const

Same-league club of the nearest reputation (lower id on ties).

◆ save()

void StoryEngine::save ( const std::shared_ptr< DatabaseConnection > &  db_conn) const

◆ setCareerProvider()

void StoryEngine::setCareerProvider ( std::function< CareerTotals(PlayerID)>  provider)

Competitive career totals before the match being processed (the competitions record a result after the world simulation). Queried once per player and session, then kept up to date from match reports.

◆ trackFollows()

void StoryEngine::trackFollows ( const GameDateValue &  date,
TeamID  managed_team_id,
const AwardSystem *  awards,
Inbox &  inbox 
)
private

◆ unfollow()

bool StoryEngine::unfollow ( PlayerID  player_id)

Member Data Documentation

◆ career_cache

std::unordered_map<PlayerID, CareerTotals> StoryEngine::career_cache
private

Transient cache of career totals, advanced from match reports.

◆ career_provider

std::function<CareerTotals(PlayerID)> StoryEngine::career_provider
private

◆ gamedata

std::shared_ptr<GameData> StoryEngine::gamedata
private

◆ rivals

std::unordered_map<TeamID, std::optional<TeamID> > StoryEngine::rivals
mutableprivate

◆ state

StoryState StoryEngine::state
private

The documentation for this class was generated from the following files: