DEPTH[$i]!="") { $tot++; $totval+=$v->DEPTH[$i]; } } $r=random_float(0.0,$totval); $sector=$tot-1; $t=0; for($i=0;$i<$tot;$i++) { if($sector==$tot-1) { $t+=$v->DEPTH[$i]; if($r<$t)$sector=$i; } } $perarea=(float)$v->MAX_DEPTH/$tot; $ret=random_float((float)$sector*$perarea,$sector*$perarea+$perarea); return($ret); } // Get random flow function venue_randomflow($v) { $tot=0; $totval=0; for($i=0;$i<20;$i++) { if($v->FLOW[$i]!="") { $tot++; $totval+=$v->FLOW[$i]; } } $r=random_float(0.0,$totval); $sector=$tot-1; $t=0; for($i=0;$i<$tot;$i++) { if($sector==$tot-1) { $t+=$v->FLOW[$i]; if($r<$t)$sector=$i; } } $perarea=(float)$v->MAX_FLOW/$tot; $ret=random_float((float)$sector*$perarea,$sector*$perarea+$perarea); return($ret); } // Get min max factor function getfactor($f1,$f2,$per,$ideal,$factor) { sscanf($f1,"%f %f",$s_min,$s_max); sscanf($f2,"%f %f",$b_min,$b_max); $dif=$b_min-$s_min; $dif=$dif*$per; $min=$s_min+$dif; $dif=$b_max-$s_max; $dif=$dif*$per; $max=$s_max+$dif; $min=$ideal-$min; $max=$ideal+$max; // echo "MIN = $min, IDEAL = $ideal, MAX = $max factor = $factor"; if($factor==$ideal)return(1.0); if($factor>$ideal) { if(($factor>$max)||($max==$ideal))return(0.0); $dif=1.0-(($factor-$ideal)/($max-$ideal)); return($dif); } if(($factor<$min)||($min==$ideal))return(0.0); $dif=1.0-(($ideal-$factor)/($ideal-$min)); return($dif); } // Processes shoal advancement function venue_process_shoal($v,$sp,$sh,$wth) { $depth=venue_randomdepth($v); $flow=venue_randomflow($v); $sizeper=0.0; $w=$wth->children(); //$depth=100.0; /* ( Each is worth 1% of live ratio ) 0.0 0.0 ; Air temperature 0.0 0.0 ; Venue set but affected by temperature, wind and clarity 0.0 0.0 ; Venue set 0.0 0.0 ; Sun 200.0 40.0 ; Water depth 0.0 0.0 ; Flow 0.0 0.0 ; Persistance 0.0 0.0 ; Wind 0.0 0.0 ; Clarity venue set but is affected by persistance // each is worth upto 0.25 % 0 Weed and reed cover 1 Overhang cover 2 Structure 3 Surface cover 4 Tree roots 5 Ledge cover 6 Mud cover 7 Sand cover 8 Rock cover 9 Stone cover 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 */ echo $sh->SIZE." ( ".$sh->NUM." ) "; if($sp->MAXSIZE>0) $sizeper=$sh->SIZE/$sp->MAXSIZE; if($sizeper>1.0)$sizeper=1.0; $dead=0; $ideal=$sh->LIVE->WD; $per=($sh->SIZE/16.0)*0.05; if($per>1.0)$per=1.0; $ideal*=$per; // Water depth $dep=getfactor($sp->LIVE_SMALL->WD,$sp->LIVE_BIG->WD,$sizeper,$ideal,$depth); $die=((1.0-$dep)*0.01)*$sh->NUM; $dead+=random_float($die*0.75,$die); // Sun $sun=random_float((float)$w->CURSUN*0.8,(float)$w->CURSUN*1.2)*(float)$v->SUNFACT; $win=getfactor($sp->LIVE_SMALL->SU,$sp->LIVE_BIG->SU,$sizeper,(float)$sh->LIVE->SU,$sun); $die=((1.0-$win)*0.01)*$sh->NUM; $dead+=random_float($die*0.75,$die); // Wind $wind=random_float((float)$w->CURWIND*0.8,(float)$w->CURWIND*1.2)*(float)$v->WINDFACT; $win=getfactor($sp->LIVE_SMALL->WI,$sp->LIVE_BIG->WI,$sizeper,(float)$sh->LIVE->WI,$wind); $die=((1.0-$win)*0.01)*$sh->NUM; $dead+=random_float($die*0.75,$die); // Air temperature $temp=random_float((float)$w->CURTEMP*0.8,(float)$w->CURTEMP*1.2)*(float)$v->TEMPFACT; $win=getfactor($sp->LIVE_SMALL->TE,$sp->LIVE_BIG->TE,$sizeper,(float)$sh->LIVE->TE,$temp); $die=((1.0-$win)*0.01)*$sh->NUM; $dead+=random_float($die*0.75,$die); // Rain fall $rain=random_float((float)$w->CURRAIN*0.8,(float)$w->CURRAIN*1.2)*(float)$v->RAINFACT; $win=getfactor($sp->LIVE_SMALL->PE,$sp->LIVE_BIG->PE,$sizeper,(float)$sh->LIVE->PE,$rain); $die=((1.0-$win)*0.01)*$sh->NUM; $dead+=random_float($die*0.75,$die); // Flow $flw=getfactor($sp->LIVE_SMALL->FLOW,$sp->LIVE_BIG->FLOW,$sizeper,$ideal,(float)$sh->LIVE->FLOW); $die=((1.0-$flw)*0.01)*$sh->NUM; $dead+=random_float($die*0.75,$die); // Clarity $cl=random_float((float)$v->CLARITY*0.85,(float)$v->CLARITY*1.15); // Factor in rain and objects $win=getfactor($sp->LIVE_SMALL->CL,$sp->LIVE_BIG->CL,$sizeper,(float)$sh->LIVE->CL,$cl); $die=((1.0-$win)*0.01)*$sh->NUM; $dead+=random_float($die*0.75,$die); // PH $ph=random_float((float)$v->PH*0.85,(float)$v->PH*1.15); $win=getfactor($sp->LIVE_SMALL->CL,$sp->LIVE_BIG->PH,$sizeper,(float)$sh->LIVE->PH,$ph); $die=((1.0-$win)*0.01)*$sh->NUM; $dead+=random_float($die*0.75,$die); // AREAS echo " $dead
"; return($dead); } // Advance species for a venue function venue_advancespecies($v,$spidx, $wth) { $fname=$v->SPECIES[$spidx]->FNAME; if(file_exists($fname)) { $spxml = simplexml_load_file($fname); echo "Processing all ".$v->SPECIES[$spidx]->NAME." shoals
"; $i=0; while(1) { if(!$v->SPECIES[$spidx]->SHOAL[$i]->SIZE) break; else { // Process the shoal here $dead=venue_process_shoal($v,$spxml,$v->SPECIES[$spidx]->SHOAL[$i],$wth); $v->SPECIES[$spidx]->SHOAL[$i]->NUM=(float)$v->SPECIES[$spidx]->SHOAL[$i]->NUM-$dead; } $i++; } } } // Advance the passed venue function venue_advance($fname) { if(!file_exists($fname))return("ERROR"); $xml = simplexml_load_file($fname); $v=$xml->children(); // LOAD WEATHER FILE HERE $wth=weather_load($v->LOCFNAME); if($wth=="ERROR")return("ERROR"); print "
Advancing venue : ".$v->NAME."
"; $i=0; while(1) { if(!$v->SPECIES[$i]->NAME) break; else { venue_advancespecies($v, $i, $wth); } $i++; if($i==100)break; // Maximum number of species in place to stop endless loop } echo "Saving"; $xml->asXml($fname); return($xml); } ?>