/**
  * Save Data: Saves the combat report
  */
 protected function saveDataReport()
 {
     // insert report
     if ($this->winner == 'defender' && $this->roundNo == 1) {
         $oneRound = true;
     } else {
         $oneRound = false;
     }
     $users = array();
     foreach ($this->navalFormationUsers as $userID => $userObj) {
         $users[$userID] = $userID;
     }
     foreach ($this->standByUsers as $userID => $userObj) {
         $users[$userID] = $userID;
     }
     $report = CombatReport::create($this->impactTime, $this->report, $oneRound, $users);
     $reportID = $report->reportID;
     // sending message
     $subject = WCF::getLanguage()->get('wot.fleet.combat.subject');
     //$message = '<a class="thickbox" href="game/index.php?page=CombatReportView&reportID='.$reportID.'&keepThis=true&TB_iframe=true&height=400&width=500"><font color="red">'.$subject.' ['.$this->galaxy.':'.$this->system.':'.$this->planet.'] (V:'.number_format($this->units['defender'], 0, ',', '.').', A:'.number_format($this->units['attacker'], 0, ',', '.').')</font></a>';
     $messagePre = '<a class="thickbox ';
     $messageAfter = '" href="game/index.php?page=CombatReportView&reportID=' . $reportID . '&keepThis=true&TB_iframe=true&height=400&width=500">' . $subject . ' [' . $this->galaxy . ':' . $this->system . ':' . $this->planet . '] (V:' . number_format($this->units['defender'], 0, ',', '.') . ', A:' . number_format($this->units['attacker'], 0, ',', '.') . ')</a>';
     $senderOwner = WCF::getLanguage()->get('wot.fleet.combat.sender.owner');
     $senderOfiara = WCF::getLanguage()->get('wot.fleet.combat.sender.ofiara');
     foreach ($users as $userID) {
         if ($userID == $this->ofiaraID) {
             $sender = $senderOfiara;
         } else {
             $sender = $senderOwner;
         }
         if (isset($this->navalFormationUsers[$userID])) {
             $class = 'combatReport_attacker_' . $this->winner;
         } else {
             $class = 'combatReport_defender_' . $this->winner;
         }
         $message = $messagePre . $class . $messageAfter;
         MessageEditor::create($userID, $subject, $message, 0, $sender, 3);
     }
 }
 /**
  * Save Data: Saves the combat report
  */
 protected function saveDataReport()
 {
     // insert report
     if ($this->winner == 'defender' && $this->roundNo == 1) {
         $oneRound = true;
     } else {
         $oneRound = false;
     }
     $users = array();
     foreach ($this->navalFormationUsers as $userID => $userObj) {
         $users[$userID] = $userID;
     }
     foreach ($this->standByUsers as $userID => $userObj) {
         $users[$userID] = $userID;
     }
     $report = CombatReport::create($this->impactTime, $this->report, $oneRound, $users);
     $reportID = $report->reportID;
     // sending message
     $subject = $this->parse(WCF::getLanguage()->get('wot.fleet.combat.subject'));
     $message = $this->summary;
     $message .= '<a class="thickbox" href="index.php?page=CombatReportView&reportID=' . $reportID;
     $message .= '&keepThis=true&TB_iframe=true&height=80%&width=80%">';
     $message .= WCF::getLanguage()->get('wot.fleet.combat.showReport') . '</a>';
     $senderOwner = WCF::getLanguage()->get('wot.fleet.combat.sender.owner');
     $senderOfiara = WCF::getLanguage()->get('wot.fleet.combat.sender.ofiara');
     foreach ($this->navalFormationUsers as $userID => $userObj) {
         NMessageEditor::create($userID, array(3, 2), $subject, '<div class="combatSummary attacker">' . $message . '</div>', 2);
     }
     foreach ($this->standByUsers as $userID => $userObj) {
         NMessageEditor::create($userID, array(3, 1), $subject, '<div class="combatSummary defender">' . $message . '</div>', 2);
     }
     foreach ($users as $userID) {
         if ($userID == $this->ofiaraID) {
             $sender = $senderOfiara;
         } else {
             $sender = $senderOwner;
         }
         /*
         if(isset($this->navalFormationUsers[$userID])) {
         	$class = 'combatReport_attacker_'.$this->winner;
         	$senderID = 2;
         }
         else {
         	$class = 'combatReport_defender_'.$this->winner;	
         	$senderID = 1;			
         }
         $message = $this->summary.'<br /><br />'.$message;
         */
         MessageEditor::create($userID, $subject, $message, 0, $sender, 3);
         //NMessageEditor::create($userID, array(3, $senderID),
         //	$subject, $message, 2);
     }
 }
