aboutsummaryrefslogtreecommitdiffstats
path: root/src/control/Phones.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/control/Phones.cpp')
-rw-r--r--src/control/Phones.cpp125
1 files changed, 16 insertions, 109 deletions
diff --git a/src/control/Phones.cpp b/src/control/Phones.cpp
index 7632cfa3..41f9d766 100644
--- a/src/control/Phones.cpp
+++ b/src/control/Phones.cpp
@@ -41,16 +41,6 @@ CPed *CPhoneInfo::pCallBackPed; // ped who picking up the phone (reset after pic
after 60 seconds of last phone pick-up.
*/
-#ifdef PEDS_REPORT_CRIMES_ON_PHONE
-CPed* crimeReporters[NUMPHONES] = {};
-bool
-isPhoneAvailable(int m_phoneId)
-{
- return crimeReporters[m_phoneId] == nil || !crimeReporters[m_phoneId]->IsPointerValid() || crimeReporters[m_phoneId]->m_objective > OBJECTIVE_WAIT_ON_FOOT ||
- (crimeReporters[m_phoneId]->m_nPedState != PED_MAKE_CALL && crimeReporters[m_phoneId]->m_nPedState != PED_FACE_PHONE && crimeReporters[m_phoneId]->m_nPedState != PED_SEEK_POS);
-}
-#endif
-
void
CPhoneInfo::Update(void)
{
@@ -167,14 +157,9 @@ CPhoneInfo::FindNearestFreePhone(CVector *pos)
int nearestPhoneId = -1;
float nearestPhoneDist = 60.0f;
- for (int phoneId = 0; phoneId < m_nMax; phoneId++) {
+ for (int phoneId = 0; phoneId < m_nMax; phoneId++) {
-#ifdef PEDS_REPORT_CRIMES_ON_PHONE
- if (isPhoneAvailable(phoneId))
-#else
- if (gPhoneInfo.m_aPhones[phoneId].m_nState == PHONE_STATE_FREE)
-#endif
- {
+ if (gPhoneInfo.m_aPhones[phoneId].m_nState == PHONE_STATE_FREE) {
float phoneDist = (m_aPhones[phoneId].m_vecPos - *pos).Magnitude2D();
if (phoneDist < nearestPhoneDist) {
@@ -215,81 +200,32 @@ CPhoneInfo::IsMessageBeingDisplayed(int phoneId)
return pPhoneDisplayingMessages == &m_aPhones[phoneId];
}
-#ifdef COMPATIBLE_SAVES
-static inline void
-LoadPhone(CPhone &phone, uint8 *&buf)
-{
- ReadSaveBuf(&phone.m_vecPos, buf);
- SkipSaveBuf(buf, 6 * 4);
- ReadSaveBuf<uint32>(&phone.m_repeatedMessagePickupStart, buf);
- uint32 tmp;
- ReadSaveBuf(&tmp, buf);
- phone.m_pEntity = (CEntity*)(uintptr)tmp;
- ReadSaveBuf<PhoneState>(&phone.m_nState, buf);
- ReadSaveBuf<bool>(&phone.m_visibleToCam, buf);
- SkipSaveBuf(buf, 3);
-}
-#endif
-
void
CPhoneInfo::Load(uint8 *buf, uint32 size)
{
INITSAVEBUF
- int32 max, scriptPhonesMax;
- ReadSaveBuf(&max, buf);
- ReadSaveBuf(&scriptPhonesMax, buf);
-
-#ifdef PEDS_REPORT_CRIMES_ON_PHONE
- m_nMax = Min(NUMPHONES, max);
- m_nScriptPhonesMax = 0;
-
- bool ignoreOtherPhones = false;
-
- // We can do it without touching saves. We'll only load script phones, others are already loaded in Initialise
- for (int i = 0; i < 50; i++) {
- CPhone phoneToLoad;
-#ifdef COMPATIBLE_SAVES
- phoneToLoad.m_apMessages[0]=phoneToLoad.m_apMessages[1]=phoneToLoad.m_apMessages[2]=phoneToLoad.m_apMessages[3]=phoneToLoad.m_apMessages[4]=phoneToLoad.m_apMessages[5] = nil;
- LoadPhone(phoneToLoad, buf);
-#else
- ReadSaveBuf(&phoneToLoad, buf);
-#endif
-
- if (ignoreOtherPhones)
- continue;
-
- if (i < scriptPhonesMax) {
- if (i >= m_nMax) {
- assert(0 && "Number of phones used by script exceeds the NUMPHONES or the stored phones in save file. Ignoring some phones");
- ignoreOtherPhones = true;
- continue;
- }
- SwapPhone(phoneToLoad.m_vecPos.x, phoneToLoad.m_vecPos.y, i);
-
- m_aPhones[i] = phoneToLoad;
- // It's saved as building pool index in save file, convert it to true entity
- if (m_aPhones[i].m_pEntity) {
- m_aPhones[i].m_pEntity = CPools::GetBuildingPool()->GetSlot((uintptr)m_aPhones[i].m_pEntity - 1);
- }
- } else
- ignoreOtherPhones = true;
- }
-#else
- m_nMax = max;
- m_nScriptPhonesMax = scriptPhonesMax;
-
+ ReadSaveBuf(&m_nMax, buf);
+ ReadSaveBuf(&m_nScriptPhonesMax, buf);
for (int i = 0; i < NUMPHONES; i++) {
#ifdef COMPATIBLE_SAVES
- LoadPhone(m_aPhones[i], buf);
+ ReadSaveBuf(&m_aPhones[i].m_vecPos, buf);
+ SkipSaveBuf(buf, 6 * 4);
+ ReadSaveBuf(&m_aPhones[i].m_repeatedMessagePickupStart, buf);
+ int32 tmp;
+ ReadSaveBuf(&tmp, buf);
+ // It's saved as building pool index in save file, convert it to true entity
+ m_aPhones[i].m_pEntity = tmp != 0 ? CPools::GetBuildingPool()->GetSlot(tmp - 1) : nil;
+ ReadSaveBuf(&m_aPhones[i].m_nState, buf);
+ ReadSaveBuf(&m_aPhones[i].m_visibleToCam, buf);
+ SkipSaveBuf(buf, 3);
#else
ReadSaveBuf(&m_aPhones[i], buf);
-#endif
// It's saved as building pool index in save file, convert it to true entity
if (m_aPhones[i].m_pEntity) {
m_aPhones[i].m_pEntity = CPools::GetBuildingPool()->GetSlot((uintptr)m_aPhones[i].m_pEntity - 1);
}
- }
#endif
+ }
VALIDATESAVEBUF(size)
}
@@ -327,31 +263,6 @@ CPhoneInfo::SetPhoneMessage_Repeatedly(int phoneId, wchar *msg1, wchar *msg2, wc
}
}
-#ifdef PEDS_REPORT_CRIMES_ON_PHONE
-void
-CPhoneInfo::SwapPhone(float xPos, float yPos, int into)
-{
- // "into" should be in 0 - m_nScriptPhonesMax range
- int nearestPhoneId = -1;
- CVector pos(xPos, yPos, 0.0f);
- float nearestPhoneDist = 1.0f;
-
- for (int phoneId = m_nScriptPhonesMax; phoneId < m_nMax; phoneId++) {
- float phoneDistance = (m_aPhones[phoneId].m_vecPos - pos).Magnitude2D();
- if (phoneDistance < nearestPhoneDist) {
- nearestPhoneDist = phoneDistance;
- nearestPhoneId = phoneId;
- }
- }
- m_aPhones[nearestPhoneId].m_nState = PHONE_STATE_MESSAGE_REMOVED;
-
- CPhone oldPhone = m_aPhones[into];
- m_aPhones[into] = m_aPhones[nearestPhoneId];
- m_aPhones[nearestPhoneId] = oldPhone;
- m_nScriptPhonesMax++;
-}
-#endif
-
int
CPhoneInfo::GrabPhone(float xPos, float yPos)
{
@@ -411,11 +322,7 @@ CPhoneInfo::Save(uint8 *buf, uint32 *size)
INITSAVEBUF
WriteSaveBuf(buf, m_nMax);
WriteSaveBuf(buf, m_nScriptPhonesMax);
-#ifdef PEDS_REPORT_CRIMES_ON_PHONE
- for (int phoneId = 0; phoneId < 50; phoneId++) { // We can do it without touching saves
-#else
- for (int phoneId = 0; phoneId < NUMPHONES; phoneId++) {
-#endif
+ for(int phoneId = 0; phoneId < NUMPHONES; phoneId++) {
#ifdef COMPATIBLE_SAVES
WriteSaveBuf(buf, m_aPhones[phoneId].m_vecPos);
ZeroSaveBuf(buf, 6 * 4);