#! /usr/bin/perl -P

# Starvation predicter.
# usage: starve [-u updates] census version
# Gives the sectors that don't have enough food.

#include "empinit.perl"

do 'getopt.pl';

;# By default, only check the next update.
$updates = 1;
do Getopt('u');
if ($opt_u) {$updates = $opt_u;}

do empinit('census', 'version');
$etus = $upd_etus * $updates;

;# Grab the relevant values from each sector.  Compute the amount
;# of food grown, and the amount of food consumed.  If more food
;# is eaten then there is food in the sector, let the dude know.
foreach $sec (@sec_list) {
    $fert = $sectors{$sec, FERT};
    $civ = $sectors{$sec, CIV};
    $mil = $sectors{$sec, MIL};
    $uw = $sectors{$sec, UW};
    $work = $sectors{$sec, WORK};
    $food = $sectors{$sec, FOOD};
    $sectype = $sectors{$sec, SECTYPE};
    $workforce = ($civ * $work / 100) + $uw + ($mil * 0.4);
    $growth = $fert * $etus * $fgrate;
    if ($sectype eq 'a') {
	$harvest = $etus * $fcrate * $workforce;
    } else {
	$harvest = ($etus * $fcrate) * ($civ + $uw + ($mil * 0.4));
    }
    if ($harvest < $growth) { $growth = $harvest; }
    $food += $growth;
    $consume = ($etus * $eatrate) * ($civ + $mil + $uw);
    if ($food < $consume) {
	printf "Sector %s will consume %.3f too much.\n", $sec, $consume-$food;
    }
}

