From c0c336500955a23e344651e5412c9d9d441ef4ee Mon Sep 17 00:00:00 2001 From: Ash Wolf Date: Wed, 28 Jun 2023 22:22:32 +0100 Subject: first pass of T2DLL --- src/T2DLL/T2People.cpp | 1500 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 1372 insertions(+), 128 deletions(-) (limited to 'src/T2DLL/T2People.cpp') diff --git a/src/T2DLL/T2People.cpp b/src/T2DLL/T2People.cpp index c434626..a238b1c 100644 --- a/src/T2DLL/T2People.cpp +++ b/src/T2DLL/T2People.cpp @@ -1,235 +1,1479 @@ +#include "GlobalFunc.h" +#include "T2Archive.h" +#include "T2BitImage.h" +#include "T2DateTime.h" +#include "T2FloorInfo.h" +#include "T2ImageObj.h" +#include "T2Mover.h" +#include "T2Name.h" +#include "T2NameList.h" #include "T2People.h" +#include "T2PeopleArrayList.h" +#include "T2PeopleDef.h" +#include "T2PeopleInfoDialog.h" +#include "T2PeopleType.h" +#include "T2Pool.h" +#include "T2RegistedTenantDB.h" +#include "T2Request.h" +#include "T2ReturnStack.h" +#include "T2RouteNavigator.h" +#include "T2SilhouetteDef.h" +#include "T2TemplatePluginList.h" +#include "T2Tenant.h" +#include "T2TenantDef.h" +#include "T2TrafficInfo.h" +#include "T2Transport.h" +#include "T2TowerDoc.h" +#include "T2TowerEvent.h" +#include "T2TowerMainView.h" +#include "T2TowerMessage.h" +#include "T2WordDefArray.h" +#include "T2WorldDef.h" +#include "UT2Coordinate.h" + +static T2People *someGlobalPeople; // 100e3e4c T2People::T2People() { + Initialize(); + mPeopleType = new T2PeopleType; } void T2People::Initialize() { + mSpecialFlag = 0; + mWalk = false; + mAttribute = 0; + mStress = 0; + m80 = 0; + mEstimate = 0; + mStatus = kStatus0; + mColor = 1; + mFiller = 0; + mPrevTenantType = 0; + mPeopleType = NULL; + mStyle = kPeopleStyle0; + for (unsigned int i = 0; i < 3; i++) + mSilhouetteDef[i] = NULL; } /*virtual*/ T2People::~T2People() { -} - -/*virtual*/ void T2People::SetUsed(int) { -} - -void T2People::Initialize(T2PeopleDef*, T2PeopleType*) { -} - -int T2People::IsMale() const { -} - -int T2People::IsGeneral() const { -} - -int T2People::IsSpecialColor() const { -} - -void T2People::ChangeStyle(int) { + if (mPeopleType) + delete mPeopleType; +} + +/*virtual*/ void T2People::SetUsed(BOOL used) { + if (!used) { + if (IsFavorite()) { + GetCurrentT2TowerDoc()->towerDoc_vf1C4(this, true); + } else if (IsNamed()) { + T2NameList *nameDB = GetCurrentT2TowerDoc()->mNameDB; + T2Name *name = nameDB->Search(this, false); + if (name) { + nameDB->RemoveName(name); + delete name; + } + } + } + + T2Matter::SetUsed(used); +} + +void T2People::Initialize(T2PeopleDef* peopleDef, T2PeopleType* peopleType) { + T2Matter::Initialize(peopleDef); + mSpecialFlag = 0; + mAttribute = peopleDef->GetAttribute(); + mStress = 0; + m80 = 0; + mEstimate = 300; + mStatus = kStatus0; + mColor = 1; + mFiller = 0; + mPrevTenantType = 0; + *mPeopleType = *peopleType; + mStyle = kPeopleStyle0; + SetSilhouetteDef(kPeopleStyle0, peopleDef->GetSilhouetteDef()); + SetSilhouetteDef(kPeopleStyle1, NULL); + SetSilhouetteDef(kPeopleStyle2, NULL); +} + +BOOL T2People::IsMale() const { + BOOL result = true; + if (mPeopleType) + result = mPeopleType->IsMale(); + return result; +} + +BOOL T2People::IsGeneral() const { + return ( + (mHomeTenant == 1 || mHomeTenant == 2) && + (mWorkTenant == 1 || mWorkTenant == 2) + ); +} + +BOOL T2People::IsSpecialColor() const { + return (mColor >= 11); +} + +void T2People::ChangeStyle(int style) { + if (style != mStyle && style >= kPeopleStyle0 && style <= kMaxPeopleStyle) { + mStyle = style; + ChangeSilhouette(); + } } int T2People::GetWidth() const { -} + int result = 1; + T2SilhouetteDef *silhouetteDef = mSilhouetteDef[mStyle]; -int T2People::GetRouteType() { -} - -int T2People::CalcWaitPersonArea(T2FloorInfo*, RECT&) { -} + if (silhouetteDef) + result = silhouetteDef->GetWidth(); -void T2People::CalcWalkingSilhouetteArea(RECT&) const { + return result; } -unsigned int T2People::GetCurTenantID() const { -} +int T2People::GetRouteType() { + int result = kRouteType0; + T2SilhouetteDef *silhouetteDef = mSilhouetteDef[mStyle]; -/*virtual*/ unsigned int T2People::Idle(T2TowerDoc*) { -} + if (!IsSetSpecialFlag(kSpecialFlag80)) { + T2SilhouetteDef *silhouetteDef = mSilhouetteDef[mStyle]; + if (silhouetteDef) + result = silhouetteDef->GetRouteType(); + } else { + result = kRouteTypeNeg1; + } -void T2People::IdleWaitMover(T2TowerDoc*) { + return result; } -void T2People::MoveToTowerEntrance(T2TowerDoc*) { -} +BOOL T2People::CalcWaitPersonArea(T2FloorInfo* floorInfo, RECT& rect) { + BOOL result = false; -void T2People::MoveToLobby(T2TowerDoc*) { -} + T2Request *request = floorInfo->GetRequest(mCurrEquipID); + if (request) + result = request->CalcPersonArea(this, rect); -int T2People::MoveToParking(T2TowerDoc*) { + return result; } -int T2People::MoveToSubway(T2TowerDoc*) { -} +void T2People::CalcWalkingSilhouetteArea(RECT& rect) const { + POINT curPosition = GetCurPosition(); + rect.top = curPosition.y; + rect.left = curPosition.x; + rect.bottom = curPosition.y + 1; + rect.right = curPosition.x + 2; -int T2People::MoveToShip(T2TowerDoc*) { + if (mWalkStyle == 0 && GetWidth() < 2) { + if (mDirection == 0) + rect.left++; + else + rect.right--; + } } -void T2People::MoveByEStair(T2TowerDoc*) { -} +unsigned int T2People::GetCurTenantID() const { + unsigned int tenantID = 0; + + if (mStatus == kStatus11) + tenantID = mCurrEquipID; + + return tenantID; +} + +/*virtual*/ unsigned int T2People::Idle(T2TowerDoc* towerDoc) { + unsigned int result = 0; + + switch (mStatus) { + case kStatus1: + if (IsStartTime(towerDoc->towerDoc_vf120()->GetRawMinutes()) && IsSetDestination()) { + towerDoc->towerDoc_vf130()->Leave(this); + MoveToTowerEntrance(towerDoc); + if (towerDoc->towerDoc_vf154()) + SetSpecialFlag(kSpecialFlag2); + } + break; + + case kStatus11: + if (IsStartTime(towerDoc->towerDoc_vf120()->GetRawMinutes())) { + T2FloorInfo *floorInfo = towerDoc->towerDoc_vf12C(); + T2Tenant *tenant = floorInfo->GetTenant(mCurrEquipID); + if (tenant) { + if (IsSetDestination()) + tenant->LeaveTenant(towerDoc, this); + else + tenant->PushOutPeople(towerDoc, this); + } + } + break; + + case kStatus2: + case kStatus3: + case kStatus4: + SolveNoRoute(towerDoc); + break; + + case kStatus6: + IdleWaitMover(towerDoc); + break; + + case kStatus5: + { + int what; + if (someGlobalPeople == this) + what = 1; + + if (!IsWalk()) { + if (IsReachDestination(towerDoc->towerDoc_vf12C()->GetGroundLine() - 1)) { + if (!IsRegistRequest(towerDoc)) + ChangeStatus(kStatus3); + } + } + + break; + } + + case kStatus10: + if (!IsWalk()) { + if (IsReachDestination(towerDoc->towerDoc_vf12C()->GetGroundLine() - 1)) { + T2FloorInfo *floorInfo = towerDoc->towerDoc_vf12C(); + T2Tenant *tenant = floorInfo->GetTenant(mDstTenant); + if (tenant) + tenant->EnterTenant(towerDoc, this); + } + } + break; + + case kStatus12: + if (!IsWalk()) { + if (IsReachDestination(towerDoc->towerDoc_vf12C()->GetGroundLine() - 1)) + GoOutTower(towerDoc); + } + break; + + case kStatus13: + if (!IsWalk()) { + if (IsReachDestination(towerDoc->towerDoc_vf12C()->GetGroundLine() - 1)) + MoveByEStair(towerDoc); + } + break; + + case kStatus14: + if (!IsWalk()) { + if (IsReachDestination(towerDoc->towerDoc_vf12C()->GetGroundLine() - 1)) + ChangeStatus(kStatus15); + } + break; + } + + return result; +} + +void T2People::IdleWaitMover(T2TowerDoc* towerDoc) { + T2FloorInfo *floorInfo = towerDoc->towerDoc_vf12C(); + BOOL changed = IncStress(5); + + if (mStress >= 300) { + T2Request *request = floorInfo->GetRequest(mCurrEquipID); + request->Leave(this); + JumpToDestination(towerDoc); + IncEstimate(-50); + changed = false; + } + + if (changed) { + RECT rect; + CalcWaitPersonArea(floorInfo, rect); + towerDoc->GetTowerMainView()->tmv_vf128(rect, false); + } +} + +void T2People::MoveToTowerEntrance(T2TowerDoc* towerDoc) { + BOOL success = true; + + switch (mPeopleType->GetTransportType()) { + case kTransportLobbyLeft: + case kTransportLobbyRight: + MoveToLobby(towerDoc); + break; + case kTransportParking: + success = MoveToParking(towerDoc); + break; + case kTransportSubway: + success = MoveToSubway(towerDoc); + break; + case kTransportShip: + success = MoveToShip(towerDoc); + break; + } + + if (!success) { + IncEstimate(-100); + MoveToLobby(towerDoc); + } +} + +void T2People::MoveToLobby(T2TowerDoc* towerDoc) { + T2FloorInfo *floorInfo = towerDoc->towerDoc_vf12C(); + T2Tenant *lobby = floorInfo->GetTenant(1000); + + if (lobby) { + lobby->Enter(this); + + RECT rect; + lobby->GetEquipArea(rect); + mCurPosition.y = rect.bottom - 1; + + if (mPeopleType->GetTransportType() == kTransportLobbyLeft) { + mCurPosition.x = rect.left; + mDirection = 0; + } else { + mCurPosition.x = rect.right - 2; + mDirection = 1; + } + + ChangeStatus(kStatus2); + } +} + +BOOL T2People::MoveToParking(T2TowerDoc* towerDoc) { + BOOL result = false; + + T2RegistedTenantDB *registedTenantDB = towerDoc->towerDoc_vf174(); + if (registedTenantDB) { + T2Tenant *parking = NULL; + if (!IsGeneral()) + parking = registedTenantDB->FindHisParking(this); + if (!parking) + parking = registedTenantDB->FindEmptyParking(); + + if (parking) { + SetDestinationToReturn(); + parking->EnterTenant(towerDoc, this); + result = true; + } + } + + return result; +} + +BOOL T2People::MoveToSubway(T2TowerDoc* towerDoc) { + // TODO: T2MetroRailway + return 0; +} + +BOOL T2People::MoveToShip(T2TowerDoc* towerDoc) { + BOOL result = false; + + T2TowerEvent *towerEvent = towerDoc->mWorldDef->GetTowerEvent(); + T2DateTime *now = towerDoc->towerDoc_vf120(); + T2Transport *transport = towerEvent->GetCruise(); + if (transport) { + T2Transport *available = transport->GetAvailable(now); + if (available) { + available->Enter(this); + result = true; + } + } + + return result; +} + +void T2People::MoveByEStair(T2TowerDoc* towerDoc) { + T2FloorInfo *floorInfo = towerDoc->towerDoc_vf12C(); + + if (floorInfo) { + T2Tenant *curTenant = floorInfo->GetTenant(mCurrEquipID); + T2Tenant *dstFloor = floorInfo->GetFloor(mCurrDestPos.y, mCurrDestPos.x); + + if (curTenant && dstFloor) { + RECT dstRect; + dstFloor->GetEquipArea(dstRect); + + if (mCurrDestPos.x == dstRect.left) + mDirection = 0; + else if (mCurrDestPos.x == (dstRect.right - 2)) + mDirection = 1; + + curTenant->Leave(this); + dstFloor->Enter(this); + } else { + ChangeStatus(kStatus3); + } + + if (IsWalk()) { + T2TowerMainView *towerMainView = towerDoc->GetTowerMainView(); + if (towerMainView) { + RECT rect; + SetRect(&rect, mCurPosition.x, mCurPosition.y, mCurPosition.x + 2, mCurPosition.y + 1); + towerMainView->tmv_vf128(rect, false); + } + } + } +} + +void T2People::SolveNoRoute(T2TowerDoc* towerDoc) { + BOOL changed = false; + + int what; + if (someGlobalPeople == this) + what = 0; + + if (!FindRoute(towerDoc)) { + changed = IncStress(30) && IsWalk(); + if (mStress >= 300) { + T2FloorInfo *floorInfo = towerDoc->towerDoc_vf12C(); + if (IsWalk()) { + // "道がないよ~" - there is no way + CString msg = "\x93\xB9\x82\xAA\x82\xC8\x82\xA2\x82\xE6\x81\x60"; + towerDoc->towerDoc_vf13C()->PeopleBalloonMessage(msg, this); + + RECT rect; + CalcWalkingSilhouetteArea(rect); + floorInfo->SetTenantDrawModeByRect(rect, DrawMode1); + towerDoc->GetTowerMainView()->tmv_vf128(rect, false); + } + + T2Tenant *tenant = floorInfo->GetTenant(mCurrEquipID); + tenant->Leave(this); + JumpToDestination(towerDoc); + IncEstimate(-150); + } + } + + if (changed) { + RECT rect; + CalcWalkingSilhouetteArea(rect); + towerDoc->GetTowerMainView()->tmv_vf128(rect, false); + } +} + +BOOL T2People::FindRoute(T2TowerDoc* towerDoc) { + BOOL result = false; + int status = mStatus; + T2FloorInfo *floorInfo = towerDoc->towerDoc_vf12C(); + + if (floorInfo) { + mCurrDestPos = floorInfo->GetEntrancePt(mDstTenant); + if (mCurPosition.y >= 0) { + if (mCurrEquipID == floorInfo->GetEntranceFloorID(mDstTenant)) { + if (mDstTenant == 1 || mDstTenant == 2) + status = kStatus12; + else if (!IsSetSpecialFlag(kSpecialFlag40)) + status = kStatus10; + else + status = kStatus14; + result = true; + } else { + int routeType = GetRouteType(); + if (towerDoc->towerDoc_vf124()->GetNextRoute(mCurPosition, mCurrDestPos, routeType)) { + if (routeType >= kRouteType0) + status = kStatus5; + else + status = kStatus13; + result = true; + } + } + } + } + + if (result) { + if (mCurPosition.x < mCurrDestPos.x) + mDirection = 0; + else + mDirection = 1; + + ChangeStatus(status); + + T2TrafficInfo *trafficInfo = towerDoc->towerDoc_vf150(); + if (trafficInfo) + trafficInfo->Pass(mCurPosition, mCurrDestPos, 1); + } + + return result; +} + +void T2People::JumpToDestination(T2TowerDoc* towerDoc) { + T2FloorInfo *floorInfo = towerDoc->towerDoc_vf12C(); + POINT entrancePt = floorInfo->GetEntrancePt(mDstTenant); + + mCurPosition = entrancePt; + T2Tenant *tenant = floorInfo->GetFloor(mCurPosition.y, mCurPosition.x); + tenant->Enter(this); +} + +void T2People::GoOutTower(T2TowerDoc* towerDoc) { + T2Tenant *tenant = towerDoc->towerDoc_vf12C()->GetTenant(mCurrEquipID); + if (tenant) + tenant->Leave(this); + + T2Pool *pool = towerDoc->towerDoc_vf130(); + pool->Enter(this); +} + +void T2People::IdleSearchedPerson(T2TowerDoc* towerDoc) { + BOOL flag = false; + int varC; + + if (someGlobalPeople == this) + varC = 2; + + switch (mStatus) { + case kStatus5: + case kStatus10: + case kStatus12: + case kStatus13: + case kStatus14: + if (mDirection != 1) + flag = WalkSearchedPersonRight(towerDoc); + else + flag = WalkSearchedPersonLeft(towerDoc); + break; + + case kStatus2: + { + T2TowerMainView *mainView = towerDoc->GetTowerMainView(); + RECT rect; + CalcWalkingSilhouetteArea(rect); + mainView->tmv_vf128(rect, false); + mStatus = kStatus3; + break; + } + } + + if (flag) { + switch (mStatus) { + case kStatus5: + if (!IsRegistRequest(towerDoc)) + ChangeStatus(kStatus4); + break; + + case kStatus10: + { + T2FloorInfo *floorInfo = towerDoc->towerDoc_vf12C(); + T2Tenant *tenant = floorInfo->GetTenant(mDstTenant); + if (tenant) + tenant->EnterTenant(towerDoc, this); + else + ChangeStatus(kStatus4); + break; + } + + case kStatus12: + GoOutTower(towerDoc); + break; + + case kStatus13: + MoveByEStair(towerDoc); + break; + + case kStatus14: + ChangeStatus(kStatus15); + break; + } + } +} + +BOOL T2People::WalkSearchedPersonRight(T2TowerDoc* towerDoc) { + BOOL result = false; + T2FloorInfo *floorInfo = towerDoc->mFloorInfo; + T2TowerMainView *towerMainView = towerDoc->GetTowerMainView(); + + RECT rect; + SetRect(&rect, mCurPosition.x, mCurPosition.y, mCurPosition.x + 2, mCurPosition.y + 1); + floorInfo->SetTenantDrawModeByRect(rect, DrawMode1); + towerMainView->tmv_vf128(rect, false); + + int var = 2; + + if ((mCurPosition.x + var) > mCurrDestPos.x) { + if (mWalkStyle != 1) + ChangeWalkStyle(1); + else + ChangeWalkStyle(0); + } else { + var = mCurrDestPos.x - mCurPosition.x; + ChangeWalkStyle(0); + result = true; + } + + mCurPosition.x += var; + OffsetRect(&rect, var, 0); + towerMainView->tmv_vf128(rect, false); + + if (mCurPosition.y != (floorInfo->GetGroundLine() - 1)) + IncStress(var / 4); + + return result; +} + +BOOL T2People::WalkSearchedPersonLeft(T2TowerDoc* towerDoc) { + BOOL result = false; + T2FloorInfo *floorInfo = towerDoc->towerDoc_vf12C(); + T2TowerMainView *towerMainView = towerDoc->GetTowerMainView(); + + RECT rect; + SetRect(&rect, mCurPosition.x, mCurPosition.y, mCurPosition.x + 2, mCurPosition.y + 1); + floorInfo->SetTenantDrawModeByRect(rect, DrawMode1); + towerMainView->tmv_vf128(rect, false); + + int var = 2; + + if ((mCurPosition.x - var) > mCurrDestPos.x) { + if (mWalkStyle != 1) + ChangeWalkStyle(1); + else + ChangeWalkStyle(0); + } else { + var = mCurPosition.x - mCurrDestPos.x; + ChangeWalkStyle(0); + result = true; + } + +#line 809 + _ASSERT(var >= 0); + + mCurPosition.x -= var; + OffsetRect(&rect, -var, 0); + towerMainView->tmv_vf128(rect, false); + + if (mCurPosition.y != (floorInfo->GetGroundLine() - 1)) + IncStress(var / 4); + + return result; +} + +BOOL T2People::IsReachDestination(int y) { + BOOL result = false; + int var = 16; -void T2People::SolveNoRoute(T2TowerDoc*) { -} + if (mDirection != 1) { + if ((mCurPosition.x + var) >= mCurrDestPos.x) { + var = mCurrDestPos.x - mCurPosition.x; + result = true; + } + mCurPosition.x += var; + } else { + if ((mCurPosition.x - var) <= mCurrDestPos.x) { + var = mCurPosition.x - mCurrDestPos.x; + result = true; + } + mCurPosition.x -= var; + } -int T2People::FindRoute(T2TowerDoc*) { -} + if (mCurPosition.y != y) + IncStress(var / 4); -void T2People::JumpToDestination(T2TowerDoc*) { + return result; } -void T2People::GoOutTower(T2TowerDoc*) { -} +BOOL T2People::IsRegistRequest(T2TowerDoc* towerDoc) { + BOOL result = false; -void T2People::IdleSearchedPerson(T2TowerDoc*) { -} + T2FloorInfo *floorInfo = towerDoc->mFloorInfo; + T2Request *request = floorInfo->GetRequest(mCurPosition.y, mCurPosition.x); + if (request) + result = request->Regist(towerDoc, this); -int T2People::WalkSearchedPersonRight(T2TowerDoc*) { + return result; } -int T2People::WalkSearchedPersonLeft(T2TowerDoc*) { +void T2People::ChangeStatus(int status) { + SetStatus(status); + ChangeSilhouette(); } -int T2People::IsReachDestination(int) { -} +void T2People::ChangeSilhouette() { + switch (mStatus) { + case kStatus7: + mWalkStyle = 1; + break; + case kStatus9: + mWalkStyle = 2; + break; + default: + mWalkStyle = 0; + } -int T2People::IsRegistRequest(T2TowerDoc*) { + SetSilhouette(); } -void T2People::ChangeStatus(int) { -} +void T2People::SetSilhouette() { + T2SilhouetteDef *silhouetteDef = mSilhouetteDef[mStyle]; -void T2People::ChangeSilhouette() { + if (silhouetteDef) { + m18 = silhouetteDef->GetSilhouette((mDirection != -1) ? mDirection : 0, mWalkStyle); + } else { + m18 = 0; + } } -void T2People::SetSilhouette() { +void T2People::ChangeWalkStyle(int style) { + mWalkStyle = style; + SetSilhouette(); } -void T2People::ChangeWalkStyle(int) { -} +void T2People::SetAnimePattern(int fillerStart, int fillerRange, int hStart, int hRange) { + if (fillerRange > 1) + mFiller = fillerStart + rand() % fillerRange; + else + mFiller = fillerStart; -void T2People::SetAnimePattern(int, int, int, int) { + if (hRange > 1) + mCurPosition.x = hStart + rand() % hRange; + else + mCurPosition.x = hStart; } -int T2People::StopOnHisWay(T2TenantMemberDef*, int, int, RECT, int, int, int, int) { -} +BOOL T2People::StopOnHisWay(T2TenantMemberDef* tenantMemberDef, int econoType, int score, RECT rect, int bindTime, int tenantType, int tenantID, int startTime) { + BOOL result = false; + BOOL negScoreFlag = false; -int T2People::CalledInTenant(T2TenantMemberDef*, int, int, int, unsigned int, unsigned int) { -} + if (score < 0) { + score *= -1; + negScoreFlag = true; + } -int T2People::CalcFreeTime(unsigned int) { -} + if (mCurPosition.x > (rect.left - score) && mCurPosition.x < (rect.right + score)) { + if (negScoreFlag || CalcFreeTime(startTime) > bindTime) { + if (mPrevTenantType != tenantType) { + if (mPeopleType->CheckWithDemand(tenantMemberDef, econoType)) { + if (SetDestinationToReturn()) { + SetDestination(tenantID, startTime); + ChangeStatus(kStatus3); + result = true; + } + } + } + } + } -int T2People::IsGoToPool() const { + return result; } -void T2People::Return() { -} +BOOL T2People::CalledInTenant(T2TenantMemberDef* tenantMemberDef, int econoType, int bindTime, int tenantType, unsigned int tenantID, unsigned int startTime) { + BOOL result = false; -void T2People::SetDestinationToOutOfTower(T2TowerDoc*) { -} + if (CalcFreeTime(startTime) > bindTime && mPrevTenantType != tenantType) { +#line 992 + _ASSERT(mPeopleType); -void T2People::ChangeDestination(unsigned int, unsigned int) { -} + if (mPeopleType->CheckWithDemand(tenantMemberDef, econoType)) { + SetDestination(tenantID, startTime); + result = true; + } + } -int T2People::CalcCurrEstimate() const { + return result; } -void T2People::IncEstimate(int) { -} +int T2People::CalcFreeTime(unsigned int time) { + int result = 0; -void T2People::UpdateEstimation() { -} + if (IsSetDestination()) { + if (mStartTime > (int) time) + result = mStartTime - time; + } else if (IsSetReturn()) { + if (GetReturnTime() > time) + result = GetReturnTime() - time; + } else { + result = 10000; + } -int T2People::GetAverageStress() const { + return result; } -int T2People::IncStress(int) { +BOOL T2People::IsGoToPool() const { + return mDstTenant <= 2 && mDstTenant >= 1; } -int T2People::StressChanged() { -} +void T2People::Return() { + if (!SetReturnToDestination()) + SetDestination(mHomeTenant); -int T2People::IsVIP() const { + if (mStatus == kStatus10) + ChangeStatus(kStatus3); } -int T2People::IsNamed() const { -} +void T2People::SetDestinationToOutOfTower(T2TowerDoc* towerDoc) { + unsigned int tenantID = 1; -void T2People::SetColor(int) { -} + switch (mPeopleType->GetTransportType()) { + case kTransportParking: + { + T2RegistedTenantDB *registedTenantDB = towerDoc->towerDoc_vf174(); + if (registedTenantDB) { + T2Tenant *parking = NULL; + if (!IsGeneral()) { + parking = registedTenantDB->FindHisParking(this); + if (parking) + tenantID = parking->GetEquipID(); + } + } + } + } -void T2People::ClearColor() { + SetDestination(tenantID); } -/*virtual*/ void T2People::SetFavorite(int) { -} +void T2People::ChangeDestination(unsigned int tenant, unsigned int startTime) { + if (mStatus == kStatus10 || mStatus == kStatus12) + ChangeStatus(kStatus3); -int T2People::VIPEstimation() { + SetDestination(tenant, startTime); } -int T2People::SearchToilet(T2TowerDoc*) { -} +int T2People::CalcCurrEstimate() const { + int result; -void T2People::DrawSearchedPerson(T2TowerDoc*) { -} + if (m80 > 0) { + if (mStatus != kStatus11 && mStatus != kStatus1) { + result = (mEstimate * m80 + (300 - mStress)) / (m80 + 1); + } else { + result = (mEstimate * m80 - mStress) / m80; + } + } else { + result = mEstimate - mStress; + } -/*virtual*/ void T2People::Draw(T2TowerDoc*, const RECT&) { -} + if (result < 1) + result = 1; -void T2People::Draw(T2BitImage*, const RECT&) { + return result; } -void T2People::Draw(T2TowerDoc*, T2Equip*) { -} +void T2People::IncEstimate(int value) { + mEstimate += value; -void T2People::DrawAt(T2TowerDoc*, T2Equip*, POINT) { + if (mEstimate < 1) + mEstimate = 1; + else if (mEstimate > 300) + mEstimate = 300; } -void T2People::Duplicate(T2TowerDoc*) { -} +void T2People::UpdateEstimation() { + mEstimate = CalcCurrEstimate(); + mStress = 0; -void T2People::Remove(T2TowerDoc*, unsigned int) { -} + if (mStatus != kStatus11 && m80 < 4) + m80++; -void T2People::TenantRemoved(unsigned int) { + StressChanged(); } -void T2People::Interview(T2TowerDoc*) { +int T2People::GetAverageStress() const { + return 300 - CalcCurrEstimate(); } -int T2People::GetInterviewWords(T2TowerDoc*, CString&) { -} +BOOL T2People::IncStress(int value) { + mStress += value; -int T2People::IsMaru() const { -} + if (mStress > 300) + mStress = 300; + else if (mStress < 0) + mStress = 0; -int T2People::IsReggae() const { + return StressChanged(); } -void T2People::BreakoutEmergency(T2TowerDoc*) { -} +BOOL T2People::StressChanged() { + BOOL changed = false; -/*virtual*/ void T2People::LoadSelf(T2Archive&, T2TowerDoc*) { -} + if (!IsSpecialColor()) { + int col = mColor; -/*virtual*/ void T2People::SaveSelf(T2Archive&) { -} + T2PeopleDef *def = (T2PeopleDef *) GetMatterDef(); + if (!def) + return false; -void T2People::ResolveLink(T2PeopleArrayList*) { -} + if (mStress < def->GetStressBlueLimit()) + col = 1; + else if (mStress < def->GetStressYellowLimit()) + col = 7; + else if (mStress < (def->GetStressMax() - 10)) + col = 9; + else + col = 9; -/*virtual*/ T2InfoDialog* T2People::ShowInfoDialog(T2TowerDoc*) { -} + if (mColor != col) { + mColor = col; + changed = true; + } + } -void T2People::GetName(CString&) { + return changed; } -/*virtual*/ int T2People::GetSilhouetteRect(RECT&) { +BOOL T2People::IsVIP() const { + return (mColor == 14); } -/*virtual*/ void T2People::DrawHitMask(T2TowerDoc*) { +BOOL T2People::IsNamed() const { + return (mColor == 13); } -void T2People::ClearSpecialFlag(unsigned int) { +void T2People::SetColor(int col) { + if (col > mColor) + mColor = col; } -void T2People::SetSpecialFlag(unsigned int) { +void T2People::ClearColor() { + if (mColor < 11) { + mColor = 1; + } else if (!IsVIP()) { + if (IsSetSpecialFlag(kSpecialFlag20 | kSpecialFlag40)) + mColor = 11; + else + mColor = 1; + + if (IsFavorite()) + mColor = max(mColor, 13); + + if (IsSetSpecialFlag(kSpecialFlag4)) + mColor = max(mColor, 17); + + if (mColor == 1) + StressChanged(); + } +} + +/*virtual*/ void T2People::SetFavorite(BOOL fav) { + T2Object::SetFavorite(fav); + if (fav) + SetColor(13); + else + ClearColor(); +} + +BOOL T2People::VIPEstimation() { + BOOL result = false; + + if (IsVIP()) + result = CalcCurrEstimate() > 200; + + return result; +} + +BOOL T2People::SearchToilet(T2TowerDoc* towerDoc) { + BOOL result = false; + + if (SetDestinationToReturn()) { + T2RegistedTenantDB *registedTenantDB = towerDoc->towerDoc_vf174(); + T2RouteNavigator *routeNavigator = towerDoc->towerDoc_vf124(); + if (registedTenantDB && routeNavigator) { + int toiletStatus; + T2Tenant *toilet = registedTenantDB->SearchToilet(routeNavigator, mCurPosition, toiletStatus); + + if (toilet) { + toilet->IncReserveCount(1); + SetDestination(toilet->GetEquipID()); + SetStatus(kStatus3); + result = true; + } else { + SetReturnToDestination(); + T2TowerMessage *towerMessage = towerDoc->towerDoc_vf13C(); + if (towerMessage) { + // "トイレが混んでいる" - toilet is crowded + CString msg = "\x83\x67\x83\x43\x83\x8C\x82\xAA\x8D\xAC\x82\xF1\x82\xC5\x82\xA2\x82\xE9"; + + switch (toiletStatus) { + case -1: + // "トイレが近くにない" - there is no toilet nearby + msg = "\x83\x67\x83\x43\x83\x8C\x82\xAA\x8B\xDF\x82\xAD\x82\xC9\x82\xC8\x82\xA2"; + case -2: + towerMessage->PeopleBalloonMessage(msg, this); + ClearSpecialFlag(kSpecialFlag2); + IncEstimate(-30); + } + } + } + } + } + + return result; +} + +void T2People::DrawSearchedPerson(T2TowerDoc* towerDoc) { + switch (mStatus) { + case kStatus3: + case kStatus4: + case kStatus5: + case kStatus10: + case kStatus12: + case kStatus13: + case kStatus14: + case kStatus15: + { + RECT rect; + rect.top = mCurPosition.y; + rect.left = mCurPosition.x; + rect.bottom = rect.top + 1; + rect.right = rect.left + 2; + Draw(towerDoc, rect); + } + } +} + +/*virtual*/ void T2People::Draw(T2TowerDoc* towerDoc, const RECT& inRect) { + if (towerDoc->towerDoc_vf108() > 0) + return; + + if (m18 != -1) { + RECT rect = inRect; + UT2Coordinate::UnitToQD(rect, 0, true); + + int objectID = mSilhouetteDef[mStyle]->mImageObj->FindObject(m18); +#line 1380 + _ASSERT(objectID != -1); + + mSilhouetteDef[mStyle]->mImageObj->DrawObject(towerDoc->towerDoc_vf10C(), objectID, rect, towerDoc->towerDoc_vf108(), T2PaletteAnimeDef::GetCommonColor(mColor)); + } +} + +void T2People::Draw(T2BitImage* image, const RECT& inRect) { + int objectID = mSilhouetteDef[mStyle]->mImageObj->FindObject(0); +#line 1388 + _ASSERT(objectID != -1); + + RECT rect = inRect; + if (mSilhouetteDef[mStyle]->GetWidth() == 1) { + rect.left -= 8; + rect.right = rect.left + 16; + } + + mSilhouetteDef[mStyle]->mImageObj->DrawObject(image, objectID, rect, 0, T2PaletteAnimeDef::GetCommonColor(mColor)); +} + +void T2People::Draw(T2TowerDoc* towerDoc, T2Equip* equip) { + if (!IsSleep() && (equip->IsMover() || !((T2Tenant *) equip)->IsFloor())) { + RECT rect; + POINT curPosition = GetCurPosition(); + SetRect(&rect, curPosition.x, curPosition.y, curPosition.x + 2, curPosition.y + 1); + + UT2Coordinate::UnitToQD(rect, towerDoc->towerDoc_vf108()); + + int objectID = equip->GetEquipDef()->mImageObj->FindObject(1003, mFiller); + if (objectID >= 0) + equip->GetEquipDef()->mImageObj->DrawObject(towerDoc->towerDoc_vf10C(), objectID, rect, towerDoc->towerDoc_vf108()); + } +} + +void T2People::DrawAt(T2TowerDoc* towerDoc, T2Equip* equip, POINT pt) { + if (!IsSleep() && (equip->IsMover() || !((T2Tenant *) equip)->IsFloor())) { + CRect rect; + SetRect(&rect, 0, 0, 2, 1); + rect.OffsetRect(mCurPosition.x - pt.x, mCurPosition.y - pt.y); + + UT2Coordinate::UnitToQD(rect, towerDoc->towerDoc_vf108()); + + int objectID = equip->GetEquipDef()->mImageObj->FindObject(1003, mFiller); + if (objectID >= 0) + equip->GetEquipDef()->mImageObj->DrawObject(towerDoc->towerDoc_vf10C(), objectID, rect); + } +} + +void T2People::Duplicate(T2TowerDoc* towerDoc) { +#line 1430 + _ASSERT(towerDoc); + + T2Pool *pool = towerDoc->mPool; + if (pool) + pool->DuplicatePeople(mPeopleType); +} + +void T2People::Remove(T2TowerDoc* towerDoc, unsigned int id) { + BOOL flag = false; + + if (mHomeTenant == id) { + mHomeTenant = 1; + flag = true; + } + if (mWorkTenant == id) { + mWorkTenant = 1; + flag |= true; + } + + if (flag && IsGeneral() && GetStatus() == kStatus1) { + T2Pool *pool = towerDoc->towerDoc_vf130(); + if (pool) + pool->RemovePeople(this); + } +} + +void T2People::TenantRemoved(unsigned int id) { + if (GetDestination() == id) { + Return(); + IncEstimate(-100); + } else if (RemoveReturn(id)) { + IncEstimate(-200); + } +} + +void T2People::Interview(T2TowerDoc* towerDoc) { + T2FloorInfo *floorInfo = towerDoc->towerDoc_vf12C(); + if (floorInfo) { + CString text; + if (GetInterviewWords(towerDoc, text) && text.GetLength() != 0) { + RECT rect; + rect.left = 0; + rect.top = 0; + rect.right = 0; + rect.bottom = 0; + + if (mStatus == kStatus6) { + T2Request *request = floorInfo->GetRequest(mCurrEquipID); + if (request) + request->CalcPersonArea(this, rect); + } else { + CalcWalkingSilhouetteArea(rect); + } + + if (!IsRectEmpty(&rect)) + towerDoc->mTowerMessage->ObjectBalloonMessage(text, rect); + } + } +} + +BOOL T2People::GetInterviewWords(T2TowerDoc* towerDoc, CString& outStr) { + OptionEvent11Data eventData; + + eventData.str = &outStr; + eventData.people = this; + if (!DispatchOptionEvent(OptionEventType_11, &eventData)) + return outStr != ""; + + unsigned int flags = 0; + + T2PeopleDef *peopleDef = (T2PeopleDef *) GetMatterDef(); + T2FloorInfo *floorInfo = towerDoc->towerDoc_vf12C(); + T2Tenant *dstTenant = floorInfo->GetTenant(mDstTenant); + T2Tenant *workTenant = floorInfo->GetTenant(GetWorkTenant()); + + T2EquipDef *equipDef = NULL; + if (mDstTenant != 1) { + if (dstTenant) { + equipDef = dstTenant->GetEquipDef(); + if (dstTenant == workTenant) + flags |= 1; + } + } else { + flags |= 8; + equipDef = towerDoc->mTenantTemplates->FindTenantDef(mPrevTenantType); + if (workTenant && workTenant->GetEquipDef() == equipDef) + flags |= 1; + } + + if (mStyle == kPeopleStyle1) + flags |= 2; + else if (mStyle == kPeopleStyle2) + flags |= 4; + + unsigned int level = 0; + if (IsVIP()) { + if (mDstTenant == 1 && VIPEstimation()) + flags |= 0x10; + + switch (towerDoc->towerDoc_vf138()) { + case 1: + level = 3; + break; + case 2: + level = 4; + break; + case 3: + level = 5; + break; + } + } else if (IsMaru()) { + level = 6; + flags &= ~1; + } else if (IsReggae()) { + level = 7; + } else if (IsSetSpecialFlag(kSpecialFlag4) && (!dstTenant || dstTenant->GetRegistID() != kTenantRegistID4)) { + level = 1; + } else if (IsSetSpecialFlag(kSpecialFlag2) && (!dstTenant || dstTenant->GetRegistID() != kTenantRegistID7)) { + level = 2; + } + + T2WordDefArray *wordDefArray = NULL; + + if (level != 0) { + wordDefArray = towerDoc->towerDoc_vf170()->mWordDefArray; + } else { + if (mStatus == kStatus6 && peopleDef && mStress >= peopleDef->GetStressYellowLimit()) { + T2Request *request = floorInfo->GetRequest(mCurrEquipID); + if (request) { + unsigned int moverID = request->GetMoverID(); + if (moverID) { + T2Mover *mover = floorInfo->GetMover(moverID); + equipDef = mover ? mover->GetEquipDef() : NULL; + } + } + } + + wordDefArray = equipDef ? equipDef->mWordDefArray : NULL; + } + + if (wordDefArray) + wordDefArray->GetWords(GetSex(), GetAge(), flags, level, outStr); + + eventData.str = &outStr; + eventData.people = this; + DispatchOptionEvent(OptionEventType_12, &eventData); + + return outStr != ""; +} + +BOOL T2People::IsMaru() const { + return mMatterDef && (mMatterDef->mSortKey == 4); +} + +BOOL T2People::IsReggae() const { + return mMatterDef && (mMatterDef->mSortKey == 5); +} + +void T2People::BreakoutEmergency(T2TowerDoc* towerDoc) { + mReturnStack->Init(); + switch (mStatus) { + case kStatus5: + case kStatus10: + ChangeStatus(kStatus3); + case kStatus2: + case kStatus3: + case kStatus4: + case kStatus8: + SetSpecialFlag(kSpecialFlag80); + SetDestination(1); + break; + case kStatus1: + if (IsGeneral()) + towerDoc->towerDoc_vf130()->RemovePeople(this); + break; + } +} + +/*virtual*/ void T2People::LoadSelf(T2Archive& archive, T2TowerDoc* towerDoc) { + DWORD peopleCode; + archive >> peopleCode; + + T2Matter::LoadSelf(archive, towerDoc); + + if (IsUsed()) { + unsigned char uc; + short s; + unsigned short us; + + archive >> uc; + mSpecialFlag = uc; + + archive >> uc; + mWalk = (uc != 0); + + archive >> s; + mStress = s; + + archive >> us; + m80 = us; + + archive >> s; + mEstimate = s; + archive >> s; + mColor = s; + archive >> s; + mFiller = s; + archive >> s; + mPrevTenantType = s; + + archive >> mStyle; + + DWORD peopleTypeCode; + archive >> peopleTypeCode; + + if (peopleTypeCode == 'PTYP') { + mPeopleType->Read(archive); + mMatterDef = towerDoc->mPeopleTemplates->FindPeopleDef(mPeopleType->GetSilhouetteType()); + mAttribute = mMatterDef->GetAttribute(); + } + + for (int i = 0; i < 3; i++) { + short silhouetteType; + archive >> silhouetteType; + if (silhouetteType) + mSilhouetteDef[i] = towerDoc->mSilhouetteTemplates->FindSilhouette(silhouetteType); + else + mSilhouetteDef[i] = NULL; + } + + ChangeSilhouette(); + + DWORD linkCode; + archive >> linkCode; +#line 1727 + _ASSERT(linkCode == 'pLk>'); + + unsigned int linkID; + + archive >> linkID; + if (linkID) + mNext = (CLink *) linkID; + + archive >> linkID; + if (linkID) + mPrev = (CLink *) linkID; + } +} + +/*virtual*/ void T2People::SaveSelf(T2Archive& archive) { + DWORD peopleCode = ''; + archive << peopleCode; + + T2Matter::SaveSelf(archive); + + if (IsUsed()) { + unsigned char uc; + short s; + unsigned short us; + + uc = mSpecialFlag; + archive << uc; + + uc = (mWalk != 0); + archive << uc; + + s = mStress; + archive << s; + + us = m80; + archive << us; + + s = mEstimate; + archive << s; + s = mColor; + archive << s; + s = mFiller; + archive << s; + s = mPrevTenantType; + archive << s; + + archive << mStyle; + + DWORD peopleTypeCode; + if (mPeopleType) + peopleTypeCode = 'PTYP'; + else + peopleTypeCode = 'xPTP'; + archive << peopleTypeCode; + + if (peopleTypeCode == 'PTYP') + mPeopleType->Write(archive); + + for (int i = 0; i < 3; i++) { + short silhouetteType = 0; + if (mSilhouetteDef[i]) + silhouetteType = mSilhouetteDef[i]->GetSilhouetteType(); + archive << silhouetteType; + } + + DWORD linkCode = 'pLk>'; + archive << linkCode; + + unsigned int emptyLinkID = 0; + T2People *linkPeople; + + if (mNext) { + linkPeople = (T2People *) mNext; + unsigned int linkID = linkPeople->GetPeopleID(); + archive << linkID; + } else { + archive << emptyLinkID; + } + + if (mPrev) { + linkPeople = (T2People *) mPrev; + unsigned int linkID = linkPeople->GetPeopleID(); + archive << linkID; + } else { + archive << emptyLinkID; + } + } +} + +void T2People::ResolveLink(T2PeopleArrayList* list) { + if (mNext) { + T2People *people = list->FindPeople((unsigned int) mNext); + mNext = people; + } + if (mPrev) { + T2People *people = list->FindPeople((unsigned int) mPrev); + mPrev = people; + } +} + +/*virtual*/ T2InfoDialog* T2People::ShowInfoDialog(T2TowerDoc* towerDoc) { + CRect rect; + AfxGetMainWnd()->GetWindowRect(rect); + + T2DLGTEMPLATE tmpl; + tmpl.pt = rect.CenterPoint(); + tmpl.moduleHandle = GetWorldModuleHandle(); + tmpl.resID = 2000; + + T2PeopleInfoDialog *dialog = new T2PeopleInfoDialog(this); + dialog->Realize(this, &tmpl, towerDoc, NULL, NULL, true, NULL, 0, true); + someGlobalPeople = this; + + return dialog; +} + +void T2People::GetName(CString& outStr) { + mSilhouetteDef[mStyle]->GetName(outStr); +} + +/*virtual*/ BOOL T2People::GetSilhouetteRect(RECT& outRect) { + if ( + (mStatus == kStatus3) || + (mStatus == kStatus5) || + (mStatus == kStatus10) || + (mStatus == kStatus12) || + (mStatus == kStatus13) || + (mStatus == kStatus4) || + (mStatus == kStatus14) || + (mStatus == kStatus15) + ) + { + if (GetDirection() == 0) { + outRect.left = mCurPosition.x + (2 - GetWidth()); + outRect.top = mCurPosition.y; + outRect.right = outRect.left + GetWidth(); + outRect.bottom = outRect.top + 1; + } else { + outRect.left = mCurPosition.x; + outRect.top = mCurPosition.y; + outRect.right = outRect.left + GetWidth(); + outRect.bottom = outRect.top + 1; + } + return true; + } + + return false; +} + +/*virtual*/ void T2People::DrawHitMask(T2TowerDoc* towerDoc) { + if (IsWalk()) { + CRect rect; + if (GetSilhouetteRect(rect)) { + UT2Coordinate::UnitToQD(rect, towerDoc->towerDoc_vf108()); + towerDoc->towerDoc_vf10C()->FillRect(rect, 1); + } + } +} + +void T2People::ClearSpecialFlag(unsigned int flag) { + mSpecialFlag &= ~flag; + if ((flag & kSpecialFlag4) > 0) + mColor = 1; +} + +void T2People::SetSpecialFlag(unsigned int flag) { + mSpecialFlag |= flag; + if ((flag & kSpecialFlag4) > 0) + mColor = 17; } -- cgit v1.2.3