거리 측정 함수 새로 작성

- 이용하는 함수도 수정
This commit is contained in:
2018-04-02 01:50:51 +09:00
parent c0e2ed7013
commit 86ecf37da6
9 changed files with 171 additions and 184 deletions
+40 -17
View File
@@ -1819,27 +1819,50 @@ function ConquerCity($connect, $game, $general, $city, $nation, $destnation) {
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
//수도였으면 긴급 천도
if($destnation['capital'] == $city['city']) {
$dist = distance($connect, $city['city']);
$distList = searchDistance($city['city'], 99, true);
$query = "select city,name,pop from city where nation='{$destnation['nation']}' and city!='{$city['city']}'";
$result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
$cityCount = MYDB_num_rows($result);
$minDist = 99; $minCity = 0; $minCityPop = 0;
for($i=0; $i < $cityCount; $i++) {
$nextCap = MYDB_fetch_array($result);
if($minDist > $dist[$nextCap['city']]) {
$minDist = $dist[$nextCap['city']];
$minCity = $nextCap['city'];
$minCityPop = $nextCap['pop'];
$minCityName = $nextCap['name'];
} elseif($minDist == $dist[$nextCap['city']] && $minCityPop < $nextCap['pop']) {
$minDist = $dist[$nextCap['city']];
$minCity = $nextCap['city'];
$minCityPop = $nextCap['pop'];
$minCityName = $nextCap['name'];
$cities = [];
foreach(
DB::db()->query(
'SELECT city, pop FROM city WHERE nation=%i and city!=%i',
$destnation['nation'],
$city['city']
) as $row
){
$cities[$row['city']] = $row;
};
$distKeys = array_keys($distList);
sort($distKeys);
$minCity = 0;
foreach($distKeys as $dist){
$hasTarget = false;
$maxCityPop = 0;
foreach($distList[$dist] as $cityID){
$city = $cities[$cityID];
if($city['nation'] != $destnation['nation']){
continue;
}
if($city['pop'] <= $maxCityPop){
continue;
}
$hasTarget = true;
$minCity = $cityID;
$maxCityPop = $city['pop'];
}
if($hasTarget){
break;
}
}
$minCityName = CityConst::byID($minCity)->name;
$history[] = "<C>●</>{$game['year']}{$game['month']}월:<M><b>【긴급천도】</b></><D><b>{$destnation['name']}</b></>(이)가 수도가 함락되어 <G><b>$minCityName</b></>으로 긴급천도하였습니다.";
//아국 수뇌부에게 로그 전달