| 1 |
#include "stdafx.h" |
| 2 |
#include "CCamera.h" |
| 3 |
#include "CRailPlugin.h" |
| 4 |
#include "CTiePlugin.h" |
| 5 |
#include "CGirderPlugin.h" |
| 6 |
#include "CPierPlugin.h" |
| 7 |
#include "CLinePlugin.h" |
| 8 |
#include "CPolePlugin.h" |
| 9 |
#include "CStationPlugin.h" |
| 10 |
#include "CStation.h" |
| 11 |
#include "CRailLink.h" |
| 12 |
#include "CRailBuilder.h" |
| 13 |
#include "CLine.h" |
| 14 |
#include "CScene.h" |
| 15 |
#include "CSaveFile.h" |
| 16 |
#include "CRailBuildMode.h" |
| 17 |
#include "CStationSelectMode.h" |
| 18 |
#include "CConfigMode.h" |
| 19 |
|
| 20 |
// 外部グローバル |
| 21 |
extern bool g_EnableCant; |
| 22 |
|
| 23 |
// 内部グローバル |
| 24 |
CStationPlugin *g_Station = NULL; |
| 25 |
CDetectInfo g_StationPlatformParentDetectInfo; |
| 26 |
|
| 27 |
// static メンバ |
| 28 |
CRailPlugin *CPlatform::ms_PlatformRail = NULL; |
| 29 |
CTiePlugin *CPlatform::ms_PlatformTie = NULL; |
| 30 |
CGirderPlugin *CPlatform::ms_PlatformGirder = NULL; |
| 31 |
CPierPlugin *CPlatform::ms_PlatformPier = NULL; |
| 32 |
CLinePlugin *CPlatform::ms_PlatformLine = NULL; |
| 33 |
CPolePlugin *CPlatform::ms_PlatformPole = NULL; |
| 34 |
|
| 35 |
/* |
| 36 |
* [static] |
| 37 |
* プラットフォーム用プラグインをリセット |
| 38 |
*/ |
| 39 |
void CPlatform::ResetPlatformPlugin(){ |
| 40 |
CRailwayMode::GetPlugin(&ms_PlatformRail, &ms_PlatformTie, |
| 41 |
&ms_PlatformGirder, &ms_PlatformPier, &ms_PlatformLine, &ms_PlatformPole); |
| 42 |
} |
| 43 |
|
| 44 |
/* |
| 45 |
* コンストラクタ |
| 46 |
*/ |
| 47 |
CPlatform::CPlatform(){ |
| 48 |
m_TrackNum = 1; |
| 49 |
m_TrackInterval = 0.0f; |
| 50 |
m_RailPluginValid = m_TiePluginValid = m_GirderPluginValid = |
| 51 |
m_PierPluginValid = m_LinePluginValid = m_PolePluginValid = false; |
| 52 |
m_RailPlugin = NULL; |
| 53 |
m_TiePlugin = NULL; |
| 54 |
m_GirderPlugin = NULL; |
| 55 |
m_PierPlugin = NULL; |
| 56 |
m_LinePlugin = NULL; |
| 57 |
m_PolePlugin = NULL; |
| 58 |
m_Stoppable = true; |
| 59 |
m_OpenDoor[0] = m_OpenDoor[1] = false; |
| 60 |
m_LiftRailSurface = true; |
| 61 |
m_EnableCant = true; |
| 62 |
m_ParentObject = NULL; |
| 63 |
} |
| 64 |
|
| 65 |
/* |
| 66 |
* 読込 |
| 67 |
*/ |
| 68 |
char *CPlatform::Read( |
| 69 |
char *str // 対象文字列 |
| 70 |
){ |
| 71 |
char *tmp, *eee; |
| 72 |
string id; |
| 73 |
if(!(str = BeginBlock(eee = str, "Platform"))) return NULL; |
| 74 |
m_TrackNum = 1; |
| 75 |
m_TrackInterval = 0.0f; |
| 76 |
if(tmp = AsgnInteger(eee = str, "TrackNum", &m_TrackNum)) str = tmp; |
| 77 |
if(m_TrackNum<1){ |
| 78 |
throw CSynErr(eee, lang(InvalidTrackNum)); |
| 79 |
}else if(m_TrackNum>1){ |
| 80 |
if(!(str = AsgnFloat(eee = str, "TrackInterval", &m_TrackInterval))) throw CSynErr(eee); |
| 81 |
} |
| 82 |
if(tmp = AsgnYesNo(eee = str, "Stoppable", &m_Stoppable)) str = tmp; |
| 83 |
else m_Stoppable = true; |
| 84 |
if(tmp = AsgnYesNo(eee = str, "OpenDoor", m_OpenDoor, 2, false)) str = tmp; |
| 85 |
else m_OpenDoor[0] = m_OpenDoor[1] = false; |
| 86 |
bool *valid[6] = {&m_RailPluginValid, &m_TiePluginValid, &m_GirderPluginValid, |
| 87 |
&m_PierPluginValid, &m_LinePluginValid, &m_PolePluginValid}; |
| 88 |
CPlugin **adr[6] = { |
| 89 |
(CPlugin **)&m_RailPlugin, (CPlugin **)&m_TiePlugin, (CPlugin **)&m_GirderPlugin, |
| 90 |
(CPlugin **)&m_PierPlugin, (CPlugin **)&m_LinePlugin, (CPlugin **)&m_PolePlugin}; |
| 91 |
CPluginList *pilist[6] = {g_RailPluginList, g_TiePluginList, |
| 92 |
g_GirderPluginList, g_PierPluginList, g_LinePluginList, g_PolePluginList}; |
| 93 |
char *pitype[6] = { |
| 94 |
lang(Rail), lang(Tie), lang(Girder), lang(Pier), lang(Line), lang(Pole)}; |
| 95 |
int i; |
| 96 |
for(i = 0; i<6; i++){ |
| 97 |
if(tmp = AsgnString(eee = str, FlashIn("%sPlugin", pilist[i]->DirName()), &id)){ |
| 98 |
str = tmp; |
| 99 |
*valid[i] = true; |
| 100 |
if(id.size()){ |
| 101 |
if(!(*adr[i] = pilist[i]->FindPlugin(id.c_str()))) throw CSynErr( |
| 102 |
eee, "%s (%s): \"%s\"", lang(LackedPlugin), pitype[i], id.c_str()); |
| 103 |
}else{ |
| 104 |
*adr[i] = NULL; |
| 105 |
} |
| 106 |
}else{ |
| 107 |
*valid[i] = false; |
| 108 |
*adr = NULL; |
| 109 |
} |
| 110 |
} |
| 111 |
if(tmp = AsgnYesNo(eee = str, "LiftRailSurface", &m_LiftRailSurface)) str = tmp; |
| 112 |
else m_LiftRailSurface = true; |
| 113 |
if(tmp = AsgnYesNo(eee = str, "EnableCant", &m_EnableCant)) str = tmp; |
| 114 |
else m_EnableCant = true; |
| 115 |
if(tmp = AsgnString(eee = str, "ParentObject", &m_ParentObjectName)) str = tmp; |
| 116 |
m_ParentObjectScriptPos = eee; |
| 117 |
m_CoordList.clear(); |
| 118 |
VEC3 coord; |
| 119 |
while(tmp = AsgnVector3D(eee = str, "Coord", &coord)){ |
| 120 |
str = tmp; |
| 121 |
m_CoordList.push_back(coord); |
| 122 |
} |
| 123 |
if(m_CoordList.size()<2) throw CSynErr(eee, lang(TwoControlPointNeeded)); |
| 124 |
if(!(str = EndBlock(eee = str))) throw CSynErr(eee, ERR_ENDBLOCK); |
| 125 |
return str; |
| 126 |
} |
| 127 |
|
| 128 |
/* |
| 129 |
* プラットフォーム親オブジェクト設定 |
| 130 |
*/ |
| 131 |
void CPlatform::SetPlatformParent(CStationPlugin *spi){ |
| 132 |
if(!m_ParentObjectName.size()) return; |
| 133 |
CNamedObject *pobj = spi->FindObject(m_ParentObjectName); |
| 134 |
if(!pobj) throw CSynErr(m_ParentObjectScriptPos, "%s: \"%s\"", lang(UndefinedObject), m_ParentObjectName.c_str()); |
| 135 |
m_ParentObject = pobj; |
| 136 |
} |
| 137 |
|
| 138 |
/* |
| 139 |
* プラットフォーム用プラグインをセット |
| 140 |
*/ |
| 141 |
void CPlatform::SetPlatformPlugin(){ |
| 142 |
if(m_RailPluginValid) ms_PlatformRail = m_RailPlugin; |
| 143 |
if(m_TiePluginValid) ms_PlatformTie = m_TiePlugin; |
| 144 |
if(m_GirderPluginValid) ms_PlatformGirder = m_GirderPlugin; |
| 145 |
if(m_PierPluginValid) ms_PlatformPier = m_PierPlugin; |
| 146 |
if(m_LinePluginValid) ms_PlatformLine = m_LinePlugin; |
| 147 |
if(m_PolePluginValid) ms_PlatformPole = m_PolePlugin; |
| 148 |
} |
| 149 |
|
| 150 |
/* |
| 151 |
* ホームのプレビュー |
| 152 |
*/ |
| 153 |
CRailBuilder *CPlatform::SetBuilder( |
| 154 |
MTX4 *mtx // ローカル座標系 |
| 155 |
){ |
| 156 |
SetPlatformPlugin(); |
| 157 |
list<VEC3>::iterator iv = m_CoordList.begin(); |
| 158 |
|
| 159 |
CRailBuilder *builder = NULL, *prev = NULL; |
| 160 |
for(; iv!=m_CoordList.end(); iv++){ |
| 161 |
VEC3 p; |
| 162 |
if(m_ParentObject) p = *iv; |
| 163 |
else D3DXVec3TransformCoord(&p, &*iv, mtx); |
| 164 |
prev = new CRailBuilder(p, prev); |
| 165 |
if(!builder) builder = prev; |
| 166 |
} |
| 167 |
return builder; |
| 168 |
} |
| 169 |
|
| 170 |
/* |
| 171 |
* ホームのプレビュー |
| 172 |
*/ |
| 173 |
void CPlatform::Preview( |
| 174 |
MTX4 *mtx, // ローカル座標系 |
| 175 |
CLineDumpL *dump // ラインダンパ |
| 176 |
){ |
| 177 |
CRailBuilder *builder = SetBuilder(mtx); |
| 178 |
int i; |
| 179 |
CRailBuilder::ResetDirSum(); |
| 180 |
for(i = 0; i<m_TrackNum; i++){ |
| 181 |
CRailBuilder::SetTrack(i, m_TrackNum, m_TrackInterval, m_LiftRailSurface); |
| 182 |
builder->Render(dump, ms_PlatformRail, ms_PlatformTie, ms_PlatformGirder, false); |
| 183 |
} |
| 184 |
delete builder; |
| 185 |
} |
| 186 |
|
| 187 |
/* |
| 188 |
* ホームの設置 |
| 189 |
*/ |
| 190 |
void CPlatform::Build( |
| 191 |
MTX4 *mtx, // ローカル座標系 |
| 192 |
CStation *station // 親ステーション |
| 193 |
){ |
| 194 |
CRailBuilder *builder = SetBuilder(mtx); |
| 195 |
CRailBuilder::ResetDirSum(); |
| 196 |
g_LastPole.resize(m_TrackNum); |
| 197 |
g_FinishPole.resize(m_TrackNum); |
| 198 |
g_EnableCant = m_EnableCant; |
| 199 |
int i; |
| 200 |
for(i = 0; i<m_TrackNum; i++) g_LastPole[i] = g_FinishPole[i] = CPoleLink(); |
| 201 |
for(i = 0; i<=m_TrackNum; i++){ |
| 202 |
if(i==m_TrackNum){ |
| 203 |
if(!(ms_PlatformGirder && ms_PlatformGirder->IsMultiTrack()) |
| 204 |
&& !(ms_PlatformPier && ms_PlatformPier->IsMultiTrack()) |
| 205 |
&& !(ms_PlatformPole && ms_PlatformPole->IsMultiTrack())) break; |
| 206 |
g_MultiTrackDummy = true; |
| 207 |
g_DummyTrackNum = m_TrackNum; |
| 208 |
g_DummyTrackInterval = m_TrackInterval; |
| 209 |
} |
| 210 |
if(ms_PlatformRail) ms_PlatformRail->ResetMapTemp(); |
| 211 |
if(ms_PlatformTie) ms_PlatformTie->ResetMapTemp(); |
| 212 |
if(ms_PlatformGirder) ms_PlatformGirder->ResetMapTemp(); |
| 213 |
if(ms_PlatformPier) ms_PlatformPier->ResetPierPos(); |
| 214 |
if(ms_PlatformLine){ |
| 215 |
ms_PlatformLine->ResetMapTemp(); |
| 216 |
ms_PlatformLine->ResetPolePos(); |
| 217 |
} |
| 218 |
CRailBuilder::SetTrack(i, m_TrackNum, m_TrackInterval, m_LiftRailSurface); |
| 219 |
if(i<m_TrackNum) g_PlatformInst = |
| 220 |
station->PushPlatformInst(R2L(CPlatformInst(station, m_Stoppable, m_OpenDoor))); |
| 221 |
if(m_ParentObject){ |
| 222 |
CPartsInst *parts = station->FindParts(m_ParentObject); |
| 223 |
if(!parts) ErrorDialog("INTERNAL ERROR: PLATFORM PARENT PARTS NOT FOUND: %s", m_ParentObject->GetName()); |
| 224 |
g_StationPlatformParentDetectInfo = CDetectInfo(m_ParentObject, station, parts); |
| 225 |
} |
| 226 |
builder->BuildRail(R2L(CRailConnectorLink()), |
| 227 |
R2L(CRailConnectorLink()), ms_PlatformRail, ms_PlatformTie, ms_PlatformGirder); |
| 228 |
g_Scene->BuildLine(ms_PlatformPier, ms_PlatformLine, ms_PlatformPole); |
| 229 |
if(m_ParentObject) g_StationPlatformParentDetectInfo = CDetectInfo(); |
| 230 |
g_PlatformInst = NULL; |
| 231 |
g_MultiTrackDummy = false; |
| 232 |
} |
| 233 |
station->MakePlatformArray(); |
| 234 |
delete builder; |
| 235 |
} |
| 236 |
|
| 237 |
//////////////////////////////////////////////////////////////////////////////// |
| 238 |
//////////////////////////////////////////////////////////////////////////////// |
| 239 |
|
| 240 |
/* |
| 241 |
* [static] |
| 242 |
* プレビュー |
| 243 |
*/ |
| 244 |
void CStationPlugin::RenderPreview( |
| 245 |
VEC3 pos, // 位置 |
| 246 |
VEC3 dir, // dir |
| 247 |
VEC3 up // up |
| 248 |
){ |
| 249 |
CNamedObjectAfterRenderer::SetCurrentInst(NULL); |
| 250 |
g_SaveFile->ResetSwitch(); |
| 251 |
if(ms_PreviewState && g_Station){ |
| 252 |
g_SystemObject[SYS_OBJ_LOCAL].SetPreviewPosture(pos, dir, up); |
| 253 |
SetCamDistSwitch(pos); |
| 254 |
g_Station->Preview(); |
| 255 |
} |
| 256 |
} |
| 257 |
|
| 258 |
/* |
| 259 |
* デストラクタ |
| 260 |
*/ |
| 261 |
CStationPlugin::~CStationPlugin(){ |
| 262 |
} |
| 263 |
|
| 264 |
/* |
| 265 |
* ロード |
| 266 |
*/ |
| 267 |
char *CStationPlugin::LoadStructBefore( |
| 268 |
char *str // 対象文字列 |
| 269 |
){ |
| 270 |
char *tmp, *eee; |
| 271 |
if(!(str = BeginBlock(eee = str, "StationInfo"))) throw CSynErr(eee); |
| 272 |
if(!(str = EndBlock(eee = str))) throw CSynErr(eee, ERR_ENDBLOCK); |
| 273 |
CPlatform platform; |
| 274 |
while(tmp = platform.Read(str)){ |
| 275 |
str = tmp; |
| 276 |
m_Platform.push_back(platform); |
| 277 |
} |
| 278 |
ChDir(); |
| 279 |
return str; |
| 280 |
} |
| 281 |
|
| 282 |
/* |
| 283 |
* ロード |
| 284 |
*/ |
| 285 |
char *CStationPlugin::LoadStructAfter( |
| 286 |
char *str // 対象文字列 |
| 287 |
){ |
| 288 |
IPlatform ip = m_Platform.begin(); |
| 289 |
for(; ip!=m_Platform.end(); ip++) ip->SetPlatformParent(this); |
| 290 |
return str; |
| 291 |
} |
| 292 |
|
| 293 |
/* |
| 294 |
* ロード |
| 295 |
*/ |
| 296 |
bool CStationPlugin::LoadOldForm(){ |
| 297 |
if(!ChDir()) return false; |
| 298 |
g_NamedObjectMipMap = g_StructMipMap; |
| 299 |
CNamedObject::SetCastShadowDefault(true); |
| 300 |
FILE *file = fopen(TextName(), "rt"); |
| 301 |
char *dummy = FlashOut(); |
| 302 |
float sc; |
| 303 |
int i, platforms = 0; |
| 304 |
bool needpush = true; |
| 305 |
fscanf(file, "%s %s %f %d", dummy, dummy, &sc, &platforms); |
| 306 |
float oldscale = 2.0f/sc; |
| 307 |
for(i = 0; i<platforms; i++){ |
| 308 |
VEC3 v1, v2; |
| 309 |
if(fscanf(file, "\n(%f,%f,%f),(%f,%f,%f)", &v1.x, &v1.y, &v1.z, &v2.x, &v2.y, &v2.z)<6) |
| 310 |
ErrorDialog("Station <%s>\n%s", m_ID.c_str(), lang(PlatformReadError)); |
| 311 |
v1 = oldscale*VEC3(-v1.x, v1.y, -v1.z); |
| 312 |
v2 = oldscale*VEC3(-v2.x, v2.y, -v2.z); |
| 313 |
if(needpush) m_Platform.push_back(CPlatform()); |
| 314 |
if(v1==v2){ |
| 315 |
(--m_Platform.end())->PushCoord(v1); |
| 316 |
needpush = false; |
| 317 |
}else{ |
| 318 |
(--m_Platform.end())->PushCoord(v1); |
| 319 |
(--m_Platform.end())->PushCoord(v2); |
| 320 |
needpush = true; |
| 321 |
} |
| 322 |
} |
| 323 |
IPlatform ip = m_Platform.begin(); |
| 324 |
for(; ip!=m_Platform.end(); ip++) if(ip->GetCoordNum()<2) |
| 325 |
ErrorDialog("Station <%s>\n%s", m_ID.c_str(), lang(TwoControlPointNeeded)); |
| 326 |
fclose(file); |
| 327 |
m_FreeObject.push_back(CFreeObjectContainer(new CFreeObject3D("MainObject", "Model.x", oldscale))); |
| 328 |
m_FreeObject.begin()->LoadModel(this); |
| 329 |
m_PartsNum = 1; |
| 330 |
return true; |
| 331 |
} |
| 332 |
|
| 333 |
/* |
| 334 |
* プレビュー設定 |
| 335 |
*/ |
| 336 |
void CStationPlugin::SetPreview(){ |
| 337 |
ms_PreviewState = true; |
| 338 |
g_Station = this; |
| 339 |
string desc = g_Station->GetBasicInfo(); |
| 340 |
desc += FlashIn("\n%s: %d", lang(PlatformNum), m_Platform.size()); |
| 341 |
desc += "\n"+g_Station->GetDescription(); |
| 342 |
g_StationSelectMode->SetProperty((char *)desc.c_str()); |
| 343 |
} |
| 344 |
|
| 345 |
/* |
| 346 |
* プレビュー |
| 347 |
*/ |
| 348 |
void CStationPlugin::PreviewStruct(){ |
| 349 |
devSetZRead(FALSE); |
| 350 |
devSetZWrite(FALSE); |
| 351 |
devResetMaterial(); |
| 352 |
devResetMatrix(); |
| 353 |
devSetLighting(FALSE); |
| 354 |
devTEX_POINT(0); |
| 355 |
devTEX_POINT(1); |
| 356 |
CLineDumpL dump(256); |
| 357 |
MTX4 mtx = g_SystemObject[SYS_OBJ_LOCAL].GetPreviewObject()->GetMatrix(); |
| 358 |
CPlatform::ResetPlatformPlugin(); |
| 359 |
IPlatform ip = m_Platform.begin(); |
| 360 |
for(; ip!=m_Platform.end(); ip++) ip->Preview(&mtx, &dump); |
| 361 |
dump.Render(true); |
| 362 |
devSetZRead(TRUE); |
| 363 |
devSetZWrite(TRUE); |
| 364 |
devSetLighting(TRUE); |
| 365 |
g_ConfigMode->SetTexFilter(); |
| 366 |
} |
| 367 |
|
| 368 |
/* |
| 369 |
* プラットフォーム建設 |
| 370 |
*/ |
| 371 |
void CStationPlugin::BuildPlatform( |
| 372 |
CStation *station // 駅 |
| 373 |
){ |
| 374 |
MTX4 mtx = g_SystemObject[SYS_OBJ_LOCAL].GetPreviewObject()->GetMatrix(); |
| 375 |
CPlatform::ResetPlatformPlugin(); |
| 376 |
IPlatform ip = m_Platform.begin(); |
| 377 |
for(; ip!=m_Platform.end(); ip++) ip->Build(&mtx, station); |
| 378 |
g_Scene->Dump(); |
| 379 |
} |