Exemplo n.º 1
0
 /**
  * Returns array of objects where each object is a type of ship. See ships class
  * for details. In addition, the objects have the field:
  * 
  * - value fraction (total ship cost / total cost for all ships)
  * 
  * If $truncate == true, then ships objects of amount = 0 aren't returned.
  * 
  * @return unknown_type
  */
 public function get_all_ships($truncate)
 {
     // instantiate fleet objects
     $f0 = new member_fleet(0, $this->user_id);
     $f1 = new member_fleet(1, $this->user_id);
     $f2 = new member_fleet(2, $this->user_id);
     $f3 = new member_fleet(3, $this->user_id);
     // get ships from each fleet
     $s0 = $f0->get_ships_in_fleet(false, false);
     $s1 = $f1->get_ships_in_fleet(false, false);
     $s2 = $f2->get_ships_in_fleet(false, false);
     $s3 = $f3->get_ships_in_fleet(false, false);
     // cycle through the entire array and add up
     $ships_new = array();
     foreach ($s0 as $i => $ship) {
         // 1 - copy ship
         $ship_new = $ship;
         // 2 - add total amount from all fleets
         $ship->set_amount($s0[$i]->get_amount() + $s1[$i]->get_amount() + $s2[$i]->get_amount() + $s3[$i]->get_amount());
         // 3 - add to array
         $ships_new[] = $ship;
     }
     // compute total value
     $total_cost = 0;
     foreach ($ships_new as $ship) {
         $total_cost += $ship->get_amount() * $ship->get_cost();
     }
     // cycle through ships array and set fractional value
     foreach ($ships_new as $ship) {
         if ($total_cost == 0) {
             $ship->set_cost_fraction(0);
         } else {
             $ship->set_cost_fraction(round($ship->get_amount() * $ship->get_cost() / $total_cost, 2));
         }
     }
     // if $truncate = true; drop all ships with $amount = 0 from array
     if ($truncate) {
         foreach ($ships_new as $i => $ship) {
             if ($ship->get_amount() == 0) {
                 unset($ships_new[$i]);
             }
         }
         $ships_new = array_values($ships_new);
     }
     // return
     return $ships_new;
 }
Exemplo n.º 2
0
 }
 echo "</table>";
 echo "</div>";
 for ($j = 0; $j < 4; $j++) {
     if ($j == 0) {
         echo "<div class=\"content_subheader\">BASE FLEET <strong>&laquo;</strong></div>";
     } elseif ($j == 1) {
         echo "<div class=\"content_subheader\">FLEET 1 <strong>&laquo;</strong></div>";
     } elseif ($j == 2) {
         echo "<div class=\"content_subheader\">FLEET 2 <strong>&laquo;</strong></div>";
     } elseif ($j == 3) {
         echo "<div class=\"content_subheader\">FLEET 3 <strong>&laquo;</strong></div>";
     }
     // mf = member_fleet
     $mf = new member_fleet($j, $_GET['user_id']);
     $sf = $mf->get_ships_in_fleet(true, true);
     $return_tick = $mf->get_return_tick();
     echo "Return Tick: " . $return_tick . "<br />";
     echo "<div class=\"content_item\">";
     echo "<table>";
     echo "<tr class=\"title\">";
     echo "<td>Ship</td>";
     echo "<td>Class</td>";
     echo "<td>T1</td>";
     echo "<td>T2</td>";
     echo "<td>T3</td>";
     echo "<td>Type</td>";
     echo "<td>Amount</td>";
     echo "<td>Value</td>";
     echo "<td>Race</td>";
     echo "</tr>";