@@ -1,4 +1,16 @@
// SPDX-License-Identifier: GPL-3.0-only
// Who plays this career as a human: the page "Spieler" exists only where there is more than one.
Json App :: bank_players () const {
try {
if ( engine_mode_ ) return engine_manager_value_ . is_object () && engine_manager_value_ . contains ( " people " ) ? engine_career_context () . at ( " active_managers " ) : Json :: array ();
if ( source_ && world_ ) return demo_career_context ( snap () . state , * snap () . world ) . at ( " active_managers " );
} catch ( const std :: exception & ) {
}
return Json :: array ();
}
// Finanzen > Bank, Immobilien, Aktien, Sparbuch, Spieler: five pages of one menu. `bank_view_`
// says which: "credit" (the bank with what the club owns and its loan), "properties", "stocks",
// "savings" or "players".
std :: string App :: render_bank () {
const auto projected = engine_mode_ ? engine_bank_projection ( engine_data_ ) : Json ();
const auto snapshot = engine_mode_ ? Snapshot { 0 , world_ , projected . at ( " state " )} : snap ();
@@ -7,59 +19,18 @@ std::string App::render_bank() {
const auto bank_money = [ & ]( int64_t value ) { return engine_mode_ ? money ( value , {{ " code " , " EUR " }, { " minor_units " , 2 }}) : cash ( value ); };
const int property_count = int ( assets . at ( " properties " ) . size ()), stock_count = int ( assets . at ( " stocks " ) . size ());
if ( ! summary . value ( " ok " , false )) return {};
if ( bank_view_ != " properties " && bank_view_ != " stocks " && bank_view_ != " savings " && bank_view_ != " players " ) bank_view_ = " credit " ;
if ( bank_view_ == " players " && bank_players () . size () < 2 ) bank_view_ = " credit " ;
const auto & finance = snapshot . state . at ( " finance " );
bank_property_ = std :: clamp ( bank_property_ , 0 , property_count - 1 );
bank_stock_ = std :: clamp ( bank_stock_ , 0 , stock_count - 1 );
bank_owned_ = std :: clamp ( bank_owned_ , 0 , property_count - 1 );
if ( finance . at ( " properties " )[ size_t ( bank_owned_ )] = = 0 )
for ( int i = 0 ; i < property_count ; ++ i )
if ( finance . at ( " properties " )[ size_t ( i )] != 0 ) { bank_owned_ = i ; break ; }
const auto actions = [ & ]( const char * left , const char * lk , const char * right , const char * rk ) {
return " <nav class= \" bank-actions \" > " +
btn ( " bank-calc " , left , " bank-control " , " id= \" bank- " + std :: string ( lk ) + " \" data-kind= \" " + lk + " \" " ) +
btn ( " bank-calc " , right , " bank-control " , " id= \" bank- " + std :: string ( rk ) + " \" data-kind= \" " + rk + " \" " ) + " </nav> " ;
bank_owned_ = bank_property_ ; // the board has one chosen property: it is bought and sold
const auto calc = [ & ]( const char * label , const char * kind , const std :: string & css , bool on = true ) {
return pg_button ( " bank-calc " , label , css , " id= \" bank- " + std :: string ( kind ) + " \" data-kind= \" " + kind + " \" " + ( on ? " " : " disabled= \" disabled \" " ));
};
const auto kv = []( const std :: string & key , const std :: string & value , const std :: string & css = std :: string () ) {
return " <div class= \" pg-kv \" ><span> " + key + " </span><strong " + ( css . empty () ? std :: string () : " class= \" " + css + " \" " ) + " > " + value + " </strong></div> " ;
};
// A data set may carry the newer hall picture or only the first one; each has its own
// places for the five services.
const bool newer_hall = ! renderer_ . image ( " art.bank-hall-v2.png " , false , 3000 ) . token . empty ();
std :: string out = " <div class= \" bank-page \" ><div class= \" bank-scene \" > " +
img ( newer_hall ? " art.bank-hall-v2.png " : " art.bank-hall-v1.png " , 2608 , 1466.016746 , false , false , 3000 );
if ( bank_view_ == " entrance " ) {
struct Service { const char * id , * label , * hint ; double x , y , w , h ; };
const std :: array < Service , 5 > services = newer_hall ? std :: array < Service , 5 > {{
{ " properties " , " Immobilien " , " Immobilien – Gebäude ansehen, kaufen oder verkaufen. " , 14 , 23 , 23 , 43 },
{ " stocks " , " Aktien " , " Aktien – Kurse und Bestände ansehen, Aktien kaufen oder verkaufen. " , 49 , 4 , 45 , 26 },
{ " overview " , " Finanzübersicht " , " Finanzübersicht – Konto, Sparbuch, Immobilien, Aktien und Kredit im Überblick. " , 44 , 48 , 14 , 17 },
{ " savings " , " Sparbuch " , " Sparbuch – Guthaben ansehen, Geld einzahlen oder abheben. " , 78 , 55 , 12 , 11 },
{ " credit " , " Kredit " , " Kredit – Laufzeit wählen, einen Kredit aufnehmen oder tilgen. " , 81 , 32 , 15 , 22 }}}
: std :: array < Service , 5 > {{
{ " properties " , " Immobilien " , " Immobilien – Gebäude ansehen, kaufen oder verkaufen. " , . 5 , 18.5 , 17.5 , 43.5 },
{ " stocks " , " Aktien " , " Aktien – Kurse und Bestände ansehen, Aktien kaufen oder verkaufen. " , 30 , 30 , 13.5 , 19.5 },
{ " overview " , " Finanzübersicht " , " Finanzübersicht – Konto, Sparbuch, Immobilien, Aktien und Kredit im Überblick. " , 30.5 , 49.5 , 13 , 14.5 },
{ " savings " , " Sparbuch " , " Sparbuch – Guthaben ansehen, Geld einzahlen oder abheben. " , 85 , 60 , 6.5 , 7.5 },
{ " credit " , " Kredit " , " Kredit – Laufzeit wählen, einen Kredit aufnehmen oder tilgen. " , 85.3 , 31.5 , 13.7 , 27.5 }}};
out += " <div class= \" bank-hotspots \" > " ;
for ( const auto & s : services )
out += btn ( " bank-view " , std :: string ( " <span class= \" bank-tag \" > " ) + s . label + " </span> " , " bank-hotspot " , " id= \" bank-view- " + std :: string ( s . id ) +
" \" data-view= \" " + s . id + " \" data-bank-hint= \" " + esc ( s . hint ) + " \" aria-label= \" " + s . label +
" \" style= \" left: " + scalar ( s . x ) + " %;top: " + scalar ( s . y ) + " %;width: " + scalar ( s . w ) + " %;height: " + scalar ( s . h ) + " %; \" " );
out += " </div> " ;
}
out += " </div> " ;
if ( bank_view_ == " entrance " )
return out + " <p id= \" bank-interaction-hint \" role= \" status \" aria-live= \" polite \" ><span> " +
esc ( bank_hint_ . empty () ? " Ein Element in der Bankhalle auswählen. " : bank_hint_ ) + " </span></p></div> " ;
// Every service of the bank shares one head: the house's name, the service, and tabs that
// lead to the other services without a walk back through the hall.
const std :: array < std :: pair < const char * , const char *> , 5 > bank_tabs {{{ " overview " , " Übersicht " }, { " stocks " , " Aktien " }, { " properties " , " Immobilien " }, { " savings " , " Sparbuch " }, { " credit " , " Kredit " }}};
std :: string service ;
for ( const auto & [ id , label ] : bank_tabs ) if ( bank_view_ == id ) service = label ;
out += " <section class= \" bank-overlay " + esc ( bank_view_ ) + " -overlay \" ><header class= \" bank-head \" ><div class= \" bank-brand \" ><strong>Waldpark Bank</strong><span> " +
service + " </span></div><nav class= \" bank-tabs \" aria-label= \" Bankdienste \" > " ;
for ( const auto & [ id , label ] : bank_tabs )
out += btn ( " bank-view " , label , std :: string ( " bank-tab " ) + ( bank_view_ == id ? " selected " : " " ),
" id= \" bank-tab- " + std :: string ( id ) + " \" data-view= \" " + id + " \" aria-pressed= \" " + ( bank_view_ == id ? " true " : " false " ) + " \" " );
out += " </nav></header> " ;
const auto one = []( double value ) {
std :: ostringstream text ;
text << std :: fixed << std :: setprecision ( 1 ) << value ;
@@ -72,9 +43,9 @@ std::string App::render_bank() {
in_property = summary . at ( " properties " ) . get < int64_t > (), in_stock = summary . at ( " stocks " ) . get < int64_t > ();
const int64_t wealth = std :: max < int64_t > ( 0 , in_cash ) + in_deposit + in_property + in_stock ;
const auto share = [ & ]( int64_t part ) { return wealth > 0 ? one ( std :: max < int64_t > ( 0 , part ) * 100.0 / wealth ) + " % " : std :: string ( " — " ); };
const std :: string ink = theme_ == " silver " ? " #233443 " : " #e8eef2 " , faint = theme_ == " silver " ? " #4a433430 " : " #dfeaf530 " ,
up = theme_ == " silver " ? " #3f7d63 " : " #8fd3ad " , down = theme_ == " silver " ? " #a23f45 " : " #f0a6a7 " ,
gold = theme_ == " silver " ? " #9a7a3a " : " #d9bd7c " , line = theme_ == " silver " ? " #25617 a " : " #9ac7d8 " ;
const bool light = theme_ == " silver " ;
const std :: string ink = light ? " #2e2b25 " : " #f0ece2 " , faint = light ? " #3a332b24 " : " #f0ece224 " , up = light ? " #56633f " : " #a3ba7c " , down = light ? " #a8452f " : " #f0a08a " ,
gold = " #d08a1e " , line = light ? " #8c491 a " : " #e0a25f " ;
// an engine name arrives in capitals
const auto calm_name = []( std :: string name ) {
bool first = true ;
@@ -104,54 +75,65 @@ std::string App::render_bank() {
}
return history ;
};
// a picture with a line of writing on its lower edge: every page of the bank begins with one
const auto banner = [ & ]( const std :: string & art , double w , double h , const std :: string & kicker , const std :: string & value , const std :: string & detail ) {
return " <div class= \" bk-banner \" style= \" width: " + pg ( w ) + " ;height: " + pg ( h ) + " ; \" ><span class= \" bk-banner-art \" > " + img ( art , w * 2.25 , h * 2.25 , false , true , 1800 ) + " </span><div class= \" bk-banner-over \" ><span class= \" ad-tile-k \" > " + esc ( pg_upper ( kicker )) +
" </span><strong> " + esc ( value ) + " </strong> " + ( detail . empty () ? std :: string () : " <span class= \" bk-banner-d \" > " + esc ( detail ) + " </span> " ) + " </div></div> " ;
};
std :: string out = " <section class= \" pg-page \" id= \" bank-page \" > " ;
if ( bank_view_ == " savings " ) {
out + = " <div class= \" passbook \" > " + img ( " art.bank-passbook-v1.png " , 2100 , 1293.109375 , false , false , 2400 ) +
" <div class= \" passbook-left \" ><h2>Waldpark Bank</h2><h3>Sparbuch</h3><p class= \" passbook-note-one \" >Bitte beachten Sie:</p> "
" <p class= \" passbook-note-two \" > " + std :: string ( engine_mode_ ? " Einzahlungen und Abhebungen werden nach Bestätigung im Spielstand verbucht. " : " Einzahlungen und Abhebungen werden hier als fiktive Vorschau verbucht. " ) + " </p> "
" <p class= \" passbook-note-three \" > " + ( engine_mode_ ? " Anteil am Vermögen: " + share ( in_deposit ) : std :: string ( " 2,5 % Beispielzins " )) + " </p></div><div class= \" passbook-right \" ><h2>Guthaben</h2><output> " +
esc ( bank_money ( snapshot . state . at ( " deposit " ) . get < int64_t > ())) + " </output><p class=\" passbook-cash \" >Auf dem Konto: " + esc ( bank_money ( in_cash )) + " </p></div></div> " + actions ( " Einzahlen " , " deposit " , " Abheben " , " withdraw " ) ;
page_title_ = " Sparbuch " ;
page_hint_ = " Waldpark Bank " ;
const auto deposit = snapshot . state . at ( " deposit " ) . get < int64_t > ();
out += " <div class= \" pg-row pg-grow \" style= \" align-items:stretch; \" > " + banner ( " bank.scene.savings " , 640 , 648 , " Guthaben auf dem Sparbuch " , bank_money ( deposit ), share ( in_deposit ) + " des Vermögens " ) +
" <div class= \" pg-col pg-grow \" ><div class=\" bk-passbook \" ><span class= \" bk-passbook-head \" >Waldpark Bank · Sparbuch</span> " ;
// the page of the passbook: what is written in it today
for ( const auto & [ label , value ] : std :: array < std :: pair < const char * , std :: string > , 4 > {{{ " Guthaben " , bank_money ( deposit )}, { " Auf dem Konto " , bank_money ( in_cash )}, { " Vermögen gesamt " , bank_money ( wealth )}, { " Anteil Sparbuch " , share ( in_deposit )}}})
out += " <div class= \" bk-passbook-line \" ><span> " + std :: string ( label ) + " </span><strong> " + esc ( value ) + " </strong></div> " ;
out += " <span class= \" bk-passbook-note \" > " + std :: string ( deposit > 0 ? " Liegt sicher. Rest bleibt auf dem Konto. " : in_cash > 0 ? " Noch nichts zurückgelegt! " : " Erst muss Geld aufs Konto. " ) + " </span></div><span class= \" pg-sp \" ></span><span class= \" pg-mut \" style= \" display:block; \" > " +
std :: string ( engine_mode_ ? " Einzahlungen und Abhebungen werden nach Bestätigung im Spielstand verbucht. " : " Einzahlungen und Abhebungen werden hier als fiktive Vorschau verbucht. " ) + " </span><div class= \" pg-row \" style= \" " + pg_css ( " gap:8px; " ) + " \" > " +
calc ( " Einzahlen " , " deposit " , " primary block " ) + calc ( " Abheben " , " withdraw " , " block " ) + " </div></div></div> " ;
} else if ( bank_view_ == " properties " ) {
const auto & owned = assets . at ( " properties " )[ size_t ( bank_owned_ )], & offer = assets . at ( " properties " )[ size_t ( bank_property_ )];
const auto count = finance . at ( " properties " )[ size_t ( bank_owned_ )] . get < int64_t > () ;
// the board of an estate agent: every house a note pinned to it; what the club owns is stamped
static constexpr std :: array < const char * , 4 > coming { " Stadthaus " , " Penthouse " , " Siedlungshaus " , " Altbau-Reihenhaus " } ;
int64_t houses = 0 ;
for ( const auto & held : finance . at ( " properties " )) houses += held . get < int64_t > ();
const auto fact = []( const std :: string & label , const std :: string & value ) { return " <div class= \" bank-fact \" ><span> " + label + " </span><strong> " + value + " </strong></div> " ; } ;
out + = " <div class= \" property-card owned-property \" ><h3>Dein Bestand</h3> " +
btn ( " property-owned-next " , count ? img ( engine_mode_ ? owned . at ( " image " ) . get < std :: string > () : " bank.property. " + std :: to_string ( bank_owned_ ), 1150 , 653.5 , false , false , 1400 )
: " <span class= \" property-empty \" ><span>Noch keine Immobilie im Bestand</span></span> " , " property-picture " , " id= \" property-owned-next \" aria-label= \" Nächste eigene Immobilie \" " + std :: string ( count ? " " : " disabled " )) +
( count ? " <h4> " + esc ( calm_name ( owned . at ( " name " ) . get < std :: string > ())) + " </h4> " + fact ( " Im Bestand " , number ( count ) + " Stück " ) +
fact ( " Wert heute " , esc ( bank_money ( count * owned . at ( " price " ) . get < int64_t > ())))
: " <h4>Kein Bestand</h4> " + fact ( " Immobilienwert " , esc ( bank_money ( in_property ) )) + fact ( " Anteil am Vermögen " , share ( in_property ))) +
" <div class= \" property-prices \" ><h5>Preise im Vergleich · " + number ( houses ) + " im Bestand</h5> " ;
{
int64_t dearest = 1 ;
for ( const auto & item : assets . at ( " properties " )) dearest = std :: max ( dearest , item . at ( " price " ) . get < int64_t > ());
for ( int i = 0 ; i < property_count ; ++ i ) {
const auto & item = assets . at ( " properties " )[ size_t ( i )];
out += " <div class= \" property-price " + std :: string ( i == bank_property_ ? " chosen " : " " ) + " \" ><span class= \" name \" tit le=\" " + esc ( item . at ( " name " ) . get < std :: string > ()) + " \" > " + esc ( calm_name ( item . at ( " name " ) . get < std :: string > ())) +
" </span><div class= \" bank-part-track \" ><div style= \" width: " + scalar ( item . at ( " price " ) . get < int64_t > () * 100.0 / dearest ) + " %; \" ></div></div><span class= \" sum \" > " +
esc ( bank_money ( item . at ( " price " ) . get < int64_t > ())) + " </span></div> " ;
}
page_title_ = " Immobilien " ;
page_hint_ = number ( houses ) + " im Bestand · Wert " + bank_money ( in_property );
out += " <div class= \" bk-board \" > " ;
for ( int i = 0 ; i < 10 ; ++ i ) {
const bool real = i < property_count ;
const auto count = real ? finance . at ( " properties " )[ size_t ( i )] . get < int64_t > () : 0 ;
const auto name = real ? calm_name ( assets . at ( " properties " )[ size_t ( i )] . at ( " name " ) . get < std :: string > ( )) : std :: string ( coming [ size_t ( std :: min ( 3 , i - property_count ))]);
const auto price = real ? bank_money ( assets . at ( " properties " )[ size_t ( i )] . at ( " price " ) . get < int64_t > () ) : std :: string ( " Bald im Angebot " ) ;
const bool chosen = real && i == bank_property_ ;
out += btn ( real ? " bank-property " : " bank-soon " , " <span class= \" bk-pin \" ></span><span class= \" bk-home-art \" > " + img ( " bank.home. " + std :: to_string ( i ), 492 , 382 , false , true , 800 ) +
( count > 0 ? " <span class= \" bk-stamp \" ><span>EIGENTÜMER</span> " + ( count > 1 ? " <small> " + number ( count ) + " Stück</small> " : std :: string ()) + " </span> " : std :: string ()) + " </span><strong> " + esc ( name ) + " </strong><span class= \" bk-home-price \" > " +
esc ( price ) + " </span> " , std :: string ( " bk-home " ) + ( chosen ? " sel " : " " ) + ( i % 2 ? " odd " : " " ),
" id= \" bank-property- " + std :: to_string ( i ) + " \" data-id= \" " + std :: to_string ( i ) + " \" aria-pressed= \" " + ( chosen ? " true " : " false " ) + " \" aria-label= \" " + esc ( name + " , " + price + ( count > 0 ? " , " + number ( count ) + " im Bestand " : " " )) + " \" " +
( real ? " " : " disab led =\" disabled \" " ));
}
out + = " </div></div> " ;
out + = " <div class= \" property-card offered-property \" ><h3>Kaufangebot " + std :: to_string ( bank_property_ + 1 ) + " von " + std :: to_string ( property_count ) + " </h3> " +
btn ( " property-next " , img ( engine_mode_ ? offer . at ( " image " ) . get < std :: string > () : " bank.property. " + std :: to_string ( bank_property_ ), 1150 , 653.5 , false , false , 1400 ),
" property-picture " , " id= \" property-next \" aria-label= \" Nächstes Immobilienangebot \" " ) +
" <h4> " + esc ( calm_name ( offer . at ( " name " ) . get < std :: string > ())) + " </h4> " + fact ( " Kaufpreis " , esc ( bank_money ( offer . at ( " price " ) . get < int64_t > ()))) +
fact ( " Anteil am Konto " , in_cash > 0 ? one ( offer . at ( " price " ) . get < int64_t > () * 100.0 / in_cash ) + " % " : std :: string ( " — " )) +
( offer . contains ( " maxToBuy " ) ? fact ( " Bezahlbar " , number ( offer . at ( " maxToBuy " ) . get < int64_t > ()) + " Stück " ) : std :: string ()) +
" <p class= \" property-hint \" >Das Bild anklicken, um das nächste Angebot zu seh en.</p ></div>" +
actions ( " Kaufen " , " property-buy " , " Verkaufen " , " property-sell " );
const auto & offer = assets . at ( " properties " )[ size_t ( bank_property_ )] ;
const auto held = finance . at ( " properties " )[ size_t ( bank_property_ )] . get < int64_t > ();
const auto price = offer . at ( " price " ) . get < int64_t > ();
out += " </div><div class= \" pg-row pg-grow \" style= \" align-items:stretch; \" ><div class= \" pg-panel pg-row pg-grow \" style= \" " + pg_css ( " gap:22px;padding:10px 16px; " ) + " \" ><div style= \" width: " + pg ( 300 ) + " ; \" > " + pg_kicker ( " Ausgewählt " ) +
" <h3 class= \" pg-h \" style= \" font-size: " + pg ( 24 ) + " ;line-height: " + pg ( 30 ) + " ; \" > " + esc ( calm_name ( offer . at ( " name " ) . get < std :: string > ())) + " </h3><strong class= \" pg-big \" > " + esc ( bank_money ( price )) + " </strong></div><div class= \" pg-grow \" > " +
kv ( " Im Bestand " , number ( held ) + " Stück " ) + kv ( " Wert heute " , esc ( bank_money ( held * price ))) + kv ( " Anteil am Konto " , in_cash > 0 ? one ( price * 100.0 / in_cash ) + " % " : std :: string ( " — " )) +
( offer . contains ( " maxToBuy " ) ? kv ( " Bezahlbar " , number ( offer . at ( " maxToBuy " ) . get < int64_t > ()) + " Stück " ) : kv ( " Auf dem Konto " , esc ( bank_money ( in_cash )))) + " </div></div><div class= \" pg-col \" style= \" width: " + pg ( 300 ) + " ;flex:none;justify-content:center; " + pg_css ( " gap:8px; " ) + " \" > " +
calc ( " Kaufen " , " property-buy " , " primary bk-wide " ) + calc ( " Verkaufen " , " property-sell " , " bk-wide " , held > 0 ) + " <span class= \" pg-mut \" style= \" display:block;text-align:center;font-size: " + pg ( 12.5 ) + " ; \" >Ein Haus am Brett anklicken, dann kaufen oder verkauf en.</span ></div></div> " ;
} else if ( bank_view_ == " stocks " ) {
const auto move = [ & ]( double from , double to ) {
if ( from <= 0 ) return std :: string ( " <span class= \" stoc k-move flat\" >—</span> " );
if ( from <= 0 ) return std :: string ( " <span class= \" b k-move flat\" >—</span> " );
const double change = ( to - from ) * 100.0 / from ;
return std :: string ( " <span class= \" stoc k-move " ) + ( change > 0.05 ? " up " : change < - 0.05 ? " down " : " flat " ) + " \" > " +
( change > 0.05 ? " ▲ + " : change < - 0.05 ? " ▼ − " : " " ) + one ( std :: abs ( change )) + " %</span> " ;
return std :: string ( " <span class= \" b k-move " ) + ( change > 0.05 ? " up " : change < - 0.05 ? " down " : " flat " ) + " \" > " + ( change > 0.05 ? " ▲ + " : change < - 0.05 ? " ▼ − " : " " ) + one ( std :: abs ( change )) + " %</span> " ;
};
out + = " <div class= \" stock-table \" ><div class= \" stock-row stock-head \" > " ;
for ( const auto * label : { " Wert " , " 30 Tage " , " Kurs " , " zum Vortag " , " Bestand " }) out += " <div><span> " + std :: string ( label ) + " </span></div> " ;
out + = " </div> " ;
int held_papers = 0 ;
for ( const auto & held : finance . at ( " stocks " )) if ( held . get < int64_t > () > 0 ) ++ held_papers ;
page_title_ = " Aktien " ;
page_hint_ = " Depotwert " + bank_money ( in_stock );
out += " <div class= \" pg-row pg-grow \" style= \" align-items:stretch; \" ><div class= \" pg-col pg-grow \" style= \" " + pg_css ( " gap:10px; " ) + " \" > " + banner ( " bank.scene.stocks " , 700 , 96 , " Depot " , bank_money ( in_stock ), std :: to_string ( held_papers ) + " von " + std :: to_string ( stock_count ) + " Papieren im Bestand " ) +
" <div class= \" pg-panel pg-col pg-grow \" style= \" " + pg_css ( " gap:0px;padding:4px 14px; " ) + " \" ><div class= \" bk-row head \" ><span class= \" bk-name \" >WERT</span><span class= \" bk-spark \" >30 TAGE</span><span class= \" bk-num \" >KURS</span><span class= \" bk-num wide \" >ZUM VORTAG</span><span class= \" bk-num \" >BESTAND</span></div> " ;
for ( int i = 0 ; i < stock_count ; ++ i ) {
const auto & s = assets . at ( " stocks " )[ size_t ( i )];
const auto history = course ( i );
@@ -163,27 +145,27 @@ std::string App::render_bank() {
spark += " <polyline points= \" " + points + " \" fill= \" none \" stroke= \" " + ( history . back () >= history . front () ? up : down ) + " \" stroke-width= \" 4 \" stroke-linejoin= \" round \" stroke-linecap= \" round \" /> " ;
}
spark += " </svg> " ;
out += " <div class= \" stock-row " + std :: string ( i == bank_stock_ ? " chosen " : " " ) + " \" ><div> " + btn ( " bank-stock " , esc ( s . at ( " name " ) . get < std :: string > ()), " stock-name " ,
" id= \" bank-stock- " + std :: to_string ( i ) + " \" data-bank-stock= \" " + std :: to_string ( i ) + " \" data-id= \" " + std :: to_string ( i ) +
" \" aria-pressed= \" " + ( i == bank_stock_ ? " true " : " false " ) + " \" " ) + " </div><div >" + picture ( renderer_ . diagram ( " bank-spark- " + std :: to_string ( i ), spark , 480 ), 240 , 60 ) +
" </div><div><span> " + number ( s . at ( " price " ) . get < int64_t > () / factor ) + " </span></div><div> " + move ( s . at ( " previous " ) . get < double > (), s . at ( " price " ) . get < double > ()) +
" </div><div><span> " + number ( finance . at ( " stocks " )[ size_t ( i )] . get < int64_t > ()) + " </span></div></div> " ;
const bool chosen = i == bank_stock_ ;
out += btn ( " bank-stock " , " <span class= \" bk-name \" > " + esc ( s . at ( " name " ) . get < std :: string > ()) + " </span><span class= \" bk-spark \" > " + picture ( renderer_ . diagram ( " bank-spark- " + std :: to_string ( i ) + " - " + theme_ , spark , 480 ), 216 , 54 ) + " </span><span class= \" bk-num \" > " +
number ( s . at ( " price " ) . get < int64_t > () / factor ) + " </span><span class= \" bk-num wide \" > " + move ( s . at ( " previous " ) . get < double > (), s . at ( " price " ) . get < double > ()) + " </span><span class= \" bk-num \" > " + number ( finance . at ( " stocks " )[ size_t ( i )] . get < int64_t > ()) + " </span> " ,
std :: string ( " bk-row " ) + ( chosen ? " sel " : " " ), " id= \" bank-stock- " + std :: to_string ( i ) + " \" data-bank-stock= \" " + std :: to_string ( i ) + " \" data-id= \" " + std :: to_string ( i ) + " \" aria-pressed= \" " + ( chosen ? " true " : " false " ) + " \" " );
}
out += " </div> " ;
out += " </div></div> " ;
// the chosen stock: its course with a five-day average, its range, and what the numbers say
const auto & chosen = assets . at ( " stocks " )[ size_t ( bank_stock_ )];
const auto history = course ( bank_stock_ );
const double price = chosen . at ( " price " ) . get < double > () / factor ;
out += " <div class= \" stock-detail \" ><h3> " + esc ( chosen . at ( " name " ) . get < std :: string > () ) + " </h3 ><div class=\" stock-quote \" ><strong> " + number ( chosen . at ( " price " ) . get < int64_t > () / factor ) +
" </strong> " + move ( chosen . at ( " previous " ) . get < double > (), chosen . at ( " price " ) . get < double > ()) + " </div> " ;
const auto held = finance . at ( " stocks " )[ size_t ( bank_stock_ )] . get < int64_t > ();
out += " <div class= \" pg-col \" style= \" width: " + pg ( 520 ) + " ;flex:none; " + pg_css ( " gap:10px; " ) + " \" ><div class= \" pg-panel pg-col pg-grow \" style= \" " + pg_css ( " gap:8px;padding:12px 16px; " ) + " \" ><div class= \" pg-row \" style= \" justify-content:space-between;align-items:flex-end; \" ><div> " +
pg_kicker ( " Ausgewähltes Papier " ) + " <h3 class= \" pg-h \" style= \" font-size: " + pg ( 24 ) + " ;line-height: " + pg ( 30 ) + " ; \" > " + esc ( chosen . at ( " name " ) . get < std :: string > ()) + " </h3></div><div class= \" pg-row \" style= \" " + pg_css ( " gap:10px; " ) + " \" ><strong class= \" pg-big \" > " +
number ( chosen . at ( " price " ) . get < int64_t > () / factor ) + " </strong> " + move ( chosen . at ( " previous " ) . get < double > (), chosen . at ( " price " ) . get < double > ()) + " </div></div> " ;
if ( history . size () > 1 ) {
const double lo = * std :: min_element ( history . begin (), history . end ()), hi = * std :: max_element ( history . begin (), history . end ());
const double floor = lo * . 97 , ceiling = std :: max ( floor + 1. , hi * 1.03 );
const auto px = [ & ]( size_t at ) { return 30 + at * 860.0 / ( history . size () - 1 ); };
const auto py = [ & ]( double value ) { return 470 - ( value - floor ) / ( ceiling - floor ) * 430 ; };
std :: string svg = " <svg xmlns= \" http://www.w3.org/2000/svg \" viewBox= \" 0 0 920 50 0 \" ><defs><linearGradient id= \" under \" x1= \" 0 \" y1= \" 0 \" x2= \" 0 \" y2= \" 1 \" ><stop offset= \" 0 \" stop-color= \" " +
line + " \" stop-opacity= \" .32 \" /><stop offset= \" 1 \" stop-color= \" " + line + " \" stop-opacity= \" .02 \" /></linearGradient></defs> " ;
for ( int row = 0 ; row < 5 ; ++ row ) svg += " <line x1= \" 30 \" y1= \" " + scalar ( 40 + row * 107.5 ) + " \" x2= \" 890 \" y2= \" " + scalar ( 40 + row * 107.5 ) + " \" stroke= \" " + faint + " \" stroke-width= \" 2 \" /> " ;
const auto py = [ & ]( double value ) { return 450 - ( value - floor ) / ( ceiling - floor ) * 420 ; };
std :: string svg = " <svg xmlns= \" http://www.w3.org/2000/svg \" viewBox= \" 0 0 920 47 0 \" ><defs><linearGradient id= \" under \" x1= \" 0 \" y1= \" 0 \" x2= \" 0 \" y2= \" 1 \" ><stop offset= \" 0 \" stop-color= \" " + line + " \" stop-opacity= \" .3 \" /><stop offset= \" 1 \" stop-color= \" " + line +
" \" stop-opacity= \" .02 \" /></linearGradient></defs> " ;
for ( int row = 0 ; row < 5 ; ++ row ) svg += " <line x1= \" 30 \" y1= \" " + scalar ( 30 + row * 105 ) + " \" x2= \" 890 \" y2= \" " + scalar ( 30 + row * 105 ) + " \" stroke= \" " + faint + " \" stroke-width= \" 2 \" /> " ;
std :: string points , average ;
size_t high_at = 0 , low_at = 0 ;
for ( size_t at = 0 ; at < history . size (); ++ at ) {
@@ -196,11 +178,9 @@ std::string App::render_bank() {
average += scalar ( px ( at )) + " , " + scalar ( py ( sum / 5 )) + " " ;
}
}
svg += " <polygon points= \" 30,47 0 " + points + " 890,47 0 \" fill= \" url(#under) \" /><polyline points= \" " + average + " \" fill= \" none \" stroke= \" " + gold +
" \" stroke-width= \" 4 \" stroke-dasharray= \" 12 9 \" /><polyline points =\" " + points + " \" fill= \" none \" stroke= \" " + line +
" \" stroke-width = \" 6 \" stroke-linejoin= \" round \" stroke-linecap= \" round \" /><circle cx= \" " + scalar ( px ( high_at )) + " \" cy= \" " + scalar ( py ( history [ high_at ] )) +
" \" r= \" 9 \" fill= \" " + up + " \" /><circle cx= \" " + scalar ( px ( low_at )) + " \" cy= \" " + scalar ( py ( history [ low_at ])) + " \" r= \" 9 \" fill= \" " + down +
" \" /><circle cx= \" " + scalar ( px ( history . size () - 1 )) + " \" cy= \" " + scalar ( py ( history . back ())) + " \" r= \" 10 \" fill= \" " + line + " \" stroke= \" " + ink + " \" stroke-width= \" 3 \" /></svg> " ;
svg += " <polygon points= \" 30,45 0 " + points + " 890,45 0 \" fill= \" url(#under) \" /><polyline points= \" " + average + " \" fill= \" none \" stroke= \" " + gold + " \" stroke-width= \" 4 \" stroke-dasharray= \" 12 9 \" /><polyline points= \" " + points + " \" fill= \" none \" stroke= \" " + line +
" \" stroke-width= \" 6 \" stroke-linejoin= \" round \" stroke-linecap= \" round \" /><circle cx =\" " + scalar ( px ( high_at )) + " \" cy= \" " + scalar ( py ( history [ high_at ])) + " \" r= \" 9 \" fill= \" " + up + " \" /><circle cx= \" " + scalar ( px ( low_at )) + " \" cy= \" " + scalar ( py ( history [ low_at ])) +
" \" r = \" 9 \" fill= \" " + down + " \" /><circle cx= \" " + scalar ( px ( history . size () - 1 )) + " \" cy= \" " + scalar ( py ( history . back () )) + " \" r= \" 10 \" fill= \" " + line + " \" stroke= \" " + ink + " \" stroke-width= \" 3 \" /></svg> " ;
double mean = 0 , spread = 0 ;
for ( const double value : history ) mean += value ;
mean /= double ( history . size ());
@@ -208,78 +188,37 @@ std::string App::render_bank() {
spread = mean > 0 ? std :: sqrt ( spread / double ( history . size ())) * 100.0 / mean : 0 ;
const double trend = history . front () > 0 ? ( history . back () - history . front ()) * 100.0 / history . front () : 0 ;
const double below = hi > 0 ? ( hi - history . back ()) * 100.0 / hi : 0 ;
const auto held = finance . at ( " stocks " )[ size_t ( bank_stock_ )] . get < int64_t > ();
const auto tile = []( const std :: string & label , const std :: string & value , const char * tone = " " ) {
return " <div class= \" stock-tile " + std :: string ( tone ) + " \" ><strong> " + value + " </strong><span> " + label + " </span></div> " ;
const auto tile = []( const std :: string & label , const std :: string & value , const std :: string & tone = std :: string ()) {
return " <div class= \" bk-tile \" ><strong class= \" " + tone + " \" > " + value + " </strong><span> " + label + " </span></div> " ;
};
out += " <div class= \" stock-chart \" role= \" img \" aria-label= \" " + std :: string ( engine_mode_ ? " Kursverlauf aus dem Spielstand für " : " Erfundener Kursverlauf für " ) +
esc ( chosen . at ( " name " ) . get < std :: string > ()) + " \" > " + picture ( renderer_ . diagram ( " bank-stock " , svg , 1840 ), 920 , 500 ) + " </div> "
" <div class= \" stock-legend \" ><span class= \" key course \" > </span><span>Kurs</span><span class= \" key average \" ></span><span>Fünf-Tage-Schnitt</span><span class= \" key high \" ></span><span>Hoch</span><span class= \" key low \" ></span><span>Tief</span></div> "
" <div class= \" stock-tiles \" > " +
tile ( " Hoch " , number ( int64_t ( std :: llround ( hi )))) + tile ( " Tief " , number ( int64_t ( std :: llround ( lo )))) +
tile ( std :: to_string ( history . size ()) + " Tage " , ( trend > 0 ? " + " : trend < 0 ? " − " : " " ) + one ( std :: abs ( trend )) + " % " , trend > 0.05 ? " up " : trend < - 0.05 ? " down " : " " ) +
tile ( " Schwankung " , one ( spread ) + " % " ) + tile ( " Depotwert " , esc ( bank_money ( held * chosen . at ( " price " ) . get < int64_t > ()))) +
( chosen . contains ( " maxToBuy " ) ? tile ( " Kaufbar " , number ( chosen . at ( " maxToBuy " ) . get < int64_t > ())) : tile ( " Bestand " , number ( held )) ) + " </div > "
" <div class= \" bank-insight \" ><h4>Analyse</h4><p > " +
std :: string ( trend > 5 ? " Aufwärtstrend: " : trend < - 5 ? " Abwärtstrend: " : " Seitwärtsbewegung: " ) + " über " + std :: to_string ( history . size ()) + " Tage " +
( trend > 0 ? " + " : trend < 0 ? " − " : " " ) + one ( std :: abs ( trend )) + " %. " +
( below < 0.5 ? " Der Kurs steht am Hoch dieses Zeitraums. " : " Der Kurs liegt " + one ( below ) + " % unter dem Hoch dieses Zeitraums. " ) + " " +
( spread > 12 ? " Das Papier schwankt stark. " : spread > 5 ? " Das Papier schwankt mäßig. " : " Das Papier läuft ruhig. " ) + " </p></div> " ;
( void ) price ;
} else out += " <p class= \" player-card-none \" >Für dieses Papier liegt noch kein Kursverlauf vor.</p> " ;
out += " </ div> " + actions ( " Kaufen " , " stock-buy " , " Verkaufen " , " stock-sell " );
} else if ( bank_view_ == " credit " ) {
if ( engine_mode_ ) return out + engine_credit_view () + " </section></div> " ;
out += " <div class= \" credit-portrait \" > " + img ( " art.bank-adviser-v1.png " , 620 , 515 , false , false , 1000 ) +
" </ div><div class= \" credit-facts \" > " ;
const auto fact = [ & ]( const char * label , const std :: string & value , int row ) {
constexpr std :: array < int , 5 > y { 0 , 83 , 166 , 273 , 356 };
return " <div class= \" credit-fact \" style= \" top: " + std :: to_string ( y [ size_t ( row )]) + " dp; \" ><span> " + label + " </span><strong> " + value + " </strong></div> " ;
};
out += fact ( " Restschuld " , esc ( bank_money ( summary . at ( " debt " ) . get < int64_t > ())), 0 ) + fact ( " Beispielzins " , " 8 % pro Jahr " , 1 );
std :: string select = " <select id= \" bank-term \" aria-label= \" Kreditlaufzeit \" " + std :: string ( summary . at ( " debt " ) == 0 ? " " : " disabled " ) + " > " ;
for ( const auto & term : demo_bank_terms ()) select += " <option value= \" " + std :: to_string ( term . get < int > ()) + " \" " +
std :: string ( term == finance . at ( " term " ) ? " selected " : " " ) + " > " + std :: to_string ( term . get < int > ()) + " Monate</option> " ;
out += fact ( " Laufzeit " , select + " </select> " , 2 ) + fact ( " Monatsrate, Beispiel " , esc ( bank_money ( summary . at ( " monthly_rate " ) . get < int64_t > ())), 3 ) +
fact ( " Maximaler Kredit " , esc ( bank_money ( 5000000 * finance_currency_factor ( * world_ ))), 4 ) + " </div> " ;
const int term = finance . at ( " term " );
const auto principal = summary . at ( " schedule_principal " ) . get < int64_t > ();
std :: string svg = " <svg xmlns= \" http://www.w3.org/2000/svg \" width= \" 2240 \" height= \" 420 \" viewBox= \" 0 0 2240 420 \" > "
" <defs><linearGradient id= \" fill \" x1= \" 0 \" y1= \" 0 \" x2= \" 0 \" y2= \" 1 \" ><stop offset= \" 0 \" stop-color= \" " + line + " \" stop-opacity= \" .28 \" /> "
" <stop offset= \" 1 \" stop-color= \" " + line + " \" stop-opacity= \" .02 \" /></linearGradient></defs> " ;
for ( int i = 0 ; i < 5 ; ++ i ) {
const auto y = 30 + i * 77.5 ;
svg += " <line x1= \" 220 \" y1= \" " + scalar ( y ) + " \" x2= \" 2180 \" y2= \" " + scalar ( y ) + " \" stroke= \" " + faint + " \" stroke-width= \" 2 \" /> "
" <text x= \" 184 \" y= \" " + scalar ( y + 9 ) + " \" text-anchor= \" end \" fill= \" " + ink + " \" font-size= \" 28 \" font-family= \" Arial, Liberation Sans, sans-serif \" > " +
esc ( bank_money (( principal * ( 4 - i ) + 2 ) / 4 )) + " </text> " ;
out += " <div class= \" bk-chart \" role= \" img \" aria-label= \" " + std :: string ( engine_mode_ ? " Kursverlauf aus dem Spielstand für " : " Erfundener Kursverlauf für " ) + esc ( chosen . at ( " name " ) . get < std :: string > ()) + " \" > " +
picture ( renderer_ . diagram ( " bank-stock- " + theme_ , svg , 1840 ), 1098 , 561 ) + " </div><div class= \" pg-legend \" ><span class= \" pg-legend-item \" ><span class= \" pg-legend-mark \" style= \" background-color: " + line +
" ; \" ></ span><span>Kurs </span></ span><span class= \" pg-legend-item \" ><span class= \" pg-legend-mark \" style= \" background-color: " + gold + " ; \" ></span><span>Fünf-Tage-Schnitt</span></span>< span class= \" pg-legend-item \" ><span class= \" pg-legend-mark \" style= \" background-color: " + up +
" ; \" ></span><span>Hoch</span></span><span class= \" pg-legend-item \" ><span class= \" pg-legend-mark \" style= \" background-color: " + down + " ; \" ></span><span>Tief</span></span></div> <div class=\" bk-tiles \" > " +
tile ( " Hoch " , number ( int64_t ( std :: llround ( hi )))) + tile ( " Tief " , number ( int64_t ( std :: llround ( lo )))) + tile ( std :: to_string ( history . size ()) + " Tage " , ( trend > 0 ? " + " : trend < 0 ? " − " : " " ) + one ( std :: abs ( trend )) + " % " , trend > 0.05 ? " ad-plus " : trend < - 0.05 ? " ad-minus " : " " ) +
tile ( " Schwankung " , one ( spread ) + " % " ) + tile ( " Depotwert " , esc ( bank_money ( held * chosen . at ( " price " ) . get < int64_t > ()))) + ( chosen . contains ( " maxToBuy " ) ? tile ( " Kaufbar " , number ( chosen . at ( " maxToBuy " ) . get < int64_t > ())) : tile ( " Bestand " , number ( held )) ) +
" </div><span class= \" pg-mut bk-reading \" > " + std :: string ( trend > 5 ? " Aufwärtstrend: " : trend < - 5 ? " Abwärtstrend: " : " Seitwärtsbewegung: " ) + " über " + std :: to_string ( history . size () ) + " Tage " + ( trend > 0 ? " + " : trend < 0 ? " − " : " " ) + one ( std :: abs ( trend )) + " %. " +
( below < 0.5 ? " Der Kurs steht am Hoch dieses Zeitraums. " : " Der Kurs liegt " + one ( below ) + " % unter dem Hoch dieses Zeitraums. " ) + " " + ( spread > 12 ? " Das Papier schwankt stark. " : spread > 5 ? " Das Papier schwankt mäßig. " : " Das Papier läuft ruhig. " ) + " </span > " ;
} else out += " <div class= \" pg-empty \" ><span>Für dieses Papier liegt noch kein Kursverlauf vor.</span></div > " ;
out += " </div><div class= \" pg-row \" style= \" " + pg_css ( " gap:8px; " ) + " \" > " + calc ( " Kaufen " , " stock-buy " , " primary block " ) + calc ( " Verkaufen " , " stock-sell " , " block " , held > 0 ) + " </div></div></div> " ;
} else if ( bank_view_ == " players " ) {
// the other humans of this career; dealings between them are not in the game yet
const auto people = bank_players () ;
page_title_ = " Spieler " ;
page_hint_ = std :: to_string ( people . size ()) + " Manager an einem Tisch " ;
out += " <div class= \" pg-row pg-grow \" style= \" align-items:stretch; \" > " + banner ( " bank.scene.players " , 700 , 648 , " Unter Managern " , " Geschäfte mit Mitspielern " , " Noch nicht im Spiel " ) + " <div class= \" pg-col pg-grow \" ><div class= \" pg-panel pg-col \" style= \" " + pg_css ( " gap:6px; " ) + " \" > " +
pg_kicker ( " Mitspieler " );
for ( const auto & person : people ) {
const auto * club = world_ -> find ( " clubs " , person . value ( " club " , " " ));
out += " <div class= \" fl-manager \" > " + ( club ? crest ( club , 72 ) : std :: string ()) + " <div><strong> " + esc ( person . value ( " name " , " " )) + " </strong><span class=\" pg-mut \" > " + esc ( club ? world_ -> name ( * club ) : std :: string ()) + " </span></div></div> " ;
}
const int interval = term <= 12 ? 3 : term <= 24 ? 6 : 12 ;
std :: vector < int > labels ;
for ( int month = 0 ; month <= term ; month += interval ) labels . push_back ( month );
if ( labels . back () ! = term ) labels . push_back ( term ) ;
for ( const int month : labels ) {
svg += " <text x= \" " + scalar ( 220 + double ( month ) / term * 1960 ) + " \" y= \" 394 \" text-anchor= \" " +
std :: string ( month == 0 ? " start " : month == term ? " end " : " middle " ) + " \" fill= \" " + ink +
" \" font-size= \" 28 \" font-family= \" Arial, Liberation Sans, sans-serif \" > " + ( month == 0 ? " Heute " : std :: to_string ( month ) + ( month == term ? " Monate " : " " )) + " </text> " ;
}
std :: string points ;
for ( const auto & point : summary . at ( " schedule " )) points += scalar ( 220 + point . at ( " month " ) . get < double > () / term * 1960 ) + " , " +
scalar ( 340 - point . at ( " remaining " ) . get < double > () / principal * 310 ) + " " ;
svg += " <path d= \" M220 340 L220 30 L2180 340 Z \" fill= \" url(#fill) \" /><polyline points= \" " + points + " \" fill= \" none \" stroke= \" " +
line + " \" stroke-width= \" 6 \" stroke-linecap= \" round \" stroke-linejoin= \" round \" /><circle cx= \" 220 \" cy= \" 30 \" r= \" 9 \" fill= \" " + gold + " \" /> "
" <circle cx= \" 2180 \" cy= \" 340 \" r= \" 9 \" fill= \" " + gold + " \" /></svg> " ;
out += " <figure class= \" credit-schedule \" ><div class= \" credit-schedule-caption \" ><h3>Restschuld über die Laufzeit</h3><p class= \" credit-schedule-amount \" > " +
esc ( bank_money ( principal )) + " <span>→</span> " + esc ( bank_money ( 0 )) + " </p><div class= \" credit-schedule-context \" ><span> " + std :: to_string ( term ) +
" Monate</span><p> " + ( summary . at ( " schedule_example " ) == true ? " Beispiel · kein laufender Kredit " : " Aktueller Kredit " ) +
" </p></div></div><div class= \" credit-chart \" role= \" img \" aria-label= \" Restschuld über " + std :: to_string ( term ) +
" Monate bei gleichmäßiger Tilgung ohne Zinsen \" > " + picture ( renderer_ . diagram ( " bank-credit " , svg , 2400 ), 2432 , 420 ) +
" </div><p class= \" credit-schedule-note \" >Gleichmäßige monatliche Tilgung · Restschuld ohne Zinsen</p></figure> "
" <p class= \" bank-note credit-note \" >Fiktiver Kredit. Im POC erfolgen keine Zins- oder Ratenbuchungen.</p> " + actions ( " Aufnehmen " , " loan " , " Tilgen " , " repay " );
} else if ( bank_view_ == " overview " ) {
// where the money lies: a ring by share, the four places with their sums, and a reading of it
out + = " </div><span class= \" pg-sp \" ></span><span class= \" pg-mut \" style= \" display:block; \" >Hier sollen Manager einander Geld leihen und Geschäfte abschließen können. Das Spiel kennt solche Geschäfte noch nicht; die Seite zeigt vorerst nur, wer mitspielt.</span></div></div> " ;
} else {
// the bank: where the money lies, and the loan
page_title_ = " Bank " ;
page_hint_ = " Waldpark Bank · Vermögen und Kredit " ;
struct Part { const char * label ; int64_t value ; const char * colour ; };
const std :: array < Part , 4 > parts {{{ " Konto " , std :: max < int64_t > ( 0 , in_cash ), " #2f 6f8f " }, { " Sparbuch " , in_deposit , " #c9a24a " },
{ " Immobilien " , in_property , " #6f8a52 " }, { " Aktien " , in_stock , " #a8574f " }}};
const std :: array < Part , 4 > parts {{{ " Konto " , std :: max < int64_t > ( 0 , in_cash ), " #2b 6f8f " }, { " Sparbuch " , in_deposit , " #d08a1e " }, { " Immobilien " , in_property , " #56633f " }, { " Aktien " , in_stock , " #a8452f " }}};
const double around = 2 * 3.14159265358979 * 300 ;
std :: string ring = " <svg xmlns= \" http://www.w3.org/2000/svg \" viewBox= \" 0 0 800 800 \" ><circle cx= \" 400 \" cy= \" 400 \" r= \" 300 \" fill= \" none \" stroke= \" " + faint + " \" stroke-width= \" 110 \" /> " ;
double turned = 0 ;
@@ -287,58 +226,45 @@ std::string App::render_bank() {
if ( wealth <= 0 || part . value <= 0 ) continue ;
const double length = around * double ( part . value ) / double ( wealth );
if ( part . value == wealth ) { ring += " <circle cx= \" 400 \" cy= \" 400 \" r= \" 300 \" fill= \" none \" stroke= \" " + std :: string ( part . colour ) + " \" stroke-width= \" 110 \" /> " ; break ; }
ring += " <circle cx= \" 400 \" cy= \" 400 \" r= \" 300 \" fill= \" none \" stroke= \" " + std :: string ( part . colour ) + " \" stroke-width= \" 110 \" stroke-dasharray= \" " + scalar ( length ) + " " +
scalar ( around - length ) + " \" stroke-dashoffset= \" " + scalar ( - turned ) + " \" transform= \" rotate(-90 400 400) \" /> " ;
ring += " <circle cx= \" 400 \" cy= \" 400 \" r= \" 300 \" fill= \" none \" stroke= \" " + std :: string ( part . colour ) + " \" stroke-width= \" 110 \" stroke-dasharray= \" " + scalar ( length ) + " " + scalar ( around - length ) + " \" stroke-dashoffset= \" " + scalar ( - turned ) + " \" transform= \" rotate(-90 400 400) \" /> " ;
turned += length ;
}
ring += " </svg> " ;
out += " <div class= \" bank-ring \" > " + picture ( renderer_ . diagram ( " bank-ring " , ring , 1600 ), 860 , 860 ) + " <div class= \" bank-ring-centre \" ><span>Vermögen</span><strong> " +
esc ( bank_money ( wealth ) ) + " </strong ></ div> </div><div class=\" bank-parts \" > " ;
out += " <div class= \" pg-row pg-grow \" style= \" align-items:stretch; \" ><div class= \" pg-col \" style= \" width: " + pg ( 590 ) + " ;flex:none; " + pg_css ( " gap:10px; " ) + " \" > " + banner ( " bank.scene.overview " , 590 , 196 , " Vermögen " , bank_money ( wealth ), " Konto, Sparbuch, Immobilien und Aktien " ) +
" <div class= \" pg-panel pg-row pg-grow \" style= \" " + pg_css ( " gap:16px;padding:12px 16px; " ) + " \" ><div class= \" bk-ring \" > " + picture ( renderer_ . diagram ( " bank-ring- " + theme_ , ring , 900 ), 400 , 400 ) + " </div><div class= \" pg-grow \" > " ;
const Part * largest = & parts [ 0 ];
for ( const auto & part : parts ) {
if ( part . value > largest -> value ) largest = & part ;
const double width = wealth > 0 ? std :: max < int64_t > ( 0 , part . value ) * 100.0 / wealth : 0 ;
out += " <div class= \" bank-part \" ><div class= \" bank-part-line \" ><span class= \" chip \" style= \" background-color: " + std :: string ( part . colour ) + " ; \" ></span><span class= \" label \" > " + part . label +
" </span><strong> " + esc ( bank_money ( std :: string ( part . label ) == " Konto " ? in_cash : part . value )) + " </strong><span class= \" share \" > " + share ( part . value ) +
" </span></div><div class= \" bank-part-track \" ><div style= \" width: " + scalar ( width ) + " %;background-color: " + part . colour + " ; \" ></div></div></div> " ;
out += " <div class= \" bk-part \" ><div class= \" pg-row \" style= \" " + pg_css ( " gap:8px; " ) + " \" ><span class= \" bk-chip \" style= \" background-color: " + std :: string ( part . colour ) + " ; \" ></span><span class= \" pg-grow \" > " + part . label + " </span><strong> " +
esc ( bank_money ( std :: string ( part . label ) == " Konto " ? in_cash : part . value )) + " </strong><span class= \" pg-mut bk-share \" > " + share ( part . value ) + " </span></div><div class= \" pg-bar \" ><div style= \" width: " + scalar ( width ) + " %;background-color: " + part . colour + " ; \" ></div></div></div> " ;
}
if ( engine_mode_ )
out += " <div class= \" bank-part plain \" ><div class= \" bank-part-line \" ><span class= \" chip none \" ></span><span class= \" label \" >Kreditlinie</span><strong> " +
esc ( bank_money ( summary . at ( " credit_line " ) . get < int64_t > ())) + " </strong><span class= \" share \" ></span></div></div> " ;
else
out += " <div class= \" bank-part plain \" ><div class= \" bank-part-line \" ><span class= \" chip none \" ></span><span class= \" label \" >Kredit</span><strong>− " +
esc ( bank_money ( summary . at ( " debt " ) . get < int64_t > ())) + " </strong><span class= \" share \" ></span></div></div> "
" <div class= \" bank-part plain \" ><div class= \" bank-part-line \" ><span class= \" chip none \" ></span><span class= \" label \" >Saldo</span><strong> " +
esc ( bank_money ( summary . at ( " net " ) . get < int64_t > ())) + " </strong><span class= \" share \" ></span></div></div> " ;
out += " </div><div class= \" bank-insight overview-insight \" ><h4>Analyse</h4><p> " ;
out += engine_mode_ ? kv ( " Kreditlinie " , esc ( bank_money ( summary . at ( " credit_line " ) . get < int64_t > ()))) : kv ( " Kredit " , " − " + esc ( bank_money ( summary . at ( " debt " ) . get < int64_t > ()))) + kv ( " Saldo " , esc ( bank_money ( summary . at ( " net " ) . get < int64_t > ())));
out += " </ div></ div><span class= \" pg-mut bk-reading \" > " ;
if ( wealth > 0 ) {
const int64_t invested = in_deposit + in_property + in_stock ;
out += " Größter Posten: " + std :: string ( largest -> label ) + " mit " + share ( largest -> value ) + " des Vermögens. " +
( invested > 0 ? " Angelegt in Sparbuch, Immobilien und Aktien sind " + share ( invested ) + " . "
: std :: string ( " Bisher ist nichts angelegt: Das ganze Vermögen liegt auf dem Konto. " ));
( invested > 0 ? " Angelegt in Sparbuch, Immobilien und Aktien sind " + share ( invested ) + " . " : std :: string ( " Bisher ist nichts angelegt: Das ganze Vermögen liegt auf dem Konto. " ));
} else out += " Es ist kein Vermögen vorhanden. " ;
out += " </p ></div> " ;
// the market at a glance: every stock's change over its recorded days
std :: vector < std :: pair < std :: string , double >> market ;
double widest = 1 ;
for ( int i = 0 ; i < stock_count ; ++ i ) {
const auto history = course ( i ) ;
if ( history . size () < 2 || history . front () <= 0 ) continue ;
const double change = ( history . back () - history . front ()) * 100.0 / history . front ();
market . emplace_back ( assets . at ( " stocks " )[ size_t ( i )] . at ( " name " ) . get < std :: string > (), change ) ;
widest = std :: max ( widest , std :: abs ( change )) ;
out += " </span ></div><div class= \" pg-col pg-grow \" style= \" " + pg_css ( " gap:10px; " ) + " \" > " ;
if ( engine_mode_ ) out += engine_credit_view ();
else {
const int term = finance . at ( " term " ) ;
std :: string select = " <select id= \" bank-term \" class= \" bk-select \" aria-label= \" Kreditlaufzeit \" " + std :: string ( summary . at ( " debt " ) == 0 ? " " : " disabled " ) + " > " ;
for ( const auto & months : demo_bank_terms ()) select + = " <option value= \" " + std :: to_string ( months . get < int > ()) + " \" " + std :: string ( months == finance . at ( " term " ) ? " selected " : " " ) + " > " + std :: to_string ( months . get < int > ()) + " Monate</option> " ;
const auto principal = summary . at ( " schedule_principal " ) . get < int64_t > () ;
// the debt over the months: a straight line down to nothing
std :: string svg = " <svg xmlns= \" http://www.w3.org/2000/svg \" viewBox= \" 0 0 1000 300 \" ><path d= \" M20 20V270H980 \" fill= \" none \" stroke= \" " + faint + " \" stroke-width= \" 3 \" /><path d= \" M20 270L20 30L980 270Z \" fill= \" " + line + " \" fill-opacity= \" .14 \" /> " ;
std :: string points ;
for ( const auto & point : summary . at ( " schedule " )) points += scalar ( 20 + point . at ( " month " ) . get < double > () / term * 960 ) + " , " + scalar ( 270 - point . at ( " remaining " ) . get < double > () / std :: max < double > ( 1 , double ( principal )) * 240 ) + " " ;
svg += " <polyline points= \" " + points + " \" fill= \" none \" stroke= \" " + line + " \" stroke-width= \" 6 \" stroke-linecap= \" round \" stroke-linejoin= \" round \" /><circle cx= \" 20 \" cy= \" 30 \" r= \" 9 \" fill= \" " + gold + " \" /><circle cx= \" 980 \" cy= \" 270 \" r= \" 9 \" fill= \" " + gold + " \" /></svg> " ;
out += " <div class= \" pg-panel pg-col pg-grow \" style= \" " + pg_css ( " gap:6px;padding:12px 16px; " ) + " \" > " + pg_kicker ( " Kredit " ) + kv ( " Restschuld " , esc ( bank_money ( summary . at ( " debt " ) . get < int64_t > ()))) + kv ( " Beispielzins " , " 8 % pro Jahr " ) +
" <div class= \" pg-kv \" ><span>Laufzeit</span> " + select + " </select></div> " + kv ( " Monatsrate, Beispiel " , esc ( bank_money ( summary . at ( " monthly_rate " ) . get < int64_t > ()))) + kv ( " Maximaler Kredit " , esc ( bank_money ( 5000000 * finance_currency_factor ( * world_ )))) +
" <div class= \" bk-chart \" role= \" img \" aria-label= \" Restschuld über " + std :: to_string ( term ) + " Monate bei gleichmäßiger Tilgung ohne Zinsen \" > " + picture ( renderer_ . diagram ( " bank-credit- " + theme_ , svg , 1800 ), 1200 , 360 ) + " </div><span class= \" pg-mut \" style= \" display:block; \" > " +
esc ( bank_money ( principal )) + " über " + std :: to_string ( term ) + " Monate · " + ( summary . at ( " schedule_example " ) == true ? " Beispiel, kein laufender Kredit " : " aktueller Kredit " ) + " . Fiktiver Kredit ohne Zins- und Ratenbuchungen.</span></div><div class= \" pg-row \" style= \" " +
pg_css ( " gap:8px; " ) + " \" > " + calc ( " Aufnehmen " , " loan " , " primary block " ) + calc ( " Tilgen " , " repay " , " block " ) + " </div> " ;
}
if ( ! market . empty ()) {
out += " <div class= \" bank-market \" ><h4>Aktienmarkt · Veränderung über die aufgezeichneten Tage</h4><div class= \" bank-market-bars \" > " ;
for ( const auto & [ name , change ] : market ) {
const double height = std :: abs ( change ) / widest * 120 ;
out += " <div class= \" bank-market-column \" ><div class= \" rise \" > " + ( change > 0 ? " <span>+ " + one ( change ) + " %</span><div class= \" bar up \" style= \" height: " + scalar ( height ) + " dp; \" ></div> " : std :: string ()) +
" </div><div class= \" fall \" > " + ( change <= 0 ? " <div class= \" bar down \" style= \" height: " + scalar ( height ) + " dp; \" ></div><span>− " + one ( std :: abs ( change )) + " %</span> " : std :: string ()) +
" </div><strong> " + esc ( name ) + " </strong></div> " ;
}
out += " </div></div> " ;
}
out += " <p class= \" bank-note overview-note \" > " + std :: string ( engine_mode_ ? " Bestände und Kurse aus dem Spielstand. " : " Erfundene Bestände · Änderungen betreffen ausschließlich die Bankvorschau. " ) + " </p> " ;
out += " </div></div> " ;
}
return out + " </section></div> " ;
return out + " </section> " ;
}