Exemplo n.º 1
0
function damage_ship($amount, $fig_dam, $s_dam, $from, $target, $target_ship)
{
    global $db_name, $query;
    //set the shields down first off (if needed).
    if ($s_dam > 0) {
        $target_ship['shields'] -= $s_dam;
        if ($target_ship['shields'] < 0) {
            $target_ship['shields'] == 0;
        }
        dbn("update {$db_name}_ships set shields = shields - '{$s_dam}' where ship_id = '{$target_ship['ship_id']}'");
    }
    //take the fighters down next (if needed).
    if ($fig_dam > 0) {
        $target_ship['fighters'] -= $fig_dam;
        if ($target_ship['fighters'] < 0) {
            $target_ship['fighters'] == 0;
        }
        dbn("update {$db_name}_ships set fighters = fighters - '{$fig_dam}' where ship_id = '{$target_ship['ship_id']}'");
    }
    //don't want to hurt the admin now do we?
    if ($target['login_id'] != 1) {
        //only play with the amount distribution if there is no value to amount
        if ($amount > 0) {
            $shield_damage = $amount;
            if ($shield_damage > $target_ship['shields']) {
                $shield_damage = $target_ship['shields'];
            }
            $amount -= $shield_damage;
        }
        if ($amount >= $target_ship['fighters'] || $amount < 0) {
            //destroy ship
            //Minerals go to the system
            if ($from['location'] != 1 && ($target_ship['fuel'] > 0 || $target_ship['metal']) > 0) {
                dbn("update {$db_name}_stars set fuel = fuel + " . round($target_ship[fuel] * (mt_rand(20, 80) / 100)) . ", metal = metal + " . round($target_ship[metal] * (mt_rand(40, 90) / 100)) . " where star_id = {$target_ship['location']}");
            }
            dbn("delete from {$db_name}_ships where ship_id = '{$target_ship['ship_id']}'");
            dbn("update {$db_name}_users set fighters_killed = fighters_killed + '{$target_ship['fighters']}', ships_killed = ships_killed + '1', ships_killed_points = ships_killed_points + '{$target_ship['point_value']}' where login_id = '{$from['login_id']}'");
            dbn("update {$db_name}_users set fighters_lost = fighters_lost + '{$target_ship['fighters']}', ships_lost = ships_lost + '1', ships_lost_points = ships_lost_points + '{$target_ship['point_value']}' where login_id = '{$target['login_id']}'");
            if (eregi($cw['escape'], $target_ship['class_name'])) {
                // escape pod lost
                dbn("update {$db_name}_users set location = '1', ship_id = '1', last_attack = " . time() . ", last_attack_by = '{$from['login_name']}', explored_sys = '1' where login_id = '{$target['login_id']}'");
                wipe_player($target['login_id'], $target['clan_id']);
                return 1;
            } else {
                // normal ship lost
                //don't bother putting an AI into a new ship to command etc.
                if ($target['login_id'] > 5) {
                    if ($target['ship_id'] != $target_ship['ship_id']) {
                        $new_ship_id = $target['ship_id'];
                    } else {
                        db("select ship_id from {$db_name}_ships where login_id = '{$target_ship['login_id']}' LIMIT 1");
                        $other_ship = dbr();
                        if (!empty($other_ship['ship_id'])) {
                            // jump to other ship
                            $new_ship_id = $other_ship['ship_id'];
                        } else {
                            // build the escape pod
                            create_escape_pod($target);
                            return 2;
                        }
                    }
                    // set ships_killed
                    if ($target['login_id'] > 5) {
                        db("select location from {$db_name}_ships where ship_id = '{$new_ship_id}'");
                        $other_ship = dbr();
                    } else {
                        $other_ship['location'] = 1;
                    }
                    dbn("update {$db_name}_users set ship_id = '{$new_ship_id}', location = '{$other_ship['location']}', last_attack =" . time() . ", last_attack_by = '{$from['login_name']}' where login_id = '{$target['login_id']}'");
                }
            }
            return 1;
        } else {
            // ship not destroyed
            dbn("update {$db_name}_users set last_attack = " . time() . ", last_attack_by = '{$from['login_name']}' where login_id = '{$target['login_id']}'");
            dbn("update {$db_name}_ships set fighters = fighters - '{$amount}', shields = shields - '{$shield_damage}' where ship_id = '{$target_ship['ship_id']}'");
            dbn("update {$db_name}_users set fighters_lost = fighters_lost + '{$amount}' where login_id = '{$target['login_id']}'");
            dbn("update {$db_name}_users set fighters_killed = fighters_killed + '{$amount}' where login_id = '{$from['login_id']}'");
            return 0;
        }
    }
    return 0;
}
Exemplo n.º 2
0
                 }
             }
         }
     }
     //Delete any destroyed ships.
     if (!empty($delete_sql)) {
         $delete_sql = preg_replace("/\\|\\| \$/", "", $delete_sql);
         dbn("delete from {$db_name}_ships where " . $delete_sql);
     }
     /***********
      * Quick loop through players
      ***********/
     foreach ($players_array as $player_id => $player) {
         //think the player has lost EP, so wipe them out.
         if ($player['ship_id'] == 1 && $player['location'] == 1 && $player['login_id'] > 4) {
             wipe_player($player_id, $player['clan_id']);
         }
     }
     //ships are now free to do as they will
     if (!empty($disengage_sql)) {
         $disengage_sql = preg_replace("/\\|\\| \$/", "", $disengage_sql);
         dbn("update {$db_name}_ships set ship_engaged = 0 where " . $disengage_sql);
     }
     //planets are now free to do as they will as well
     if (!empty($disengage_planets_sql)) {
         $disengage_planets_sql = preg_replace("/\\|\\| \$/", "", $disengage_planets_sql);
         dbn("update {$db_name}_planets set planet_engaged = 0 where " . $disengage_planets_sql);
     }
     charge_turns($total_attack_turn_cost);
 } else {
     //even simulations take turns to run!