Develop and Download Open Source Software

Browse Subversion Repository

Contents of /trunk/CStation.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3 - (show annotations) (download) (as text)
Tue Nov 23 14:34:03 2010 UTC (13 years, 5 months ago) by okadu
File MIME type: text/x-c++src
File size: 9239 byte(s)
[okadu] Version 2.13
1 #include "stdafx.h"
2 #include "CPopMenu.h"
3 #include "CSimpleDialog.h"
4 #include "CRailWay.h"
5 #include "CScene.h"
6 #include "CSaveFile.h"
7 #include "CStation.h"
8 #include "CStationPlugin.h"
9 #include "CStationEditMode.h"
10 #include "CDiaEditMode.h"
11
12 // static メンバ
13 CStation **CStation::ms_Root = NULL;
14
15 /*
16 * コンストラクタ (読込用)
17 */
18 CPlatformInst::CPlatformInst(
19 CStation *station // 駅
20 ){
21 m_Length = -1.0f;
22 m_Stoppable = false;
23 m_OpenDoor[0] = m_OpenDoor[1] = false;
24 m_Station = station;
25 }
26
27 /*
28 * コンストラクタ
29 */
30 CPlatformInst::CPlatformInst(
31 CStation *station, // 駅
32 bool stoppable, // 停車可能 /*CP932対応*/
33 bool *opendoor // ドア開
34 ){
35 m_Length = -1.0f;
36 m_Stoppable = stoppable;
37 int i;
38 for(i = 0; i<2; i++) m_OpenDoor[i] = opendoor[i];
39 m_Station = station;
40 }
41
42 /*
43 * レール削除
44 */
45 void CPlatformInst::DeleteRailWay(
46 CRailWay *way // レール
47 ){
48 m_Length = -1.0f;
49 m_RailList.remove(way);
50 }
51
52 /*
53 * プラットフォーム削除
54 */
55 void CPlatformInst::DeletePlatform(){
56 g_SaveFile->DeletePlatform(this);
57 IPRailWay ipr = m_RailList.begin();
58 for(; ipr!=m_RailList.end(); ipr++){
59 (*ipr)->SetPlatform(NULL);
60 (*ipr)->SetParent(NULL);
61 }
62 }
63
64 /*
65 * プラットフォーム親設定
66 */
67 void CPlatformInst::SetPlatformParent(CDetectInfo *d_info){
68 IPRailWay ipr = m_RailList.begin();
69 for(; ipr!=m_RailList.end(); ipr++) (*ipr)->SetParent(d_info);
70 }
71
72 /*
73 * 長さ計算
74 */
75 float CPlatformInst::GetLength(){
76 if(m_Length<0.0f){
77 m_Length = 0.0f;
78 IPRailWay ipr = m_RailList.begin();
79 for(; ipr!=m_RailList.end(); ipr++) m_Length += (*ipr)->GetSegLen();
80 }
81 return m_Length;
82 }
83
84 /*
85 * 状態取得 (1: approach, 2: stop)
86 */
87 int CPlatformInst::GetPlatformState(){
88 int state = 0;
89 IPRailWay ipr = m_RailList.begin();
90 for(; ipr!=m_RailList.end(); ipr++) state |= (*ipr)->GetPlatformState();
91 return state;
92 }
93
94 /*
95 * シミュレーション進行
96 */
97 void CPlatformInst::Simulate(){
98 IPRailWay ipr = m_RailList.begin();
99 for(; ipr!=m_RailList.end(); ipr++) (*ipr)->UpdateSplitList();
100 }
101
102 /*
103 * アドレス復元
104 */
105 void CPlatformInst::RestoreAddress(){
106 IPRailWay ipr = m_RailList.begin();
107 for(; ipr!=m_RailList.end(); ipr++) *ipr = (CRailWay *)ReplaceAdr(*ipr);
108 }
109
110 /*
111 * 読込
112 */
113 char *CPlatformInst::Read(
114 char *str // 対象文字列
115 ){
116 char *eee, *tmp;
117 if(!(str = BeginBlock(str, "Platform"))) return NULL;
118 void *oldadr;
119 if(!(str = AsgnPointer(eee = str, "Address", &oldadr))) throw CSynErr(eee);
120 if(!(str = AsgnYesNo(eee = str, "Stoppable", &m_Stoppable))) throw CSynErr(eee);
121 if(!(str = AsgnYesNo(eee = str, "OpenDoor", m_OpenDoor, 2, false))) throw CSynErr(eee);
122 g_AddressMap[oldadr] = this;
123 if(tmp = Assignment(str, "RailList")){
124 str = tmp;
125 do{
126 if(m_RailList.size() && !(str = Character2(eee = str, ','))) throw CSynErr(eee);
127 CRailWay *way;
128 if(!(str = HexPointer(eee = str, (void **)&way))) throw CSynErr(eee);
129 m_RailList.push_back(way);
130 } while(!(tmp = Character2(str, ';')));
131 str = tmp;
132 }
133 if(!(str = EndBlock(eee = str))) throw CSynErr(eee, ERR_ENDBLOCK);
134 return str;
135 }
136
137 /*
138 * 保存
139 */
140 void CPlatformInst::Save(
141 FILE *df // ファイル
142 ){
143 fprintf(df, "\t\t\t\t\tPlatform{\n");
144 fprintf(df, "\t\t\t\t\t\tAddress = %p;\n", this);
145 fprintf(df, "\t\t\t\t\t\tStoppable = %s;\n", YESNO[m_Stoppable]);
146 fprintf(df, "\t\t\t\t\t\tOpenDoor = %s, %s;\n",
147 YESNO[m_OpenDoor[0]], YESNO[m_OpenDoor[1]]);
148 if(m_RailList.size()){
149 fprintf(df, "\t\t\t\t\t\tRailList = ");
150 IPRailWay ipr = m_RailList.begin();
151 for(; ipr!=m_RailList.end(); ipr++) fprintf(
152 df, ipr==m_RailList.begin() ? "%p" : ", %p", *ipr);
153 fprintf(df, ";\n");
154 }
155 fprintf(df, "\t\t\t\t\t}\n");
156 }
157
158 ////////////////////////////////////////////////////////////////////////////////
159 ////////////////////////////////////////////////////////////////////////////////
160
161 /*
162 * コンストラクタ (読込用)
163 */
164 CStation::CStation(){
165 m_StationPlugin = NULL;
166 m_Next = NULL;
167 }
168
169 /*
170 * コンストラクタ
171 */
172 CStation::CStation(
173 CStationPlugin *spi, // 駅舎プラグイン
174 VEC3 pos, // 位置
175 VEC3 dir, // dir
176 VEC3 up // up
177 ):
178 CStruct(spi, pos, dir, up, false) // 基本クラス
179 {
180 m_StationPlugin = spi;
181 m_Next = *ms_Root;
182 *ms_Root = this;
183 g_SystemObject[SYS_OBJ_LOCAL].SetPreviewPosture(m_Pos, m_Dir, m_Up);
184 m_StationPlugin->BuildPlatform(this);
185 }
186
187 /*
188 * デストラクタ
189 */
190 CStation::~CStation(){
191 DELETE_V(m_Next); // CStruct::m_Next is not linked
192 }
193
194 /*
195 * プラットフォーム追加
196 */
197 CPlatformInst *CStation::PushPlatformInst(
198 CPlatformInst &pfi // 停車可能 /*CP932対応*/
199 ){
200 m_PlatformList.push_back(pfi);
201 return &*m_PlatformList.rbegin();
202 }
203
204 /*
205 * プラットフォーム配列構築
206 */
207 void CStation::MakePlatformArray(){
208 m_PlatformArray.clear();
209 IPlatformInst ipi = m_PlatformList.begin();
210 for(; ipi!=m_PlatformList.end(); ipi++) m_PlatformArray.push_back(&*ipi);
211 }
212
213 /*
214 * プラグイン選択モード取得
215 */
216 bool CStation::IsSelectVisible(){
217 return g_StationEditMode->IsModeActive() || g_DiaEditMode->IsModeActive();
218 }
219
220 /*
221 * 撤去
222 */
223 void CStation::Remove(){
224 m_Scene->DeleteStation(this);
225 }
226
227 /*
228 * リストから削除
229 */
230 void CStation::Delete(){
231 m_Next = NULL;
232 IPlatformInst ipi = m_PlatformList.begin();
233 for(; ipi!=m_PlatformList.end(); ipi++) ipi->DeletePlatform();
234 delete this;
235 }
236
237 /*
238 * 操作
239 */
240 CModelInst *CStation::Control(){
241 if(CEditBox::IsActive()) return this;
242 if(GetKey(DIK_DELETE)==S_PUSH){
243 class CStationDeleter: public CMenuCommand{
244 private:
245 CStation *m_Station; // 駅舎
246 public:
247 CStationDeleter(CStation *s){ m_Station = s; }
248 void Exec(){
249 void PushUndoStack();
250 PushUndoStack();
251 m_Station->Remove();
252 }
253 };
254 CYesNoDialog *dlg = new CYesNoDialog(
255 lang(DeleteStationCfmMessage), lang(Confirmation), false);
256 dlg->SetYesCommand(new CStationDeleter(this));
257 EnqueueCommonDialog(dlg);
258 }
259 return this;
260 }
261
262 /*
263 * シミュレーション進行
264 */
265 void CStation::SimulateStruct(){
266 IPlatformInst ipi = m_PlatformList.begin();
267 for(; ipi!=m_PlatformList.end(); ipi++) ipi->Simulate();
268 }
269
270 /*
271 * 専用スイッチ設定
272 */
273 void CStation::SetSwitchStruct(){
274 int i = 0, apr1 = 0, apr2 = 0, stpp = 0;
275 IPlatformInst ipi = m_PlatformList.begin();
276 for(; ipi!=m_PlatformList.end(); ipi++, i++){
277 int state = ipi->GetPlatformState();
278 if(state&1) apr1 |= 1<<i;
279 if(state&2) apr2 |= 1<<i;
280 if(state&4) stpp |= 1<<i;
281 }
282 g_SystemSwitch[SYS_SW_APPROACH1].SetValue(apr1);
283 g_SystemSwitch[SYS_SW_APPROACH2].SetValue(apr2);
284 g_SystemSwitch[SYS_SW_STOPPING].SetValue(stpp);
285 }
286
287 /*
288 * 停車可能か
289 */
290 bool CStation::IsStoppable(){
291 IPlatformInst ipi = m_PlatformList.begin();
292 for(; ipi!=m_PlatformList.end(); ipi++) if(ipi->IsStoppable()) return true;
293 return false;
294 }
295
296 /*
297 * アドレス復元
298 */
299 void CStation::RestoreAddress(){
300 IPlatformInst ipi = m_PlatformList.begin();
301 for(; ipi!=m_PlatformList.end(); ipi++) ipi->RestoreAddress();
302 m_DiaInst.RestoreAddress();
303 list<CPlatformInst>::iterator pfi_itr = m_PlatformList.begin();
304 list<CPlatform>::iterator pf_itr = m_StationPlugin->m_Platform.begin();
305 for(; pfi_itr!=m_PlatformList.end(); pfi_itr++){
306 if(pf_itr==m_StationPlugin->m_Platform.end()) break;
307 if(pf_itr->m_ParentObject){
308 CPartsInst *parts = FindParts(pf_itr->m_ParentObject);
309 if(!parts) ErrorDialog("INTERNAL ERROR: PLATFORM PARENT PARTS NOT FOUND: %s", pf_itr->m_ParentObject->GetName());
310 CDetectInfo d_info = CDetectInfo(pf_itr->m_ParentObject, this, parts);
311 pfi_itr->SetPlatformParent(&d_info);
312 }
313 ++pf_itr;
314 }
315 }
316
317 /*
318 * 読込
319 */
320 char *CStation::Read(
321 char *str // 対象文字列
322 ){
323 char *eee, *tmp;
324 if(!(str = BeginBlock(str, "Station"))){
325 delete this;
326 return NULL;
327 }
328 void *oldadr;
329 if(!(str = AsgnPointer(eee = str, "Address", &oldadr))) throw CSynErr(eee);
330 g_AddressMap[oldadr] = this;
331 string pid;
332 if(!(str = AsgnString(eee = str, "StationPlugin", &pid))) throw CSynErr(eee);
333 m_ModelPlugin = m_StructPlugin =
334 m_StationPlugin = g_StationPluginList->FindPlugin(pid.c_str(), true);
335 if(!(str = ReadModelInst(eee = str, true))) throw CSynErr(eee);
336
337 if(!(str = BeginBlock(eee = str, "PlatformList"))) throw CSynErr(eee);
338 while(true){
339 m_PlatformList.push_back(CPlatformInst(this));
340 if(tmp = m_PlatformList.rbegin()->Read(eee = str)){
341 str = tmp;
342 }else{
343 m_PlatformList.pop_back();
344 break;
345 }
346 }
347 MakePlatformArray();
348 if(!(str = EndBlock(eee = str))) throw CSynErr(eee, ERR_ENDBLOCK);
349
350 if(tmp = m_DiaInst.Read(str)) str = tmp;
351 if(!(str = EndBlock(eee = str))) throw CSynErr(eee, ERR_ENDBLOCK);
352 *ms_Root = this;
353 ms_Root = &m_Next;
354 return str;
355 }
356
357 /*
358 * 保存
359 */
360 void CStation::Save(
361 FILE *df // ファイル
362 ){
363 fprintf(df, "\t\t\tStation{\n");
364 fprintf(df, "\t\t\t\tAddress = %p;\n", this);
365 fprintf(df, "\t\t\t\tStationPlugin = \"%s\";\n", CheckPluginID(m_StationPlugin));
366 SaveModelInst(df, "\t\t\t\t", true);
367 fprintf(df, "\t\t\t\tPlatformList{\n");
368 IPlatformInst ipi = m_PlatformList.begin();
369 for(; ipi!=m_PlatformList.end(); ipi++) ipi->Save(df);
370 fprintf(df, "\t\t\t\t}\n");
371 m_DiaInst.Save(df, "\t\t\t\t");
372 fprintf(df, "\t\t\t}\n");
373 }

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26