Пример #3
0
 /**
  * Prepares the data for simulation
  */
 protected function simulate()
 {
     // organize data
     foreach ($this->shipDataArray as $key => $value) {
         if (empty($value)) {
             continue;
         }
         $nfsSlotNo = intval(substr($key, 8, 2));
         $front = strtolower(substr($key, 10, 8));
         $isTech = strlen($key) > 21;
         $arrayName = $front . 'Fleets';
         if ($isTech) {
             $techID = substr($key, -3);
             $this->{$arrayName}[$nfsSlotNo]['tech'][$techID] = intval($value);
         } else {
             $techID = substr($key, -3);
             $this->{$arrayName}[$nfsSlotNo]['fleet'][$techID] = intval($value);
         }
     }
     if (!count($this->attackerFleets) || !count($this->defenderFleets)) {
         return;
     }
     // create objs
     foreach ($this->attackerFleets as $nfsSlotNo => $fleetData) {
         $fleetStr = LWUtil::serialize($fleetData['fleet']);
         $array = array('fleet' => Spec::arrayToStr($fleetData['fleet']), 'galaxy' => 0, 'system' => 0, 'planet' => 0, 'ownerID' => 0, 'targetPlanetID' => 0, 'fleetID' => 0, 'weaponTech' => $fleetData['tech'][109], 'shieldTech' => $fleetData['tech'][110], 'hullPlatingTech' => $fleetData['tech'][111]);
         $this->attackerFleetObjs[$nfsSlotNo] = new PhantomFleet(null, $array);
     }
     $simulatingFleetArray = $array;
     foreach ($this->defenderFleets as $nfsSlotNo => $fleetData) {
         $fleetStr = LWUtil::serialize($fleetData['fleet']);
         $array = array('fleet' => Spec::arrayToStr($fleetData['fleet']), 'galaxy' => 0, 'system' => 0, 'planet' => 0, 'ownerID' => 0, 'targetPlanetID' => 0, 'fleetID' => 0, 'weaponTech' => $fleetData['tech'][109], 'shieldTech' => $fleetData['tech'][110], 'hullPlatingTech' => $fleetData['tech'][111]);
         $this->defenderFleetObjs[$nfsSlotNo] = new PhantomFleet(null, $array);
     }
     // simulate
     set_time_limit(60);
     for ($i = 0; $i < self::SIMULATIONS; ++$i) {
         try {
             ob_start();
             $simulator = new CombatSimulator($this->attackerFleetObjs, $this->defenderFleetObjs, $simulatingFleetArray);
             $simulator->simulate();
             ob_clean();
         } catch (Exception $e) {
             message('Es ist ein fehler bei der Simulation aufgetreten!');
         }
         $this->unitsAttackerArray[$i] = $simulator->units['attacker'];
         $this->unitsDefenderArray[$i] = $simulator->units['defender'];
         $this->debrisMetalArray[$i] = $simulator->debris['metal'];
         $this->debrisCrystalArray[$i] = $simulator->debris['crystal'];
         $this->bootyArray[$i] = $simulator->totalCapacity;
         $this->roundNoArray[$i] = $simulator->roundNo;
         $this->winnerArray[$i] = $simulator->winner;
         // check extrema
         if ($i == 0) {
             //var_dump($simulator);
             $this->minSimulator = $this->maxSimulator = $simulator;
             continue;
         }
         // real best case: difference in attacker units
         $byAttackerUnits = $simulator->units['attacker'] < $this->minSimulator->units['attacker'];
         // unreal best case: no difference in attacker units, but more defender units
         $byDefenderUnits = $simulator->units['attacker'] == $this->minSimulator->units['attacker'] && $simulator->units['defender'] > $this->minSimulator->units['defender'];
         if ($byAttackerUnits || $byDefenderUnits) {
             $this->minSimulator = $simulator;
         }
         // real worst case: difference in attacker units
         $byAttackerUnits = $simulator->units['attacker'] > $this->maxSimulator->units['attacker'];
         // unreal worst case: no difference in attacker units, but less defender units
         $byDefenderUnits = $simulator->units['attacker'] == $this->maxSimulator->units['attacker'] && $simulator->units['defender'] < $this->maxSimulator->units['defender'];
         if ($byAttackerUnits || $byDefenderUnits) {
             $this->maxSimulator = $simulator;
         }
     }
     $simulator->generateReport();
     $report = CombatReport::create(time(), $simulator->report, false, array(WCF::getUser()->userID => WCF::getUser()->userID));
     $this->reportID = $report->reportID;
     // sum up (avg)
     $this->units['attacker'] = array_sum($this->unitsAttackerArray) / self::SIMULATIONS;
     $this->units['defender'] = array_sum($this->unitsDefenderArray) / self::SIMULATIONS;
     $this->debris['metal'] = array_sum($this->debrisMetalArray) / self::SIMULATIONS;
     $this->debris['crystal'] = array_sum($this->debrisCrystalArray) / self::SIMULATIONS;
     $this->booty = array_sum($this->bootyArray) / self::SIMULATIONS;
     $this->roundNo = array_sum($this->roundNoArray) / self::SIMULATIONS;
     // sum up (min)
     $this->minUnits['attacker'] = $this->minSimulator->units['attacker'];
     $this->minUnits['defender'] = $this->minSimulator->units['defender'];
     $this->minDebris['metal'] = $this->minSimulator->debris['metal'];
     $this->minDebris['crystal'] = $this->minSimulator->debris['crystal'];
     $this->minBooty = $this->minSimulator->totalCapacity;
     // sum up (max)
     $this->maxUnits['attacker'] = $this->maxSimulator->units['attacker'];
     $this->maxUnits['defender'] = $this->maxSimulator->units['defender'];
     $this->maxDebris['metal'] = $this->maxSimulator->debris['metal'];
     $this->maxDebris['crystal'] = $this->maxSimulator->debris['crystal'];
     $this->maxBooty = $this->maxSimulator->totalCapacity;
     $this->winner = array_count_values($this->winnerArray);
 }
Пример #4
0
 /**
  * Creates a new combat report database representation.
  * 
  * @param	int		time
  * @param	string	text
  * @param	boolean	one round
  * @param	array	users
  * @return	CombatReport
  */
 public static function create($time, $text, $oneRound, $users)
 {
     $reportID = self::insert($time, $text, $oneRound);
     $reportObj = new CombatReport($reportID);
     $reportObj->addUsers($users);
     return $reportObj;
 }