summaryrefslogtreecommitdiffstats
path: root/src/peds/PedChat.cpp
blob: 470b7eeb4b1e2054e32b771918d35a12ab8ec13c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#include "common.h"
#include "Camera.h"
#include "DMAudio.h"
#include "General.h"
#include "Ped.h"

// --MIAMI: file done

// Corresponds to ped sounds (from SOUND_PED_DEATH to SOUND_PED_TAXI_CALL)
PedAudioData CommentWaitTime[56] = {
  { 500, 800, 500, 2 },
  { 500, 800, 500, 2 },
  { 500, 800, 500, 2 },
  { 500, 800, 500, 2 },
  { 100, 2, 100, 2 },
  { 500, 500, 2000, 1000 },
  { 2000, 50, 2050, 1000 },
  { 5000, 2000, 7000, 3000 },
  { 5000, 2000, 7000, 3000 },
  { 300, 200, 500, 200 },
  { 3000, 1000, 4000, 1000 },
  { 6000, 6000, 6000, 6000 },
  { 4000, 1000, 5000, 1000 },
  { 3000, 1000, 4000, 1000 },
  { 1000, 1000, 2000, 2000 },
  { 1000, 500, 2000, 1500 },
  { 1700, 1000, 3000, 1000 },
  { 800, 200, 1000, 500 },
  { 800, 200, 1000, 500 },
  { 800, 400, 2000, 1000 },
  { 800, 400, 2000, 1000 },
  { 2000, 2000, 4000, 4000 },
  { 2000, 2000, 4000, 1000 },
  { 4000, 1000, 5000, 1000 },
  { 800, 400, 1200, 500 },
  { 5000, 1000, 6000, 2000 },
  { 5000, 1000, 6000, 2000 },
  { 5000, 1000, 6000, 2000 },
  { 5000, 1000, 6000, 2000 },
  { 5000, 1000, 6000, 2000 },
  { 5000, 1000, 6000, 2000 },
  { 5000, 1000, 6000, 2000 },
  { 4000, 2000, 7000, 2000 },
  { 1000, 300, 2000, 1000 },
  { 1500, 1000, 2500, 1000 },
  { 200, 200, 200, 200 },
  { 2000, 1000, 4000, 1000 },
  { 2000, 1000, 4000, 1000 },
  { 1000, 500, 3000, 1000 },
  { 1000, 500, 1000, 1000 },
  { 3000, 2000, 5000, 1000 },
  { 3000, 2000, 5000, 1000 },
  { 3000, 2000, 3000, 2000 },
  { 2000, 1000, 3000, 1000 },
  { 2500, 1000, 5000, 5000 },
  { 2000, 1000, 3000, 2000 },
  { 4000, 1000, 5000, 1000 },
  { 1000, 500, 2000, 4000 },
  { 1000, 500, 2000, 5000 },
  { 2000, 500, 2500, 500 },
  { 1000, 500, 3000, 2000 },
  { 1600, 1000, 2000, 2000 },
  { 2000, 1000, 4000, 2000 },
  { 1500, 1000, 2500, 1000 },
  { 1000, 1000, 5000, 5000 },
  { 0, 0, 0, 0 }
};

bool
CPed::ServiceTalkingWhenDead(void)
{
	return m_queuedSound == SOUND_PED_DEATH;
}

void
CPed::ServiceTalking(void)
{
	if (bBodyPartJustCameOff && m_bodyPartBleeding == PED_HEAD)
		return;

	if (!CGame::germanGame && m_pFire)
		m_queuedSound = SOUND_PED_BURNING;

	if (m_queuedSound != SOUND_NO_SOUND) {
		if (m_queuedSound == SOUND_PED_DEATH)
			m_soundStart = CTimer::GetTimeInMilliseconds() - 1;

		if (CTimer::GetTimeInMilliseconds() > m_soundStart) {
			DMAudio.PlayOneShot(m_audioEntityId, m_queuedSound, 1.0f);
			m_lastSoundStart = CTimer::GetTimeInMilliseconds();
			m_soundStart =
				CommentWaitTime[m_queuedSound - SOUND_PED_DEATH].m_nFixedDelayTime
				+ CTimer::GetTimeInMilliseconds()
				+ CGeneral::GetRandomNumberInRange(0, CommentWaitTime[m_queuedSound - SOUND_PED_DEATH].m_nOverrideFixedDelayTime);

			if (m_queuedSound == SOUND_PED_PLAYER_BEFORESEX && IsPlayer())
				m_soundStart += 2000;

			m_lastQueuedSound = m_queuedSound;
			m_queuedSound = SOUND_NO_SOUND;
		}
	}
}

void
CPed::Say(uint16 audio)
{
	if (3.0f + TheCamera.GetPosition().z < GetPosition().z)
		return;

	if (TheCamera.m_CameraAverageSpeed > 1.65f) {
		if (audio != SOUND_PED_DAMAGE && audio != SOUND_PED_HIT && audio != SOUND_PED_LAND)
			return;

	} else if (TheCamera.m_CameraAverageSpeed > 1.25f) {
		if (audio != SOUND_PED_DEATH &&
			audio != SOUND_PED_DAMAGE && audio != SOUND_PED_HIT && audio != SOUND_PED_LAND &&
			audio != SOUND_PED_TAXI_WAIT && audio != SOUND_PED_EVADE)
			return;

	} else if (TheCamera.m_CameraAverageSpeed > 0.9f) {
		switch (audio) {
			case SOUND_PED_DEATH:
			case SOUND_PED_DAMAGE:
			case SOUND_PED_HIT:
			case SOUND_PED_LAND:
			case SOUND_PED_BURNING:
			case SOUND_PED_FLEE_SPRINT:
			case SOUND_PED_TAXI_WAIT:
			case SOUND_PED_EVADE:
			case SOUND_PED_CRASH_VEHICLE:
			case SOUND_PED_CRASH_CAR:
			case SOUND_PED_ANNOYED_DRIVER:
				break;
			default:
				return;
		}
	}

	if (audio < m_queuedSound) {
		if (audio != m_lastQueuedSound || audio == SOUND_PED_DEATH

		// See VC Ped Speech patch
#ifdef FIX_BUGS
			|| CommentWaitTime[audio - SOUND_PED_DEATH].m_nOverrideMaxRandomDelayTime
				+ (uint32)CGeneral::GetRandomNumberInRange(0, CommentWaitTime[audio - SOUND_PED_DEATH].m_nMaxRandomDelayTime)
#else
			|| CommentWaitTime[m_queuedSound - SOUND_PED_DEATH].m_nOverrideMaxRandomDelayTime
			+ (uint32)CGeneral::GetRandomNumberInRange(0, CommentWaitTime[m_queuedSound - SOUND_PED_DEATH].m_nMaxRandomDelayTime)
#endif
				+ m_lastSoundStart <= CTimer::GetTimeInMilliseconds()) {
			m_queuedSound = audio;
		}
	}
}