From lavaca.uh.edu!zaphod.mps.ohio-state.edu!samsung!uunet!mcsun!ukc!reading!minster!ken Thu Feb 14 13:26:37 CST 1991
Article: 1098 of rec.games.empire
Path: menudo.uh.edu!lavaca.uh.edu!zaphod.mps.ohio-state.edu!samsung!uunet!mcsun!ukc!reading!minster!ken
From: ken@minster.york.ac.uk
Newsgroups: rec.games.empire
Subject: Re: Thresh and food
Message-ID: <666486291.11736@minster.york.ac.uk>
Date: 13 Feb 91 23:04:51 GMT
References: <1991Feb12.213508.21915@ux1.cso.uiuc.edu> <1991Feb12.223431.25873@ims.alaska.edu>
Reply-To: ken@SoftEng.UUCP (ken)
Organization: Department of Computer Science, University of York, England
Lines: 200

>Does anybody have any good ways of figuring out how much you should set
>the food threshhold for a sector with civilians and how much the warehouse
>thresholds should be set to have optimum distribution of raw materials to
>sectors that need them?
> 
>I know this is a really big question but any thought would be helpful! Thanks
>`
>>Chris Parrinello                   | Is there blues music in Utopia?     

We have a few awk scripts here for this. One is called "shortage" and gives
warnings about imminent starvation, and the other is called "produce" and
indicates sectors which have production throttled (e.g. lcm plants with not
enough iron ore). Shortage works on a dump file (produced by the dump
command in empire, or the dumpfile .dump maintained by ve). Produce works on
the output of the production command. I'm not sure who wrote them
originally, but Dr Mike Richardson (hi mike!) has hacked them.

----------cut here for shortage----------------------------
#! /bin/awk -f

#	Filter a dump file to locate shortages of food.			#

BEGIN	{
	civ	= 0
	mil	= 0
	uw	= 0
	food	= 0
	first	= 1
	}

{
	if (first && (substr("dump", 1, length($1)) != $1))
	{	print	"shortage: input is not a dump file"
		exit	1
	}

	first	= 0

	if ((NF > 26) && ($1 != "x") && (match ($4, "[A-Z]") == 0))
	{
		# Check for food shortages. According to the "version"	#
		# command, 1000 people eat 1 unit of food each time	#
		# unit, that is, 8 units per update.			#
		civ	= $16
		mil	= $17
		uw	= $18
		food	= $19

		if (civ + mil + uw <= 2)
			# Almost nobody there. This never seems to	#
			# give rise to any problems.			#
			continue

		if (((civ + mil + uw) * 8) > (food * 1000))
		{	# Not enough to last even the next update. Oh	#
			# dear, starvation iminent			#
			printf	("%d,%d\t: pop=%5d food=%5d (!!not enough!!)\n",
					$1, $2, civ + mil + uw, food)
			printf	("%4d,%d %d\n", $1, $2, 2) >> "special"
		}
		else if (((civ + mil + uw) * 8) > (food * 1000 / 10))
		{	# Insufficient to last 5 days at 2 updates per	#
			# day. Issue a warning about this.		#
			printf	("%d,%d\t: pop=%5d food=%5d (%d days)\n",
					$1, $2, civ + mil + uw, food,
					(food * 1000) / ((civ + mil + uw) * 16))
			printf	("%4d,%d %d\n", $1, $2, 1) >> "special"
		}

	}
}
----------cut here for produce----------------------------
#! /bin/awk -f

#	Scan a produce file to locate commodity shortages and to	#
#	generate a production summary.					#


BEGIN	{
	header	= 0
	first	= 1

	# For each commodity, total up the actual production, and the	#
	# maximum (ie., that assuming the same populations but enough	#
	# input materials), and similarly the actual and maximum	#
	# consumption.							#
	prod_f = maxp_f = 0
	prod_i = maxp_i = used_i = maxu_i = 0
	prod_g = maxp_g = used_g = maxu_g = 0
	prod_l = maxp_l = used_l = maxu_l = 0
	prod_h = maxp_h = used_h = maxu_h = 0
	prod_e = maxp_e
	cost   = 0
	}

{
	if (first && (substr("production", 1, length($1)) != $1))
	{	print	"produce: input is not a production file"
		exit	1
	}

	first	= 0

	if ((length($2) == 1) && (substr($3, length($3), 1) == "%"))
	{
		# Interesting lines have a sector designation in the	#
		# second field, and the third field ends with a percent	#
		# character						#

		use1 = use2 = use3 = 0
		max1 = max2 = max3 = 0


		if	($2 == "m")
		{	# Iron mines use nothing at all and is free.	#
			prod_i	= prod_i + $5
			maxp_i	= maxp_i + $9
		}
		else if ($2 == "a")
		{	# Ditto agribusinesses				#
			prod_f	= prod_f + $5
			maxp_f	= maxp_f + $9
		}
		else if ($2 == "g")
		{	# Gold mines use gold ore but this doesn't	#
			# show up on the production report		#
			prod_g	= prod_g + $5
			maxp_g	= maxp_g + $9
		}
		else if ($2 == "j")
		{	# Light industry uses iron and nothing but iron	#
			use1	= substr ($9,  1, length($9 )-1)
			max1	= substr ($10, 1, length($10)-1)
			typ1	= "iron"
			prod_l	= prod_l + $5
			maxp_l	= maxp_l + $11
			used_i  = used_i + use1
			maxu_i	= maxu_i + max1
		}
		else if ($2 == "k")
		{	# Light industry uses iron and nothing but iron	#
			use1	= substr ($9,  1, length($9 )-1)
			max1	= substr ($10, 1, length($10)-1)
			typ1	= "iron"
			prod_h	= prod_h + $5
			maxp_h	= maxp_h + $11
			used_i  = used_i + use1
			maxu_i	= maxu_i + max1
		}
		else if ($2 == "l")
		{	# Consume lcm's and money to produce edu's	#
			use1	= substr ($9,  1, length($9 )-1)
			max1	= substr ($10, 1, length($10)-1)
			typ1	= "lcm"
			prod_e	= prod_e + $5
			maxp_e	= maxp_e + $11
			used_l  = used_l + use1
			maxu_l	= maxu_l + max1
		}
		else if ($2 == "e")
		{	# Enlistment centres consume civilians		#
			use1	= substr ($9,  1, length($9 )-1)
			max1	= substr ($10, 1, length($10)-1)
			typ1	= "civ"
		}

		if ((header == 0) && (use1 < max1 ||
				      use2 < max2 || use3 < max3))
		{
			print	"sect      des : product :  use  max"
			header	= 1
		}

		# Check each of the three possible input commodities	#
		# and warn about any possible shortages.		#
		if (use1 < max1)
			printf	("%-9s  %1s  : %-7s : %4d %4d\n",
				 $1, $2, typ1, use1, max1) ;
		if (use2 < max2)
			printf	("%-9s  %1s  : %-7s : %4d %4d\n",
				 $1, $2, typ2, use2, max2) ;
		if (use3 < max3)
			printf	("%-9s  %1s  : %-7s : %4d %4d\n",
				 $1, $2, typ3, use3, max3) ;
	}
}

END	{
	print	""
	print	""
	print	"commodity   production       consumption"
	print	"            actual    max    actual    max"

	printf	("%-9s   %6d %6d           \n", "food", prod_f, maxp_f)
	printf	("%-9s   %6d %6d    %6d %6d\n", "iron", prod_i, maxp_i, used_i, maxu_i)
	printf	("%-9s   %6d %6d    %6d %6d\n", "gold", prod_g, maxp_g, used_g, maxu_g)
	printf	("%-9s   %6d %6d    %6d %6d\n", "lcm",  prod_l, maxp_l, used_l, maxu_l)
	printf	("%-9s   %6d %6d    %6d %6d\n", "hcm",  prod_h, maxp_h, used_h, maxu_h)
	printf	("%-9s   %6d %6d           \n", "edu",  prod_e, maxp_e)
	}


