PHP:
1
| <? function stop($army_id) { global $haloplayerid; $sql = "SELECT starhalo_armies.army_id, start_x, start_y, starhalo_armies.end_x, starhalo_armies.end_y, start_time, (start_time+distance/MIN(speed)) as end_time, MIN(speed) as army_speed FROM (starhalo_armies INNER JOIN starhalo_units ON starhalo_armies.army_id=starhalo_units.army_id) LEFT JOIN starhalo_unittypes ON starhalo_units.unittype_id=starhalo_unittypes.unittype_id WHERE starhalo_armies.player_id='$haloplayerid' AND starhalo_armies.army_id='$army_id' GROUP BY starhalo_armies.army_id"; $result = mysql_query($sql); if ($row = mysql_fetch_object($result)) { $time = time(); if ($time<$row->end_time) { $time_traveled = $time - $row->start_time; $distance_traveled = $time_traveled * $row->army_speed; $horizontal = $row->end_x - $row->start_x; $vertical = $row->end_y - $row->start_y; $shief = sqrt($horizontal*$horizontal + $vertical*$vertical); $scale = $distance_traveled / $shief; $current_x = $row->start_x + ($horizontal * $scale); $current_y = $row->start_y + ($vertical * $scale); } else { $current_x = $row->end_x; $current_y = $row->end_y; } $current_x = round($current_x); $current_y = round($current_y); $sql = "UPDATE starhalo_armies SET start_x='$current_x', start_y='$current_y', end_x='$current_x', end_y='$current_y', distance='0', start_time='$time' WHERE army_id='$army_id' AND player_id='$haloplayerid'"; mysql_query($sql); $sql = "UPDATE starhalo_units SET end_x='$current_x', end_y='$current_y' end_time='$time' WHERE army_id='$army_id' AND player_id='$haloplayerid'"; mysql_query($sql); } } function newlocation($army_id, $new_x, $new_y) { global $haloplayerid; $sql = "SELECT starhalo_armies.army_id, start_x, start_y, starhalo_armies.end_x, starhalo_armies.end_y, start_time, (start_time+distance/MIN(speed)) as end_time, MIN(speed) as army_speed FROM (starhalo_armies INNER JOIN starhalo_units ON starhalo_armies.army_id=starhalo_units.army_id) LEFT JOIN starhalo_unittypes ON starhalo_units.unittype_id=starhalo_unittypes.unittype_id WHERE starhalo_armies.player_id='$haloplayerid' AND starhalo_armies.army_id='$army_id' GROUP BY starhalo_armies.army_id"; $result = mysql_query($sql); if ($row = mysql_fetch_object($result)) { $time = time(); if ($time<$row->end_time) { $time_traveled = $time - $row->start_time; $distance_traveled = $time_traveled * $row->army_speed; $horizontal = $row->end_x - $row->start_x; $vertical = $row->end_y - $row->start_y; $shief = sqrt($horizontal*$horizontal + $vertical*$vertical); $scale = $distance_traveled / $shief; $current_x = $row->start_x + ($horizontal * $scale); $current_y = $row->start_y + ($vertical * $scale); } else { $current_x = $row->end_x; $current_y = $row->end_y; } $current_x = round($current_x); $current_y = round($current_y); $horizontal = $new_x - $current_x; $vertical = $new_y - $current_y; $distance_to_travel = sqrt($horizontal*$horizontal + $vertical*$vertical); $sql = "UPDATE starhalo_armies SET start_x='$current_x', start_y='$current_y', end_x='$new_x', end_y='$new_y', distance='$distance_to_travel', start_time='$time' WHERE army_id='$army_id' AND player_id='$haloplayerid'"; $result = mysql_query($sql); $sql = "UPDATE starhalo_units SET end_x='$new_x', end_y='$new_y', end_time='". round($time+$distance_to_travel/$row->army_speed) ."' WHERE army_id='$army_id' AND player_id='$haloplayerid'"; $result = mysql_query($sql); } }?> |
functie stop() is om het leger te stoppen, functie newlocation() om de nieuwe locatie op te geven.
Nadat ik op het knopje stop heb geklikt en hij dus de functie stop() heeft uitgevoerd doet hij de laatste twee queries van newlocation() niet meer goed.
De queries kloppen wel als ik ze laat zien, maar hij voert ze niet goed uit. Hij update alleen de tijd.
(sorry voor de lange, slordige sql queries)