-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathzscript.zs
182 lines (146 loc) · 5.37 KB
/
zscript.zs
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
// SPDX-FileCopyrightText: 2022 Alexander Kromm <[email protected]>
// SPDX-License-Identifier: GPL-3.0-or-later
version 4.8
class fm_EventHandler : EventHandler
{
override void WorldTick()
{
if (!mIsInitialized) initialize();
if (fm_damage_limit_enabled != mLastDamageLimitEnabled || fm_damage_limit != mLastDamageLimit)
{
updateDamageLimit();
}
if (fm_damage_leak_enabled != mLastDamageLeakEnabled)
{
updateDamageLeak();
}
mDamageInformation = getDamageInformation();
}
override void NetWorkProcess(ConsoleEvent event)
{
if (event == NULL || event.player != consolePlayer) return;
if (event.name == "fm_detector_on" ) mDamageDetectionEnabled = true;
else if (event.name == "fm_detector_off") mDamageDetectionEnabled = false;
else if (event.name == "fm_detector_toggle") mDamageDetectionEnabled = !mDamageDetectionEnabled;
}
override void RenderOverlay(RenderEvent event)
{
if (mDamageInformation.length() == 0) return;
Font aFont = NewConsoleFont;
let scaleVector = StatusBar.getHudScale();
double scale = scaleVector.x;
double stringWidth = scale * aFont.stringWidth(mDamageInformation);
double stringHeight = scale * aFont.getHeight();
double x = int(0.5 * (Screen.getWidth() - stringWidth));
double y = int(0.1 * (Screen.getHeight() - stringHeight));
double border = int(stringHeight / 4 * scale);
double border2 = border * 2;
Screen.dim("000000", 0.5, x - border, y - border, stringWidth + border2, stringHeight + border2);
Screen.drawText( NewConsoleFont, Font.CR_White, x, y, mDamageInformation
, DTA_ScaleX, scale
, DTA_ScaleY, scale
);
}
// private: ////////////////////////////////////////////////////////////////////////////////////////
private void initialize()
{
mIsInitialized = true;
int sectorsCount = level.sectors.size();
for (int i = 0; i < sectorsCount; ++i)
{
Sector aSector = level.sectors[i];
if (aSector.damageType == 'None') continue;
mDamagingSectorsIndices.push(i);
mDamagingSectorsOriginalDamage.push(aSector.damageAmount);
mDamagingSectorsOriginalLeak.push(aSector.leakyDamage);
}
updateDamageLimit();
updateDamageLeak();
}
private void updateDamageLimit()
{
mLastDamageLimitEnabled = fm_damage_limit_enabled;
mLastDamageLimit = fm_damage_limit;
if (fm_damage_limit_enabled) applyDamageLimit();
else restoreDamage();
}
private void applyDamageLimit()
{
int sectorsCount = mDamagingSectorsIndices.size();
for (int i = 0; i < sectorsCount; ++i)
{
Sector aSector = level.sectors[mDamagingSectorsIndices[i]];
int originalDamage = mDamagingSectorsOriginalDamage[i];
aSector.damageAmount = min(originalDamage, fm_damage_limit);
}
}
private void restoreDamage()
{
int sectorsCount = mDamagingSectorsIndices.size();
for (int i = 0; i < sectorsCount; ++i)
{
Sector aSector = level.sectors[mDamagingSectorsIndices[i]];
aSector.damageAmount = mDamagingSectorsOriginalDamage[i];
}
}
private void updateDamageLeak()
{
mLastDamageLeakEnabled = fm_damage_leak_enabled;
if (fm_damage_leak_enabled) restoreDamageLeak();
else disableDamageLeak();
}
private void restoreDamageLeak()
{
int sectorsCount = mDamagingSectorsIndices.size();
for (int i = 0; i < sectorsCount; ++i)
{
Sector aSector = level.sectors[mDamagingSectorsIndices[i]];
aSector.leakyDamage = mDamagingSectorsOriginalLeak[i];
}
}
private void disableDamageLeak()
{
int sectorsCount = mDamagingSectorsIndices.size();
for (int i = 0; i < sectorsCount; ++i)
{
Sector aSector = level.sectors[mDamagingSectorsIndices[i]];
aSector.leakyDamage = 0;
}
}
private string getDamageInformation()
{
if (!mDamageDetectionEnabled) return "";
let player = players[consolePlayer].mo;
if (player == NULL) return "";
FLineTraceData trace;
player.lineTrace(player.angle, RANGE, player.pitch, offsetz: player.viewHeight, data: trace);
if (trace.hitType != FLineTraceData.TRACE_HitFloor || trace.hitSector == NULL) return "";
int originalDamageAmount = 0;
bool isOriginalDamageAmount = true;
int sectorsCount = mDamagingSectorsIndices.size();
for (int i = 0; i < sectorsCount; ++i)
{
Sector aSector = level.sectors[mDamagingSectorsIndices[i]];
if (trace.hitSector.index() != aSector.index()) continue;
originalDamageAmount = mDamagingSectorsOriginalDamage[i];
isOriginalDamageAmount = (aSector.damageAmount == originalDamageAmount);
break;
}
return isOriginalDamageAmount ?
string.format( StringTable.localize("$FM_DAMAGE"), originalDamageAmount) :
string.format( StringTable.localize("$FM_DAMAGE_ORIGINAL")
, trace.hitSector.damageAmount
, originalDamageAmount
);
}
const RANGE = 1024.0;
private bool mIsInitialized;
private Array<int> mDamagingSectorsIndices;
private Array<int> mDamagingSectorsOriginalDamage;
private Array<int> mDamagingSectorsOriginalLeak;
private bool mLastDamageLimitEnabled;
private int mLastDamageLimit;
private bool mLastDamageLeakEnabled;
private bool mDamageDetectionEnabled;
private string mDamageInformation;
}