";
if($city['nation'] == 0) {
diff --git a/twe/func_converter.php b/twe/func_converter.php
index 9e2265c4..0693e7d0 100644
--- a/twe/func_converter.php
+++ b/twe/func_converter.php
@@ -63,129 +63,6 @@ function NationCharCall($call) {
return $type;
}
-
-function CityNameArray() {
- $cityNames = array(
- '','업','허창','낙양','장안','성도','양양','건업','북평','남피','완','수춘','서주','강릉','장사',
- '시상','위례','계','복양','진류','여남','하비','서량','하내','한중','상용','덕양','강주','건녕',
- '남해','계양','오','평양','사비','계림','진양','평원','북해','초','패','천수','안정','홍농',
- '하변','자동','영안','귀양','주시','운남','남영','교지','신야','강하','무릉','영릉','상동','여강',
- '회계','고창','대','안평','졸본','이도','강','저','흉노','남만','산월','오환','왜','호관',
- '호로','사곡','함곡','사수','양평','가맹','역경','계교','동황','관도','정도','합비','광릉','적도',
- '가정','기산','면죽','이릉','장판','백랑','적벽','파양','탐라','유구'
- );
- return $cityNames;
-}
-
-
-function CityCall($call) {
- switch($call) {
- case '업': $type = 1; break; case '허창': $type = 2; break;
- case '낙양': $type = 3; break; case '장안': $type = 4; break;
- case '성도': $type = 5; break; case '양양': $type = 6; break;
- case '건업': $type = 7; break; case '북평': $type = 8; break;
- case '남피': $type = 9; break; case '완': $type = 10; break;
- case '수춘': $type = 11; break; case '서주': $type = 12; break;
- case '강릉': $type = 13; break; case '장사': $type = 14; break;
- case '시상': $type = 15; break; case '위례': $type = 16; break;
- case '계': $type = 17; break; case '복양': $type = 18; break;
- case '진류': $type = 19; break; case '여남': $type = 20; break;
- case '하비': $type = 21; break; case '서량': $type = 22; break;
- case '하내': $type = 23; break; case '한중': $type = 24; break;
- case '상용': $type = 25; break; case '덕양': $type = 26; break;
- case '강주': $type = 27; break; case '건녕': $type = 28; break;
- case '남해': $type = 29; break; case '계양': $type = 30; break;
- case '오': $type = 31; break; case '평양': $type = 32; break;
- case '사비': $type = 33; break; case '계림': $type = 34; break;
- case '진양': $type = 35; break; case '평원': $type = 36; break;
- case '북해': $type = 37; break; case '초': $type = 38; break;
- case '패': $type = 39; break; case '천수': $type = 40; break;
- case '안정': $type = 41; break; case '홍농': $type = 42; break;
- case '하변': $type = 43; break; case '자동': $type = 44; break;
- case '영안': $type = 45; break; case '귀양': $type = 46; break;
- case '주시': $type = 47; break; case '운남': $type = 48; break;
- case '남영': $type = 49; break; case '교지': $type = 50; break;
- case '신야': $type = 51; break; case '강하': $type = 52; break;
- case '무릉': $type = 53; break; case '영릉': $type = 54; break;
- case '상동': $type = 55; break; case '여강': $type = 56; break;
- case '회계': $type = 57; break; case '고창': $type = 58; break;
- case '대': $type = 59; break; case '안평': $type = 60; break;
- case '졸본': $type = 61; break; case '이도': $type = 62; break;
- case '강': $type = 63; break; case '저': $type = 64; break;
- case '흉노': $type = 65; break; case '남만': $type = 66; break;
- case '산월': $type = 67; break; case '오환': $type = 68; break;
- case '왜': $type = 69; break; case '호관': $type = 70; break;
- case '호로': $type = 71; break; case '사곡': $type = 72; break;
- case '함곡': $type = 73; break; case '사수': $type = 74; break;
- case '양평': $type = 75; break; case '가맹': $type = 76; break;
- case '역경': $type = 77; break; case '계교': $type = 78; break;
- case '동황': $type = 79; break; case '관도': $type = 80; break;
- case '정도': $type = 81; break; case '합비': $type = 82; break;
- case '광릉': $type = 83; break; case '적도': $type = 84; break;
- case '가정': $type = 85; break; case '기산': $type = 86; break;
- case '면죽': $type = 87; break; case '이릉': $type = 88; break;
- case '장판': $type = 89; break; case '백랑': $type = 90; break;
- case '적벽': $type = 91; break; case '파양': $type = 92; break;
- case '탐라': $type = 93; break; case '유구': $type = 94; break;
- }
- return $type;
-}
-
-
-function CityNum($num) {
- switch($num) {
- case 1: $call = '업' ; break; case 2: $call = '허창'; break;
- case 3: $call = '낙양'; break; case 4: $call = '장안'; break;
- case 5: $call = '성도'; break; case 6: $call = '양양'; break;
- case 7: $call = '건업'; break; case 8: $call = '북평'; break;
- case 9: $call = '남피'; break; case 10: $call = '완' ; break;
- case 11: $call = '수춘'; break; case 12: $call = '서주'; break;
- case 13: $call = '강릉'; break; case 14: $call = '장사'; break;
- case 15: $call = '시상'; break; case 16: $call = '위례'; break;
- case 17: $call = '계' ; break; case 18: $call = '복양'; break;
- case 19: $call = '진류'; break; case 20: $call = '여남'; break;
- case 21: $call = '하비'; break; case 22: $call = '서량'; break;
- case 23: $call = '하내'; break; case 24: $call = '한중'; break;
- case 25: $call = '상용'; break; case 26: $call = '덕양'; break;
- case 27: $call = '강주'; break; case 28: $call = '건녕'; break;
- case 29: $call = '남해'; break; case 30: $call = '계양'; break;
- case 31: $call = '오' ; break; case 32: $call = '평양'; break;
- case 33: $call = '사비'; break; case 34: $call = '계림'; break;
- case 35: $call = '진양'; break; case 36: $call = '평원'; break;
- case 37: $call = '북해'; break; case 38: $call = '초' ; break;
- case 39: $call = '패' ; break; case 40: $call = '천수'; break;
- case 41: $call = '안정'; break; case 42: $call = '홍농'; break;
- case 43: $call = '하변'; break; case 44: $call = '자동'; break;
- case 45: $call = '영안'; break; case 46: $call = '귀양'; break;
- case 47: $call = '주시'; break; case 48: $call = '운남'; break;
- case 49: $call = '남영'; break; case 50: $call = '교지'; break;
- case 51: $call = '신야'; break; case 52: $call = '강하'; break;
- case 53: $call = '무릉'; break; case 54: $call = '영릉'; break;
- case 55: $call = '상동'; break; case 56: $call = '여강'; break;
- case 57: $call = '회계'; break; case 58: $call = '고창'; break;
- case 59: $call = '대' ; break; case 60: $call = '안평'; break;
- case 61: $call = '졸본'; break; case 62: $call = '이도'; break;
- case 63: $call = '강' ; break; case 64: $call = '저' ; break;
- case 65: $call = '흉노'; break; case 66: $call = '남만'; break;
- case 67: $call = '산월'; break; case 68: $call = '오환'; break;
- case 69: $call = '왜' ; break; case 70: $call = '호관'; break;
- case 71: $call = '호로'; break; case 72: $call = '사곡'; break;
- case 73: $call = '함곡'; break; case 74: $call = '사수'; break;
- case 75: $call = '양평'; break; case 76: $call = '가맹'; break;
- case 77: $call = '역경'; break; case 78: $call = '계교'; break;
- case 79: $call = '동황'; break; case 80: $call = '관도'; break;
- case 81: $call = '정도'; break; case 82: $call = '합비'; break;
- case 83: $call = '광릉'; break; case 84: $call = '적도'; break;
- case 85: $call = '가정'; break; case 86: $call = '기산'; break;
- case 87: $call = '면죽'; break; case 88: $call = '이릉'; break;
- case 89: $call = '장판'; break; case 90: $call = '백랑'; break;
- case 91: $call = '적벽'; break; case 92: $call = '파양'; break;
- case 93: $call = '탐라'; break; case 94: $call = '유구'; break;
- }
- return $call;
-}
-
-
function CharCall($call) {
switch($call) {
case '은둔': $type =10; break;
@@ -247,37 +124,6 @@ function SpecCall($call) {
return $type;
}
-
-function getCityLevel($level) {
- switch($level) {
- case 8: $call = '특'; break;
- case 7: $call = '대'; break;
- case 6: $call = '중'; break;
- case 5: $call = '소'; break;
- case 4: $call = '이'; break;
- case 3: $call = '관'; break;
- case 2: $call = '진'; break;
- case 1: $call = '수'; break;
- default:$call = '?'; break;
- }
- return $call;
-}
-
-function getRegion($region) {
- switch($region) {
- case 8: $call = '동이'; break;
- case 7: $call = '오월'; break;
- case 6: $call = '초'; break;
- case 5: $call = '남중'; break;
- case 4: $call = '서촉'; break;
- case 3: $call = '서북'; break;
- case 2: $call = '중원'; break;
- case 1: $call = '하북'; break;
- default:$call = '?'; break;
- }
- return $call;
-}
-
function getNationChiefLevel($level) {
switch($level) {
case 7: $lv = 5; break;
diff --git a/twe/func_legacy.php b/twe/func_legacy.php
index f068b72c..862b4e3d 100644
--- a/twe/func_legacy.php
+++ b/twe/func_legacy.php
@@ -57,11 +57,9 @@ function bar($per, $h=7) {
function OptionsForCitys() {
- $citynames = CityNameArray();
-
- for($i=1; $i <= 94; $i++) {
+ foreach(CityConst::all() as $city){
echo "
- ";
+ ";
}
}
@@ -108,23 +106,21 @@ function closeButton() {
function printCitysName($connect, $cityNo, $distance=1) {
$dist = distance($connect, $cityNo, $distance);
- $citynames = CityNameArray();
- $citynum = 94;
-
- $citystr = "";
- for($i=1; $i <= $citynum; $i++) {
-
- if($dist[$i] == $distance) {
- $citystr = $citystr.$citynames[$i].", ";
+ $cityList = [];
+ foreach(CityConst::all() as $city){
+ if($dist[$city->id] == $distance){
+ $cityList[] = $city->name;
}
}
+ $cityStr = join(', ', $cityList);
+
switch($distance) {
case 1: $color = "magenta"; break;
case 2: $color = "orange"; break;
default: $color = "yellow"; break;
}
- echo "{$distance}칸 떨어진 도시 : {$citystr} ";
+ echo "{$distance}칸 떨어진 도시 : {$cityStr} ";
}
diff --git a/twe/func_npc.php b/twe/func_npc.php
index 2174550d..a45da7b3 100644
--- a/twe/func_npc.php
+++ b/twe/func_npc.php
@@ -35,9 +35,9 @@ function RegGeneral($init,$life,$fiction,$turnterm,$startyear,$year,$gencount,$a
//$name = "ⓝ".$name;
$npc = 2;
if($city == "-") {
- $city = rand() % 94 + 1;
+ $city = rand(1, count(CityConst::all()));
} else {
- $city = CityCall($city);
+ $city = CityConst::byName($city)->id;
}
if($affinity == 0 || $fiction == 1) { $affinity = rand() % 150 + 1; }
if($life == 1) { $bornyear = 160; $deadyear = 300; }
@@ -1069,6 +1069,7 @@ function processAI($connect, $no) {
//$command = $fourth * 100000000 + $type * 100000 + $crew * 100 + 11;
function RegNation($name, $color, $gold, $rice, $scoutmsg, $tech, $gencount, $type, $level) {
+ //TODO: 삭제
$type = NationCharCall($type);
$totaltech = $tech * $gencount;
@@ -1093,11 +1094,11 @@ function RegNation($name, $color, $gold, $rice, $scoutmsg, $tech, $gencount, $ty
}
function RegCity($nation, $name, $cap=0) {
- $city = CityCall($name);
+ //TODO: 삭제
+ $city = CityConst::byName($name)->id;
DB::db()->update('city', [
'nation'=>$nation,
- 'city'=>$city
- ]);
+ ], 'city=%i',$city);
if($cap > 0){
DB::db()->update('nation', ['capital'=>city], 'nation = %i', $nation);
diff --git a/twe/sammo/Scenario.php b/twe/sammo/Scenario.php
index ca7a8830..eed9e569 100644
--- a/twe/sammo/Scenario.php
+++ b/twe/sammo/Scenario.php
@@ -25,19 +25,12 @@ class Scenario{
private $initialEvents;
private $events;
- public function __construct(int $scenarioIdx){
- $scenarioPath = self::SCENARIO_PATH."/scenario_{$scenarioIdx}.json";
+ private $initOK = false;
- $this->scenarioIdx = $scenarioIdx;
- $this->scenarioPath = $scenarioPath;
-
- $data = Json::decode(file_get_contents($scenarioPath));
- $this->data = $data;
-
- $this->year = Util::array_get($data['startYear']);
- $this->title = Util::array_get($data['title'] , '');
-
- $this->history = Util::array_get($data['history'], []);
+ private function initFull(){
+ if($this->initOK){
+ return;
+ }
$this->nations = [];
$this->nations[0] = new Scenario\Nation(0, '재야', '#ffffff', 0, 0);
@@ -149,6 +142,25 @@ class Scenario{
'action' => $action
];
}, Util::array_get($data['events'], []));
+ }
+
+ public function __construct(int $scenarioIdx, bool $lazyInit = true){
+ $scenarioPath = self::SCENARIO_PATH."/scenario_{$scenarioIdx}.json";
+
+ $this->scenarioIdx = $scenarioIdx;
+ $this->scenarioPath = $scenarioPath;
+
+ $data = Json::decode(file_get_contents($scenarioPath));
+ $this->data = $data;
+
+ $this->year = Util::array_get($data['startYear']);
+ $this->title = Util::array_get($data['title'] , '');
+
+ $this->history = Util::array_get($data['history'], []);
+
+ if(!$lazyInit){
+ $this->initFull();
+ }
}
@@ -165,76 +177,23 @@ class Scenario{
}
public function getNPC(){
+ $this->initFull();
return $this->generals;
}
public function getNPCex(){
+ $this->initFull();
return $this->generalsEx;
}
public function getNation(){
+ $this->initFull();
return $this->nations;
-
- $nationsRaw = Util::array_get($this->data['nation']);
- if(!$nationsRaw){
- return [];
- }
-
- $nations = [];
- foreach($nationsRaw as $idx=>$nation){
- list($name, $color, $gold, $rice, $infoText, $tech, $type, $nationLevel, $cities) = $nation;
- $nationID = $idx+1;
-
- $nation['id'] = $nationID;
-
- $nations[$nationID] = [
- 'id'=>$nationID,
- 'name'=>$name,
- 'color'=>$color,
- 'gold'=>$gold,
- 'rice'=>$rice,
- 'infoText'=>$infoText,
- 'tech'=>$tech,
- 'type'=>$type,
- 'nationLevel'=>$nationLevel,
- 'cities'=>$cities,
- 'generals'=>0
- ];
- }
-
- $nations[0] = [
- 'id'=>0,
- 'name'=>'재야',
- 'color'=>'#ffffff',
- 'gold'=>0,
- 'rice'=>0,
- 'infoText'=>'재야',
- 'tech'=>0,
- 'type'=>'재야',
- 'nationLevel'=>0,
- 'cities'=>[],
- 'generals'=>0
- ];
-
- foreach(Util::array_get($this->data['general'], []) as $idx=>$general){
- while(count($general) < 14){
- $general[] = null;
- }
- list(
- $a, $name, $npcname, $nationID, $specifiedCity,
- $leadership, $power, $intel, $birth, $death,
- $charDom, $charWar, $text
- ) = $general;
-
- if(array_key_exists($nationID, $nations)){
- $nations[$nationID]['generals']++;
- };
- }
-
- return $nations;
}
public function getScenarioBrief(){
+ $this->initFull();
+
$nations = [];
$nationGeneralCnt = [];
$nationGeneralExCnt = [];
@@ -275,6 +234,8 @@ class Scenario{
}
private function buildGenerals($env){
+ $this->initFull();
+
$remainGenerals = [];
foreach($this->generals as $general){
if($general->build($env)){
@@ -307,6 +268,8 @@ class Scenario{
}
private function buildDiplomacy($env){
+ $this->initFull();
+
$db = DB::db();
foreach($this->diplomacy as $diplomacy){
list($me, $you, $state, $remain) = $diplomacy;
@@ -318,6 +281,8 @@ class Scenario{
}
public function build($env=[]){
+ $this->initFull();
+
//NOTE: 초기화가 되어있다고 가정함.
/*
|