Search: Home | Atlas | Guides | Tests | Research | Index | Recent Changes | Preferences | Login

Users > Roen > Roen Utilities Dev

Bonfire PHP Class (work in progress)

Tests

Without burning temperature

Range 4-8
Wood CC Yield
10
20
30
40
50
60
70
80
90
100
111
121
131
141
151
162
172
182
192
202
212
223
233
243
253
263
273
283
294
304
314
324
334
344
354
364
375

This prove the 4-8 range theory.

Now let's put burning temp at 13 and simulate a fire with 105 wood as notyfied in bonfires page "Doing the first type of this method I accidently added all of my wood half way in, 105 peices, I ended up with 3 charcoal. More experimentation is needed to determine why."

Tick Temp Wood cc
001050
111040
221020
33990
44950
55901
66841
77772
88692
99602
1010502
1111392
1212272
1313142
141401
151301
161201
171101
181001
19901
20801
21702
22602
23503
24403
25303
26203
27103

We end with 3 cc just as stated.

If I set burning temp to 12 or 14 we get 2 or 4 cc for this 105 wood BF, so burning temp is 13.

The Class

Class Bonfire
	{
	////////
	//VARS//
	////////

	//bonfire vars
	var $Temp = 0; //temperature of BF

	//////////////
	//stock vars//
	//////////////
	var $WoodStock = 0; 		//wood left in BF
	var $WoodBeforeTick = 0; 	//Wood left before tick
	var $PapyStock = 0; 		//Papyrus stock in BF
	var $carrotStock = 0;  		//Carrot stock in BF
	var $garlicStock = 0;		//Garlic stock in BF
	var $limestoneStock = 0;	//Limestone stockin BF

	var $waterStock = 0;		//water in BF

	var $ccStock = 0; 			//cc stock in BF
	var $ashStock = 0; 			//Ash stock in BF
	var $limeStock = 0;			//Lime stock in BF

	///////////////////////////
	//production temperatures//
	///////////////////////////
	var $ccProdLow = 4; 		//cc production low temperature
	var $ccProdHigh = 8; 		//cc produciton high temperature

	var $PapyAshLow = 5; 		//Papyrus Ash production low temperature
	var $PapyAshHigh = 10;		//Papyrus Ash production high temperature

	var $carrotAshLow = 15;		//Carrot Ash production low temperature
	var $carrotAshHigh = 24;	//Carrot Ash production high temperature

	var $garlicAshLow = 10;		//Garlic Ash production low temperature
	var $garlicAshHigh = 11;	//Garlic Ash production high temperature

	var $limeProdLow1 = 2;		//Lime production low temperature (low prod range)
	var $limeProdHigh1 = 6;		//Lime production high temperature (low prod range)

	var $limeProdLow2 = 7;		//Lime production low temperature (high prod range)
	var $limeProdHigh2 = 9		//Lime production high temperature (high prod range)

	////////////////////////
	//burning temperatures//
	////////////////////////
	var $ccBurn = 13; 			//cc burning temperature

	/**
	 * Bonfire::Bonfire()
	 * Constructor
	 * 
	 * @param $wood => number of initial wood in BF
	 * @param $limestone => number of initial limestone in BF
	 * @param $papyrus => number of initial papyrus in BF
	 * @param $carrot => number of initial carrot in BF
	 * @param $garlic => number of initial garlic in BF
	 * 
	 * @return nothing
	 */
	function Bonfire($wood=0, $limestone=0, $papyrus=0, $carrot=0, $garlic=0)
		{
		$this->WoodStock = $wood;
		$this->PapyStock = $papyrus;
		$this->carrotStock = $carrot;
		$this->garlicStock = $garlic;
		$this->limestoneStock = $limestone;
		}

	/**
	 * Bonfire::Tick()
	 * simulates a BF tick
	 * 
	 * @param $wood => number of wood added
	 * @param $limestone => number of limestone added
	 * @param $papyrus => number of papyrus added
	 * @param $carrot => number of carrot added
	 * @param $garlic => number of garlic added
	 * @param $water => number of water added
	 * 
	 * @return BF state
	 */
	function Tick($wood=0, $limestone=0, $papyrus=0, $carrot=0, $garlic=0, $water = 0)
		{
		//Remember how much wood there was before temp calculation
		$this->WoodBeforeTick = $this->WoodStock;	

		//Temp calculation
		if ($this->WoodStock > 0)
			$this->Temp++;
		else
			$this->Temp--;

		if ($this->waterStock > 0)
			$this->Temp -= $this->waterStock;

		if ($this->Temp < 0)
			$this->Temp = 0;

		/////////////////////
		//YIELDS ADJUSTMENT//
		/////////////////////
		$this->ccYield();
		$this->ashYield();
		$this->limeYield();

		//////////////////////
		//STOCKS ADJUSTMENTS//
		//////////////////////
		//Wood stock (such a great party :D)
		$this->WoodStock -= $this->Temp; //wood minus current temp

		if ($this->WoodStock < 0) //if down under 0 then stock is 0
			$this->WoodStock = 0;

		$this->PapyStock--; //reduce papy stock by 1
		if ($this->PapyStock < 0) //if down under 0 then stock is 0
			$this->PapyStock = 0;

		$this->carrotStock -= 8; //reduce carrot stock by 8
		if ($this->carrotStock < 0) //if down under 0 then stock is 0
			$this->carrotStock = 0;

		$this->garlicStock -= 6; //reduce garlic stock by 6
		if ($this->garlicStock < 0) //if down under 0 then stock is 0
			$this->garlicStock = 0;

		$this->limestoneStock -= 6; //reduce limestone stock by 1
		if ($this->limestoneStock < 0) //if down under 0 then stock is 0
			$this->limestoneStock = 0;

		$this->WoodStock += $wood; //add this tick's wood addition
		$this->PapyStock += $papyrus; //add this tick's papyrus addition
		$this->carrotStock += $carrot; //add this tick's carrot addition
		$this->garlicStock += $garlic; //add this tick's garlic addition
		$this->limestoneStock += $limestone; //add this tick's limestone addition
		$this->waterStock += $water; //add this tick's water addition

		//return BF state, false if off, true if lit
		if ($this->Temp == 0)
			return false;
		else 
			return true;
		}

	//////////////////////
	//YIELDS CALCULATORS//
	//////////////////////

	/**
	 * Bonfire::ccYield()
	 * calculate cc Stock in BF
	 * 
	 * @return nothing
	 */
	function ccYield()
		{
		//if we are in good temperature range
		if ($this->Temp >= $this->ccProdLow && $this->Temp <= $this->ccProdHigh)
			{
			$this->ccStock += 0.5; //then add 0.5 cc
			}

		//if over cc burning temp
		if ($this->Temp >= $this->ccBurn)  
			$this->ccStock -= 0.5; //then burn 0.5 cc
		if ($this->ccStock < 0)
			$this->ccStock = 0;
		}

	/**
	 * Bonfire::ashYield()
	 * calculate Ash production
	 * 
	 * @return nothing
	 */ 
	function ashYield()
		{
		//if we are in papyrus burning temperature range 
		if ($this->Temp >= $this->PapyAshLow && $this->Temp <= $this->PapyAshHigh)	
			if($this->PapyStock >= 0) //and if there is papyrus in the bonfire
				$this->ashStock += 0.45; //then add 0.45 cc

		//if we are in carrot burning temperature range 
		if ($this->Temp >= $this->carrotAshLow && $this->Temp <= $this->carrotAshHigh)	
			if($this->carrotStock >= 8) //and if there is carrot in the bonfire
				$this->ashStock += 1.5; //then add 1.5 cc	

		//if we are in garlic burning temperature range 
		if ($this->Temp >= $this->garlicAshLow && $this->Temp <= $this->garlicAshHigh)	
			if($this->garlicStock >= 6) //and if there is garlic in the bonfire
				$this->ashStock += 1.5; //then add 1.5 cc		
		}

	/**
	 * Bonfire::limeYield()
	 * calculate Lime production
	 * 
	 * @return nothing
	 */
	function limeYield()
		{
		//if there is limestone in BF
		if ($this->limestoneStock > 0)
			{
			//if in low prod range
			if ($this->Temp >= $this->$limeProdLow1 && $this->Temp <= $this->$limeProdLow1)
				$this->limeStock += 0.1; //then yield 0.1 Lime		
			//if in high prod range
			if ($this->Temp >= $this->$limeProdLow2 && $this->Temp <= $this->$limeProdLow2)
				$this->limeStock += 0.7; //then yield 0.7 lime
			}
		}

	/////////////
	//BF STATE //
	/////////////

	/**
	 * Bonfire::getValues()
	 * return every current values of BF
	 * 
	 * @return associative array with current values of BF
	 * wood 		=> wood stock
	 * papyrus 		=> papyrus stock
	 * carrot 		=> carrot stock
	 * garlid 		=> garlic stock
	 * limestone 	=> Limestone stock
	 * 
	 * temps 		=> temperature of BF
	 * 
	 * cc 			=> charcoal stock
	 * ash 			=> Ash stock
	 * lime 		=> Lime stock
	 */
	function getValues()
		{
		//create an associative array with every values of BF
		$Values = array();

		//initial products values
		$Values['wood'] = $this->WoodStock;
		$Values['papyrus'] = $this->PapyStock;
		$Values['carrot'] = $this->carrotStock;
		$Values['garlic'] = $this->garlicStock;
		$Values['limestone'] = $this->limestoneStock;

		//temperature
		$Values['temp'] = $this->Temp;

		//productions values
		$Values['cc'] = floor($this->ccStock);
		$Values['ash'] = floor($this->ashStock);
		$Values['lime'] = floor($this->limeStock);

		//return the array
		return $Values;
		}

	}

Home | Atlas | Guides | Tests | Research | Index | Recent Changes | Preferences | Login
View source text of this page | | Create/Edit another page | View other revisions
Last edited September 21, 2004 3:00 pm by Roen (diff)
Users must be logged in to edit this page.
Search: