| 1 | package BalanceOfPower::Nation; | ||
| 2 | $BalanceOfPower::Nation::VERSION = '0.200000'; | ||
| 3 | use strict; | ||
| 4 | use v5.10; | ||
| 5 | |||
| 6 | use Moo; | ||
| 7 | |||
| 8 | use BalanceOfPower::Utils qw( prev_turn ); | ||
| 9 | use BalanceOfPower::Constants ':all'; | ||
| 10 | |||
| 11 | with 'BalanceOfPower::Role::Reporter'; | ||
| 12 | with 'BalanceOfPower::Nation::Role::IA'; | ||
| 13 | with 'BalanceOfPower::Nation::Role::Shareholder'; | ||
| 14 | |||
| 15 | has name => ( | ||
| 16 | is => 'ro', | ||
| 17 | default => 'Dummyland' | ||
| 18 | ); | ||
| 19 | has code => ( | ||
| 20 | is => 'ro', | ||
| 21 | default => 'DUM' | ||
| 22 | ); | ||
| 23 | has area => ( | ||
| 24 | is => 'ro', | ||
| 25 | default => 'Neverwhere' | ||
| 26 | ); | ||
| 27 | |||
| 28 | |||
| 29 | has export_quote => ( | ||
| 30 | is => 'ro', | ||
| 31 | default => 50 | ||
| 32 | ); | ||
| 33 | has government => ( | ||
| 34 | is => 'ro', | ||
| 35 | default => 'democracy' | ||
| 36 | ); | ||
| 37 | has government_strength => ( | ||
| 38 | is => 'rw', | ||
| 39 | default => 70 | ||
| 40 | ); | ||
| 41 | has size => ( | ||
| 42 | is => 'ro', | ||
| 43 | default => 1 | ||
| 44 | ); | ||
| 45 | |||
| 46 | has internal_disorder => ( | ||
| 47 | is => 'rw', | ||
| 48 | default => 0 | ||
| 49 | ); | ||
| 50 | has production_for_domestic => ( | ||
| 51 | is => 'rw', | ||
| 52 | default => 0 | ||
| 53 | ); | ||
| 54 | has production_for_export => ( | ||
| 55 | is => 'rw', | ||
| 56 | default => 0 | ||
| 57 | ); | ||
| 58 | has prestige => ( | ||
| 59 | is => 'rw', | ||
| 60 | default => 0 | ||
| 61 | ); | ||
| 62 | has wealth => ( | ||
| 63 | is => 'rw', | ||
| 64 | default => 0 | ||
| 65 | ); | ||
| 66 | has debt => ( | ||
| 67 | is => 'rw', | ||
| 68 | default => 0 | ||
| 69 | ); | ||
| 70 | has rebel_provinces => ( | ||
| 71 | is => 'rw', | ||
| 72 | default => 0 | ||
| 73 | ); | ||
| 74 | has current_year => ( | ||
| 75 | is => 'rw' | ||
| 76 | ); | ||
| 77 | |||
| 78 | has army => ( | ||
| 79 | default => 0, | ||
| 80 | is => 'rw' | ||
| 81 | ); | ||
| 82 | |||
| 83 | has progress => ( | ||
| 84 | default => 0, | ||
| 85 | is => 'rw' | ||
| 86 | ); | ||
| 87 | |||
| 88 | has frozen_disorder => ( | ||
| 89 | default => 0, | ||
| 90 | is => 'rw' | ||
| 91 | ); | ||
| 92 | |||
| 93 | sub production | ||
| 94 | { | ||
| 95 | my $self = shift; | ||
| 96 | my $prod = shift; | ||
| 97 | if($prod) | ||
| 98 | { | ||
| 99 | if($prod <= DEBT_TO_RAISE_LIMIT && $self->debt < MAX_DEBT && DEBT_ALLOWED) | ||
| 100 | { | ||
| 101 | $prod += PRODUCTION_THROUGH_DEBT; | ||
| 102 | $self->debt($self->debt + 1); | ||
| 103 | $self->register_event("DEBT RISE"); | ||
| 104 | } | ||
| 105 | if($self->government eq 'dictatorship') | ||
| 106 | { | ||
| 107 | $prod -= DICTATORSHIP_PRODUCTION_MALUS; | ||
| 108 | } | ||
| 109 | my $internal = $prod - (($self->export_quote * $prod) / 100); | ||
| 110 | my $export = $prod - $internal; | ||
| 111 | $self->production_for_domestic($internal); | ||
| 112 | $self->production_for_export($export); | ||
| 113 | $self->register_event("PRODUCTION INT: $internal EXP: $export"); | ||
| 114 | } | ||
| 115 | return $self->production_for_domestic + $self->production_for_export; | ||
| 116 | } | ||
| 117 | |||
| 118 | sub calculate_internal_wealth | ||
| 119 | { | ||
| 120 | my $self = shift; | ||
| 121 | my $internal_production = $self->production_for_domestic(); | ||
| 122 | $self->add_wealth($internal_production * INTERNAL_PRODUCTION_GAIN); | ||
| 123 | $self->production_for_domestic(0); | ||
| 124 | $self->register_event("INTERNAL " . $internal_production); | ||
| 125 | } | ||
| 126 | |||
| 127 | sub calculate_trading | ||
| 128 | { | ||
| 129 | my $self = shift; | ||
| 130 | my $world = shift; | ||
| 131 | my @routes = $world->routes_for_node($self->name); | ||
| 132 | my %diplomacy = $world->diplomacy_for_node($self->name); | ||
| 133 | @routes = sort { $b->factor_for_node($self->name) * 1000 + $diplomacy{$b->destination($self->name)} | ||
| 134 | <=> | ||
| 135 | $a->factor_for_node($self->name) * 1000 + $diplomacy{$a->destination($self->name)} | ||
| 136 | } @routes; | ||
| 137 | if(@routes > 0) | ||
| 138 | { | ||
| 139 | foreach my $r (@routes) | ||
| 140 | { | ||
| 141 | if($self->production_for_export >= TRADING_QUOTE) | ||
| 142 | { | ||
| 143 | my $treaty_bonus = 0; | ||
| 144 | if($world->exists_treaty_by_type($self->name, $r->destination($self->name), 'commercial')) | ||
| 145 | { | ||
| 146 | $treaty_bonus = TREATY_TRADE_FACTOR; | ||
| 147 | } | ||
| 148 | $self->trade(TRADING_QUOTE, $r->factor_for_node($self->name) + $treaty_bonus); | ||
| 149 | my $event = "TRADE OK " . $r->destination($self->name) . " [x" . $r->factor_for_node($self->name); | ||
| 150 | if($treaty_bonus > 0) | ||
| 151 | { | ||
| 152 | $event .= " +$treaty_bonus"; | ||
| 153 | } | ||
| 154 | $event .= "]"; | ||
| 155 | $self->register_event($event); | ||
| 156 | } | ||
| 157 | else | ||
| 158 | { | ||
| 159 | $self->trade(0, $r->factor_for_node($self->name)); | ||
| 160 | $self->register_event("TRADE KO " . $r->destination($self->name)); | ||
| 161 | } | ||
| 162 | } | ||
| 163 | } | ||
| 164 | } | ||
| 165 | |||
| 166 | sub convert_remains | ||
| 167 | { | ||
| 168 | my $self = shift; | ||
| 169 | $self->add_wealth($self->production); | ||
| 170 | $self->register_event("REMAIN " . $self->production); | ||
| 171 | $self->production_for_domestic(0); | ||
| 172 | $self->production_for_export(0); | ||
| 173 | } | ||
| 174 | |||
| 175 | sub war_cost | ||
| 176 | { | ||
| 177 | my $self = shift; | ||
| 178 | $self->add_wealth(-1 * WAR_WEALTH_MALUS); | ||
| 179 | $self->register_event("WAR COST PAYED: " . WAR_WEALTH_MALUS); | ||
| 180 | } | ||
| 181 | sub civil_war_cost | ||
| 182 | { | ||
| 183 | my $self = shift; | ||
| 184 | $self->add_wealth(-1 * CIVIL_WAR_WEALTH_MALUS); | ||
| 185 | $self->register_event("CIVIL WAR COST PAYED: " . CIVIL_WAR_WEALTH_MALUS); | ||
| 186 | } | ||
| 187 | |||
| 188 | sub boost_production | ||
| 189 | { | ||
| 190 | my $self = shift; | ||
| 191 | my $boost = BOOST_PRODUCTION_QUOTE * PRODUCTION_UNITS->[$self->size]; | ||
| 192 | $self->subtract_production('export', -1 * $boost); | ||
| 193 | $self->subtract_production('domestic', -1 * $boost); | ||
| 194 | $self->register_event("BOOST OF PRODUCTION"); | ||
| 195 | } | ||
| 196 | sub receive_aid | ||
| 197 | { | ||
| 198 | my $self = shift; | ||
| 199 | my $from = shift; | ||
| 200 | my $boost = ECONOMIC_AID_QUOTE * PRODUCTION_UNITS->[$self->size]; | ||
| 201 | $self->subtract_production('export', -1 * $boost); | ||
| 202 | $self->subtract_production('domestic', -1 * $boost); | ||
| 203 | } | ||
| 204 | |||
| 205 | sub trade | ||
| 206 | { | ||
| 207 | my $self = shift; | ||
| 208 | my $production = shift; | ||
| 209 | my $gain = shift; | ||
| 210 | $self->subtract_production('export', $production); | ||
| 211 | $self->add_wealth($production * $gain); | ||
| 212 | $self->add_wealth(-1 * TRADEROUTE_COST); | ||
| 213 | } | ||
| 214 | |||
| 215 | sub calculate_disorder | ||
| 216 | { | ||
| 217 | my $self = shift; | ||
| 218 | my $world = shift; | ||
| 219 | return if($self->internal_disorder_status eq 'Civil war'); | ||
| 220 | return if($self->frozen_disorder); | ||
| 221 | |||
| 222 | my @ordered_best = $world->order_statistics(prev_turn($self->current_year), 'progress'); | ||
| 223 | |||
| 224 | #Variables | ||
| 225 | my $wd = $self->wealth / PRODUCTION_UNITS->[$self->size]; | ||
| 226 | my $d = $self->internal_disorder; | ||
| 227 | my $g = $self->government_strength; | ||
| 228 | my $prg = $ordered_best[0] ? $ordered_best[0]->{'value'} - $self->progress : 0; | ||
| 229 | |||
| 230 | #Constants | ||
| 231 | my $wd_middle = 30; | ||
| 232 | my $wd_divider = 10; | ||
| 233 | my $disorder_divider = 70; | ||
| 234 | my $government_strength_minimum = 60; | ||
| 235 | my $government_strength_divider = 40; | ||
| 236 | my $random_factor_max = 15; | ||
| 237 | |||
| 238 | my $disorder = ( ($wd_middle - $wd) / $wd_divider ) + | ||
| 239 | ( $d / $disorder_divider ) + | ||
| 240 | ( ($government_strength_minimum - $g) / $government_strength_divider ) + | ||
| 241 | $world->random_around_zero($random_factor_max, 100, "Internal disorder random factor for " . $self->name) + | ||
| 242 | $prg; | ||
| 243 | |||
| 244 | $disorder = int ($disorder * 100) / 100; | ||
| 245 | $self->register_event("DISORDER CHANGE: " . $disorder); | ||
| 246 | $self->add_internal_disorder($disorder, $world); | ||
| 247 | } | ||
| 248 | |||
| 249 | sub subtract_production | ||
| 250 | { | ||
| 251 | my $self = shift; | ||
| 252 | my $which = shift; | ||
| 253 | my $production = shift; | ||
| 254 | if($which eq 'export') | ||
| 255 | { | ||
| 256 | $self->production_for_export($self->production_for_export - $production); | ||
| 257 | } | ||
| 258 | elsif($which eq 'domestic') | ||
| 259 | { | ||
| 260 | $self->production_for_domestic($self->production_for_domestic - $production); | ||
| 261 | } | ||
| 262 | |||
| 263 | } | ||
| 264 | |||
| 265 | sub add_wealth | ||
| 266 | { | ||
| 267 | my $self = shift; | ||
| 268 | my $wealth = shift; | ||
| 269 | $self->wealth($self->wealth + $wealth); | ||
| 270 | $self->wealth(0) if($self->wealth < 0); | ||
| 271 | } | ||
| 272 | |||
| 273 | sub lower_disorder | ||
| 274 | { | ||
| 275 | my $self = shift; | ||
| 276 | my $world = shift; | ||
| 277 | if($world->at_civil_war($self->name)) | ||
| 278 | { | ||
| 279 | return; | ||
| 280 | } | ||
| 281 | if($self->production_for_domestic > RESOURCES_FOR_DISORDER) | ||
| 282 | { | ||
| 283 | $self->subtract_production('domestic', RESOURCES_FOR_DISORDER); | ||
| 284 | $self->add_internal_disorder(-1 * DISORDER_REDUCTION, $world); | ||
| 285 | $self->register_event("DISORDER LOWERED TO " . $self->internal_disorder); | ||
| 286 | } | ||
| 287 | } | ||
| 288 | |||
| 289 | sub add_internal_disorder | ||
| 290 | { | ||
| 291 | my $self = shift; | ||
| 292 | my $disorder = shift; | ||
| 293 | my $world = shift; | ||
| 294 | my $actual_disorder = $self->internal_disorder_status; | ||
| 295 | my $new_disorder_data = $self->internal_disorder + $disorder; | ||
| 296 | $new_disorder_data = int($new_disorder_data * 100) / 100; | ||
| 297 | $self->internal_disorder($new_disorder_data); | ||
| 298 | if($self->internal_disorder > 100) | ||
| 299 | { | ||
| 300 | $self->internal_disorder(100); | ||
| 301 | } | ||
| 302 | if($self->internal_disorder < 0) | ||
| 303 | { | ||
| 304 | $self->internal_disorder(0); | ||
| 305 | } | ||
| 306 | my $new_disorder = $self->internal_disorder_status; | ||
| 307 | if($actual_disorder ne $new_disorder) | ||
| 308 | { | ||
| 309 | $self->register_event("INTERNAL DISORDER LEVEL FROM $actual_disorder TO $new_disorder"); | ||
| 310 | if($new_disorder eq "Civil war") | ||
| 311 | { | ||
| 312 | $world->start_civil_war($self); | ||
| 313 | } | ||
| 314 | } | ||
| 315 | } | ||
| 316 | |||
| 317 | sub internal_disorder_status | ||
| 318 | { | ||
| 319 | my $self = shift; | ||
| 320 | my $disorder = $self->internal_disorder; | ||
| 321 | if($disorder < INTERNAL_DISORDER_TERRORISM_LIMIT) | ||
| 322 | { | ||
| 323 | return "Peace"; | ||
| 324 | } | ||
| 325 | elsif($disorder < INTERNAL_DISORDER_INSURGENCE_LIMIT) | ||
| 326 | { | ||
| 327 | return "Terrorism"; | ||
| 328 | } | ||
| 329 | elsif($disorder < INTERNAL_DISORDER_CIVIL_WAR_LIMIT) | ||
| 330 | { | ||
| 331 | return "Insurgence"; | ||
| 332 | } | ||
| 333 | else | ||
| 334 | { | ||
| 335 | return "Civil war"; | ||
| 336 | } | ||
| 337 | } | ||
| 338 | |||
| 339 | sub fight_civil_war | ||
| 340 | { | ||
| 341 | my $self = shift; | ||
| 342 | my $world = shift; | ||
| 343 | return undef if($self->internal_disorder_status ne 'Civil war'); | ||
| 344 | my $government = $world->random(0, 100, "Civil war " . $self->name . ": government fight result"); | ||
| 345 | my $rebels = $world->random(0, 100, "Civil war " . $self->name . ": rebels fight result"); | ||
| 346 | $self->register_event("FIGHTING CIVIL WAR"); | ||
| 347 | if($self->army >= ARMY_UNIT_FOR_CIVIL_WAR) | ||
| 348 | { | ||
| 349 | $self->add_army(-1 * ARMY_UNIT_FOR_CIVIL_WAR); | ||
| 350 | $government += ARMY_HELP_FOR_CIVIL_WAR; | ||
| 351 | } | ||
| 352 | if($self->government eq 'dictatorship') | ||
| 353 | { | ||
| 354 | $government += DICTATORSHIP_BONUS_FOR_CIVIL_WAR; | ||
| 355 | } | ||
| 356 | my $reb_sup; | ||
| 357 | my $sup; | ||
| 358 | if($reb_sup = $world->rebel_supported($self->name)) | ||
| 359 | { | ||
| 360 | $rebels += REBEL_SUPPORT_HELP_FOR_CIVIL_WAR; | ||
| 361 | } | ||
| 362 | if($sup = $world->supported($self->name)) | ||
| 363 | { | ||
| 364 | $government += SUPPORT_HELP_FOR_CIVIL_WAR; | ||
| 365 | } | ||
| 366 | if($reb_sup) | ||
| 367 | { | ||
| 368 | $world->broadcast_event("RELATIONS BETWEEN " . $self->name . " AND " . $reb_sup->node1 . " CHANGED FOR CIVIL WAR IN " . $self->name, $self->name, $reb_sup->node1); | ||
| 369 | $world->change_diplomacy($self->name, $reb_sup->node1, -1 * DIPLOMACY_MALUS_FOR_REBEL_CIVIL_WAR_SUPPORT); | ||
| 370 | } | ||
| 371 | if($sup && $reb_sup) | ||
| 372 | { | ||
| 373 | $world->broadcast_event("RELATIONS BETWEEN " . $sup->node1 . " AND " . $reb_sup->node1 . " CHANGED FOR CIVIL WAR IN " . $self->name, $self->name, $sup->node1, $reb_sup->node1); | ||
| 374 | $world->change_diplomacy($sup->node1, $reb_sup->node1, -1 * DIPLOMACY_MALUS_FOR_CROSSED_CIVIL_WAR_SUPPORT); | ||
| 375 | } | ||
| 376 | if($government > $rebels) | ||
| 377 | { | ||
| 378 | $reb_sup->casualities(1) if $reb_sup; | ||
| 379 | $world->rebel_military_support_garbage_collector(); | ||
| 380 | return $self->civil_war_battle('government'); | ||
| 381 | } | ||
| 382 | elsif($rebels > $government) | ||
| 383 | { | ||
| 384 | $sup->casualities(1) if $sup; | ||
| 385 | $world->military_support_garbage_collector(); | ||
| 386 | return $self->civil_war_battle('rebels'); | ||
| 387 | } | ||
| 388 | else | ||
| 389 | { | ||
| 390 | return undef; | ||
| 391 | } | ||
| 392 | } | ||
| 393 | |||
| 394 | sub civil_war_battle | ||
| 395 | { | ||
| 396 | my $self = shift; | ||
| 397 | my $battle_winner = shift; | ||
| 398 | if($battle_winner eq 'government') | ||
| 399 | { | ||
| 400 | $self->rebel_provinces($self->rebel_provinces() - .5); | ||
| 401 | } | ||
| 402 | elsif($battle_winner eq 'rebels') | ||
| 403 | { | ||
| 404 | $self->rebel_provinces($self->rebel_provinces() + .5); | ||
| 405 | } | ||
| 406 | if($self->rebel_provinces == 0) | ||
| 407 | { | ||
| 408 | $self->internal_disorder(AFTER_CIVIL_WAR_INTERNAL_DISORDER); | ||
| 409 | $self->register_event("THE GOVERNMENT WON THE CIVIL WAR"); | ||
| 410 | return 'government'; | ||
| 411 | } | ||
| 412 | elsif($self->rebel_provinces == PRODUCTION_UNITS->[$self->size]) | ||
| 413 | { | ||
| 414 | $self->internal_disorder(AFTER_CIVIL_WAR_INTERNAL_DISORDER); | ||
| 415 | $self->register_event("THE REBELS WON THE CIVIL WAR"); | ||
| 416 | $self->rebel_provinces(0); | ||
| 417 | return 'rebels'; | ||
| 418 | } | ||
| 419 | return undef; | ||
| 420 | } | ||
| 421 | |||
| 422 | sub win_civil_war | ||
| 423 | { | ||
| 424 | my $self = shift; | ||
| 425 | my $winner = shift; | ||
| 426 | my $world = shift; | ||
| 427 | if($winner eq 'rebels') | ||
| 428 | { | ||
| 429 | $self->new_government($world); | ||
| 430 | my $rebsup = $world->rebel_supported($self->name); | ||
| 431 | if($rebsup) | ||
| 432 | { | ||
| 433 | my $rebel_supporter = $world->get_nation($rebsup->node1); | ||
| 434 | $world->stop_rebel_military_support($rebel_supporter, $self) if $rebel_supporter; | ||
| 435 | $world->diplomacy_exists($self->name, $rebel_supporter->name)->factor(REBEL_SUPPORTER_WINNER_FRIENDSHIP); | ||
| 436 | $world->create_treaty($self->name, $rebel_supporter->name, 'alliance'); | ||
| 437 | $world->broadcast_event($self->name . " AND " . $rebel_supporter->name . " ARE NOW ALLIES. " . $rebel_supporter->name . " HELPED " . $self->name . " REVOLUTION", $self->name, $rebel_supporter->name); | ||
| 438 | } | ||
| 439 | $world->empty_stocks($self->name); | ||
| 440 | $self->available_stocks(START_STOCKS->[$self->size]); | ||
| 441 | } | ||
| 442 | elsif($winner eq 'government') | ||
| 443 | { | ||
| 444 | my $rebsup = $world->rebel_supported($self->name); | ||
| 445 | if($rebsup) | ||
| 446 | { | ||
| 447 | my $rebel_supporter = $world->get_nation($rebsup->node1); | ||
| 448 | $world->stop_rebel_military_support($rebel_supporter, $self) if $rebel_supporter; | ||
| 449 | } | ||
| 450 | } | ||
| 451 | } | ||
| 452 | |||
| 453 | sub new_government | ||
| 454 | { | ||
| 455 | my $self = shift; | ||
| 456 | my $world = shift; | ||
| 457 | $self->government_strength($world->random10(MIN_GOVERNMENT_STRENGTH, MAX_GOVERNMENT_STRENGTH, "Reroll government strength for " . $self->name)); | ||
| 458 | $world->reroll_diplomacy($self->name); | ||
| 459 | $world->reset_treaties($self->name); | ||
| 460 | $world->reset_influences($self->name); | ||
| 461 | $world->reset_supports($self->name); | ||
| 462 | $world->reset_crises($self->name); | ||
| 463 | $self->register_event("NEW GOVERNMENT CREATED"); | ||
| 464 | } | ||
| 465 | |||
| 466 | sub occupation | ||
| 467 | { | ||
| 468 | my $self = shift; | ||
| 469 | my $world = shift; | ||
| 470 | $world->reset_treaties($self->name); | ||
| 471 | $world->reset_influences($self->name); | ||
| 472 | $world->reset_supports($self->name); | ||
| 473 | $world->reset_crises($self->name); | ||
| 474 | } | ||
| 475 | |||
| 476 | sub build_troops | ||
| 477 | { | ||
| 478 | my $self = shift; | ||
| 479 | my $army_cost = $self->build_troops_cost(); | ||
| 480 | |||
| 481 | if($self->production_for_domestic > $army_cost && $self->army < MAX_ARMY_FOR_SIZE->[ $self->size ]) | ||
| 482 | { | ||
| 483 | $self->subtract_production('domestic', $army_cost); | ||
| 484 | $self->add_army(ARMY_UNIT); | ||
| 485 | $self->register_event("NEW TROOPS FOR THE ARMY"); | ||
| 486 | } | ||
| 487 | } | ||
| 488 | |||
| 489 | sub build_troops_cost | ||
| 490 | { | ||
| 491 | my $self = shift; | ||
| 492 | my $army_cost = ARMY_COST; | ||
| 493 | if($self->government eq 'dictatorship') | ||
| 494 | { | ||
| 495 | $army_cost -= DICTATORSHIP_BONUS_FOR_ARMY_CONSTRUCTION; | ||
| 496 | } | ||
| 497 | return $army_cost; | ||
| 498 | } | ||
| 499 | |||
| 500 | sub add_army | ||
| 501 | { | ||
| 502 | my $self = shift; | ||
| 503 | my $army = shift; | ||
| 504 | $self->army($self->army + $army); | ||
| 505 | if($self->army > MAX_ARMY_FOR_SIZE->[ $self->size ]) | ||
| 506 | { | ||
| 507 | $self->army(MAX_ARMY_FOR_SIZE->[ $self->size ]); | ||
| 508 | } | ||
| 509 | if($self->army < 0) | ||
| 510 | { | ||
| 511 | $self->army(0); | ||
| 512 | } | ||
| 513 | |||
| 514 | } | ||
| 515 | |||
| 516 | sub grow | ||
| 517 | { | ||
| 518 | my $self = shift; | ||
| 519 | return if($self->production_for_domestic < PROGRESS_COST); | ||
| 520 | my $new_progress = $self->progress + PROGRESS_INCREMENT; | ||
| 521 | $self->progress($new_progress); | ||
| 522 | $self->subtract_production('domestic', PROGRESS_COST); | ||
| 523 | $self->register_event("GROW. NEW PROGRESS: $new_progress"); | ||
| 524 | } | ||
| 525 | |||
| 526 | sub treaty_limit | ||
| 527 | { | ||
| 528 | my $self = shift; | ||
| 529 | my $progress_step = int($self->progress / TREATY_LIMIT_PROGRESS_STEP) + 1; | ||
| 530 | return $progress_step * TREATIES_FOR_PROGRESS_STEP; | ||
| 531 | } | ||
| 532 | |||
| 533 | sub print_attributes | ||
| 534 | { | ||
| 535 | my $self = shift; | ||
| 536 | my $out = ""; | ||
| 537 | $out .= "Area: " . $self->area . "\n"; | ||
| 538 | $out .= "Export quote: " . $self->export_quote . "\n"; | ||
| 539 | $out .= "Government strength: " . $self->government_strength . "\n"; | ||
| 540 | $out .= "Internal situation: " . $self->internal_disorder_status . "\n"; | ||
| 541 | return $out; | ||
| 542 | } | ||
| 543 | |||
| 544 | sub print | ||
| 545 | { | ||
| 546 | my $self = shift; | ||
| 547 | my $out = ""; | ||
| 548 | $out .= "Name: " . $self->name . "\n"; | ||
| 549 | $out .= $self->print_attributes(); | ||
| 550 | $out .= "Events:\n"; | ||
| 551 | foreach my $year (sort keys %{$self->events}) | ||
| 552 | { | ||
| 553 | $out .= " $year:\n"; | ||
| 554 | foreach my $e (@{$self->events->{$year}}) | ||
| 555 | { | ||
| 556 | $out .= " " . $e ."\n"; | ||
| 557 | } | ||
| 558 | } | ||
| 559 | return $out; | ||
| 560 | } | ||
| 561 | |||
| 562 | sub dump | ||
| 563 | { | ||
| 564 | my $self = shift; | ||
| 565 | my $io = shift; | ||
| 566 | my $indent = shift || ""; | ||
| 567 | print {$io} $indent . | ||
| 568 | join(";", $self->name, $self->code, $self->area, $self->export_quote, $self->government, $self->government_strength, $self->size, $self->internal_disorder, $self->production_for_domestic, $self->production_for_export, $self->prestige, $self->wealth, $self->debt, $self->rebel_provinces, $self->current_year, $self->army, $self->progress) . "\n"; | ||
| 569 | $self->dump_events($io, " " . $indent); | ||
| 570 | } | ||
| 571 | |||
| 572 | sub load | ||
| 573 | { | ||
| 574 | my $self = shift; | ||
| 575 | my $data = shift; | ||
| 576 | my $nation_line = ( split /\n/, $data )[0]; | ||
| 577 | $nation_line =~ s/^\s+//; | ||
| 578 | chomp $nation_line; | ||
| 579 | my ($name, $code, $area, $export_quote, $government, $government_strength, $size, $internal_disorder, $production_for_domestic, $production_for_export, $prestige, $wealth, $debt, $rebel_provinces, $current_year, $army, $progress) = split ";", $nation_line; | ||
| 580 | $data =~ s/^.*?\n//; | ||
| 581 | my $events = $self->load_events($data); | ||
| 582 | return $self->new(name => $name, code => $code, area => $area, size => $size, | ||
| 583 | export_quote => $export_quote, government => $government, government_strength => $government_strength, | ||
| 584 | internal_disorder => $internal_disorder, | ||
| 585 | production_for_domestic => $production_for_domestic, production_for_export => $production_for_export, | ||
| 586 | prestige => $prestige, wealth => $wealth, debt => $debt, | ||
| 587 | rebel_provinces => $rebel_provinces, army => $army, | ||
| 588 | current_year => $current_year, | ||
| 589 | progress => $progress, | ||
| 590 | events => $events); | ||
| 591 | } | ||
| 592 | |||
| 593 | 1; |