c2ephp
|
00001 <?php 00002 require_once(dirname(__FILE__).'/CreatureHistoryEvent.php'); 00003 require_once(dirname(__FILE__).'/../PRAY/GLSTBlock.php'); 00004 00005 00011 00012 00013 define('CREATUREHISTORY_GENDER_MALE',1); 00014 00016 define('CREATUREHISTORY_GENDER_FEMALE',2); 00018 00020 00023 class CreatureHistory { 00024 00026 00027 private $events; 00028 private $moniker; 00029 private $name; 00030 private $gender; 00031 private $genus; 00032 private $species; 00033 private $warpveteran; 00034 00035 00036 //TODO: find out what unknowns are` 00037 private $mutations; 00038 private $crossoverpoints; 00039 private $unknown1; 00040 private $unknown2; 00041 00043 00045 00052 public function CreatureHistory($moniker,$name,$gender,$genus,$species) { 00053 $this->moniker = $moniker; 00054 $this->name = $name; 00055 $this->gender = $gender; 00056 $this->genus = $genus; 00057 $this->species = $species; 00058 } 00059 00061 00065 public function Compile($format=GLST_FORMAT_C3) { 00066 $data = ''; 00067 if($format != GLST_FORMAT_C3 && $format != GLST_FORMAT_DS) { 00068 $format = $this->GuessFormat(); 00069 } 00070 if($format == GLST_FORMAT_DS) { 00071 $data = pack('V',0x27); 00072 } else { 00073 $data = pack('V',0x0C); 00074 } 00075 $data .= pack('V',1); 00076 $data .= pack('V',32).$this->moniker; 00077 $data .= pack('V',32).$this->moniker; //yeah, twice. Dunno why, CL are bonkers. 00078 $data .= pack('V',strlen($this->name)).$this->name; 00079 $data .= pack('VVVV',$this->gender,$this->genus,$this->species,count($this->events)); 00080 foreach($this->events as $event) { 00081 $data .= $event->Compile($format); 00082 } 00083 $data .= pack('V',$this->mutations); 00084 $data .= pack('V',$this->crossoverpoints); 00085 if($format == GLST_FORMAT_DS) { 00086 $data .= pack('V',$this->unknown1); 00087 $data .= pack('V',strlen($this->unknown2)).$this->unknown2; 00088 } 00089 return $data; 00090 } 00091 00093 00098 public function GuessFormat() { 00099 return (isset($this->unknown1))?GLST_FORMAT_DS:GLST_FORMAT_C3; 00100 } 00101 00103 00107 public function AddEvent(CreatureHistoryEvent $event) { 00108 $this->events[] = $event; 00109 } 00110 00112 00117 public function GetEvent($n) { 00118 return $this->events[$n]; 00119 } 00120 00122 00126 public function RemoveEvent($n) { 00127 unset($this->events[$n]); 00128 } 00129 00131 00134 public function CountEvents() { 00135 return sizeof($this->events); 00136 } 00137 00139 00144 public function GetEventsByType($type) { 00145 $matchingEvents = array(); 00146 foreach($this->events as $event) { 00147 if($event->GetEventType() == $type) { 00148 $matchingEvents[] = $event; 00149 } 00150 } 00151 return $matchingEvents; 00152 } 00153 00155 00158 public function GetEvents() { 00159 return $this->events; 00160 } 00161 00163 public function GetCreatureMoniker() { 00164 return $this->moniker; 00165 } 00166 00168 00174 public function GetCreatureGenerationNumber() { 00175 if($pos = strpos('_',$this->moniker) == -1) { 00176 return 0; 00177 } else { 00178 $firstbit = substr($this->moniker,0,$pos); 00179 if(is_numeric($firstbit)) { 00180 return $firstbit+0; 00181 } 00182 return 0; 00183 } 00184 } 00185 00187 public function GetCreatureName() { 00188 return $this->name; 00189 } 00190 00192 public function GetCreatureGender() { 00193 return $this->gender; 00194 } 00195 00197 public function GetCreatureGenus() { 00198 return $this->genus; 00199 } 00200 00202 public function GetCreatureSpecies() { 00203 return $this->species; 00204 } 00205 00207 public function GetCreatureIsWarpVeteran() { 00208 return $this->warpveteran; 00209 } 00210 00212 public function GetCreatureMutations() { 00213 return $this->mutations; 00214 } 00215 00217 public function GetCreatureCrossoverPoints() { 00218 return $this->crossoverpoints; 00219 } 00220 00221 public function SetMutationsAndCrossovers($mutations,$crossovers) { 00222 $this->mutations = $mutations; 00223 $this->crossoverpoints = $crossovers; 00224 } 00225 00226 00229 00234 public function SetDSUnknowns($unknown1,$unknown2) { 00235 $this->unknown1 = $unknown1; 00236 $this->unknown2 = $unknown2; 00237 } 00238 00240 00243 public function SetWarpVeteran($warpveteran) { 00244 $this->warpveteran = $warpveteran; 00245 } 00246 } 00247 00248 ?>