-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathZScript.zsc
407 lines (290 loc) · 16.9 KB
/
ZScript.zsc
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
version "3.3.0"
#include "ZScript/W2Util.zsc"
#include "ZScript/W2Data.zsc"
#include "ZScript/W2DListTexCache.zsc"
#include "ZScript/W2PlayerHandler.zsc"
#include "ZScript/W2AmbientActors.zsc"
const WeathremumVersion = "0.31a";
class WeathremumHandler: EventHandler {
bool mustCreateGeneralSectorsData; // "PlayerEntered()" is called before "WorldLoaded()".
WeathremumCacheTextureKeeper texturesCache;
W2LevelGeneralData w2level;
W2PlayerHandler playerHandlers[ MAXPLAYERS ], initCurW2PlayerHandler;
int initCurW2SurfaceType;
uint updateSectorCurIndex, updateSectorsMaxTickAmount, totalLevelSectors;
//transient ThinkerIterator lastHandledActorIter; // Causes savegame to crush.
int globalWindVectorChangeCountdown, blowWindVectorChangeCountdown;
override void OnRegister() {
SetOrder( WeathremumHandlerOrder );
W2Global.Log( LL_Debug, String.Format( "%s::OnRegister(). Handler order 0x%X.", GetClassName(), WeathremumHandlerOrder ) );
mustCreateGeneralSectorsData = true;
w2level = new( 'W2LevelGeneralData' );
texturesCache = WeathremumCacheTextureKeeper.CreateKeeper();
W2Global.Log( LL_Detailed, "Weathremum v" .. WeathremumVersion .. " handler initialized." );
Super.OnRegister();
}
private void setNextToOutdoorSectorData( Line curline, Sector ls ) {
W2SectorData closeSectorData = w2level.allSectorsData[ ls.Index() ];
if ( ls.GetTexture( Sector.ceiling ) != skyflatnum ) {
closeSectorData.w2area = W2AT_NextToOutdoor;
W2LinedefData ldata = w2level.GetLinedefData( curline );
ldata.isCornice = true;
//W2Global.Log( LL_Debug, GetClassName() .. "::SetNextToOutdoor(). Line " .. curline.Index() .. ", len " .. ldata.linelen .. ", dir " .. ldata.deltadir );
if ( curline.frontsector == ls )
ldata.corniceDir = Actor.RotateVector( ldata.deltadir, -90.0 );
else
ldata.corniceDir = Actor.RotateVector( ldata.deltadir, 90.0 );
}
}
void UpdateW2SectorSurfaceType( out W2SectorData w2secdata, Sector sec ) {
w2secdata.lastFloorTexture = sec.GetTexture( Sector.FLOOR );
EWeathremumSectorType w2oldSectype = w2secdata.w2type;
w2secdata.w2type = W2ST_Default;
WeathremumCacheTexture texcache = texturesCache.Update( w2secdata.lastFloorTexture );
// Understanding the sector floor terrain Weathremum type:
if ( texcache.w2type != W2ST_None ) {
w2secdata.w2type = texcache.w2type;
} else {
String floorTexName = TexMan.GetName( w2secdata.lastFloorTexture );
String floorTexNameLeft4 = floorTexName.Left( 4 );
String floorTexNameLeft5 = floorTexName.Left( 5 );
String floorTexNameLeft6 = floorTexName.Left( 6 );
bool isSlime00Slime08 = ( floorTexNameLeft6 == "SLIME0" && floorTexName.CharCodeAt( 6 ) <= 0x38 );
if ( floorTexNameLeft6 == "FWATER" || ( isSlime00Slime08 && sec.damageamount ) ) {
w2secdata.w2type = W2ST_Water;
} else if ( floorTexNameLeft5 == "METAL" ) {
w2secdata.w2type = W2ST_MetalSurface;
} else if ( floorTexNameLeft5 == "FLOOR" ) {
String postfix = floorTexName.Mid( 5, 3 );
if ( postfix == "0_5" || postfix == "0_6" || postfix == "0_7" || postfix == "3_3" || postfix == "4_8" || postfix == "5_1" )
w2secdata.w2type = W2ST_MetalSurface;
} else if ( floorTexName == "GATE4" || floorTexName == "SLIME14" || floorTexName == "SLIME15" || floorTexName == "SLIME16" || floorTexNameLeft4 == "STEP" || floorTexName == "CEIL3_5" || floorTexName == "CEIL3_6" || floorTexName == "CEIL1_2" ) {
w2secdata.w2type = W2ST_MetalSurface;
} else if ( floorTexName == "FLOOR4_6" ) {
w2secdata.w2type = W2ST_PlasticSurface;
} else if ( floorTexNameLeft4 == "FLAT" ) {
String postfix = floorTexName.Mid( 4, 3 );
if ( postfix == "20" || postfix == "22" || postfix == "23" || postfix == "3" || postfix == "4" )
w2secdata.w2type = W2ST_MetalSurface;
else if ( postfix == "1" || postfix == "17" || postfix == "18" || postfix == "19" || postfix == "2" || postfix == "9" )
w2secdata.w2type = W2ST_PlasticSurface;
else if ( postfix == "10" || postfix == "14" || postfix == "5_5" || postfix == "8" )
w2secdata.w2type = W2ST_SoftSurface;
} else if ( floorTexNameLeft5 == "GRASS" ) {
w2secdata.w2type = W2ST_SoftSurface;
} else if ( floorTexNameLeft5 == "SLIME" || floorTexNameLeft5 == "RROCK" ) {
int texSubindex = floorTexName.Mid( 5, 2 ).ToInt();
if ( isSlime00Slime08
|| ( floorTexNameLeft5 == "SLIME" && texSubindex >= 9 && texSubindex <= 12 )
|| ( floorTexNameLeft5 == "RROCK" && texSubindex <= 8 && texSubindex != 3 && texSubindex != 4 ) ) {
w2secdata.w2type = W2ST_Incandecent;
} else if ( floorTexNameLeft5 == "RROCK" ) {
w2secdata.w2type = W2ST_RockSurface;
}
} else if ( floorTexName == "GRNROCK" ) {
w2secdata.w2type = W2ST_RockSurface;
} else if ( floorTexNameLeft6 == "MFLR8_" ) {
String postfix = floorTexName.Mid( 6, 1 );
if ( postfix == "1" || postfix == "3" )
w2secdata.w2type = W2ST_RockSurface;
else
w2secdata.w2type = W2ST_SoftSurface;
} else if ( floorTexNameLeft4 == "SFLR" ) {
w2secdata.w2type = W2ST_SoftSurface;
} else if ( floorTexNameLeft4 == "LAVA" ) {
w2secdata.w2type = W2ST_Incandecent;
} else if ( floorTexNameLeft5 == "BLOOD" || floorTexNameLeft6 == "NUKAGE" ) {
w2secdata.w2type = W2ST_Nukage;
} else if ( floorTexNameLeft6 == "F_SKY1" ) {
w2secdata.w2type = W2ST_Void;
}
texcache.w2type = w2secdata.w2type;
}
if ( W2Global.GetLoglevel() >= LL_Debug ) {
String w2oldSectypeName = ( w2oldSectype != W2ST_None? TEXTCOLOR_GRAY .. W2SoundKeeper.WeathremumSectorTypeNames[ w2oldSectype ] .. LLCOLOR_DEBUG : "<None>" );
String w2newSectypeName = ( w2secdata.w2type != W2ST_None? TEXTCOLOR_GRAY .. W2SoundKeeper.WeathremumSectorTypeNames[ w2secdata.w2type ] .. LLCOLOR_DEBUG : "<None>" );
W2Global.ClearscopeLog( LL_Debug, GetClassName() .. "::UpdateW2SectorSurfaceType(). Sector #" .. sec.Index() .. ", from \"" .. w2oldSectypeName .. "\" (" .. w2oldSectype .. ") to \"" .. w2newSectypeName .. "\" (" .. w2secdata.w2type .. ")." );
}
} // of void UpdateW2SectorSurfaceType( out W2SectorData w2secdata, Sector sec ) {}
void CreateGeneralSectorsData( void ) {
W2Global.Log( LL_Debug, GetClassName() .. "::CreateGeneralSectorsData(). Initialization..." );
w2level.allSectorsData.Clear();
w2level.allLinedefsData.Clear();
texturesCache.Clear();
// Save all of the level lines and sectors for the quick index-based
//access. Filled up before any other operations because the next ones
//may (and will) get any element, not only less than their "Index()".
for ( int i = 0; i < level.lines.Size(); i++ )
w2level.allLinedefsData.Push( W2LinedefData.Create( level.lines[ i ] ) );
for ( int i = 0; i < level.sectors.Size(); i++ )
w2level.allSectorsData.Push( W2SectorData.Create( level.sectors[ i ] ) );
W2Global.Log( LL_Debug, GetClassName() .. "::CreateGeneralSectorsData(). " .. w2level.allLinedefsData.Size() .. " lines, " .. w2level.allSectorsData.Size() .. " sectors." );
// Understand its data such as "w2type" and "groupnum" for sectors under sky:
for ( int i = 0; i < level.sectors.Size(); i++ ) {
//console.printf( "Sector " .. i .. ": " .. level.Sectors[ i ].GetTexture( Sector.ceiling ) .. "." );
Sector s = level.Sectors[ i ];
W2SectorData secdataOutdoor = w2level.allSectorsData[ i ];
if ( secdataOutdoor.w2area == W2AT_None )
secdataOutdoor.w2area = W2AT_Indoor;
if ( s.GetTexture( Sector.CEILING ) == skyflatnum ) {
// Setting relationship to neighbour sectors:
secdataOutdoor.w2area = W2AT_Outdoor;
for ( int j = 0; j < s.Lines.Size(); j++ ) {
Line l = s.Lines[ j ];
Sector lsector = l.frontsector;
if ( lsector && lsector != s )
setNextToOutdoorSectorData( l, lsector );
lsector = l.backsector;
if ( lsector && lsector != s )
setNextToOutdoorSectorData( l, lsector );
} // of for ( int j = 0; j < s.Lines.Size(); j++ ) {}
} // of if ( s.GetTexture( Sector.ceiling ) == skyflatnum ) {}
UpdateW2SectorSurfaceType( secdataOutdoor, s );
} // of for ( int i = 0; i < level.Sectors.Size(); i++ ) {}
totalLevelSectors = level.sectors.Size();
updateSectorCurIndex = 0;
updateSectorsMaxTickAmount = int( ceil( totalLevelSectors / 10.0 ) );
//lastHandledActorIter = ThinkerIterator.Create( "Actor", STAT_WEATHREMUM_MAINDECOR );
globalWindVectorChangeCountdown = Random( 35, 3500 );
blowWindVectorChangeCountdown = Random( 0, 175 );
w2level.globalWindVector = (FRandom( -2.0, 2.0 ), FRandom( -2.0, 2.0 ));
w2level.blowWindVector = (0.0, 0.0);
mustCreateGeneralSectorsData = false;
} // of void CreateGeneralSectorsData( void ) {}
private void pushSound( String sndname, String w2typename = "" ) {
Actor plmo = players[ initCurW2PlayerHandler.targetPlayerNum ].mo;
initCurW2SurfaceType++;
initCurW2PlayerHandler.sndkeepers.Push( W2SoundKeeper.Create( sndname, initCurW2SurfaceType, plmo, w2typename ) );
W2Global.Log( LL_Detailed, String.Format( "Sound keeper for player %i, w2type %2i \"%s\", sound \"%s\".",
initCurW2PlayerHandler.targetPlayerNum, initCurW2SurfaceType, initCurW2PlayerHandler.sndkeepers[ initCurW2SurfaceType ].w2typename, sndname ) );
}
override void PlayerEntered( PlayerEvent e ) {
if ( mustCreateGeneralSectorsData )
CreateGeneralSectorsData();
if ( players[ e.PlayerNumber ].mo ) {
Actor plmo = players[ e.PlayerNumber ].mo;
initCurW2PlayerHandler = W2PlayerHandler( new( 'W2PlayerHandler' ) );
initCurW2PlayerHandler.targetPlayerNum = e.PlayerNumber;
initCurW2PlayerHandler.w2level = w2level;
initCurW2SurfaceType = W2ST_None;
// Based on the both of SNDINFO and SNDSEQ.
pushSound( "nothing" ); // W2ST_Void,
pushSound( "weathremum/rain/default" ); // W2ST_NormalSurface,
pushSound( "weathremum/rainsurface/soft" ); // W2ST_SoftSurface,
pushSound( "weathremum/rain/heavy" ); // W2ST_Water,
pushSound( "weathremum/rain/default" ); // W2ST_Nukage,
pushSound( "weathremum/rainsurface/incandescent" ); // W2ST_Incandecent,
pushSound( "weathremum/rainsurface/rock" ); // W2ST_RockSurface,
pushSound( "weathremum/rainsurface/metal" ); // W2ST_MetalSurface,
pushSound( "weathremum/rainsurface/plasticglass" ); // W2ST_PlasticSurface,
playerHandlers[ e.PlayerNumber ] = initCurW2PlayerHandler;
W2Global.Log( LL_Detailed, "Created handler " .. initCurW2PlayerHandler.GetClassName() .. " for player " .. e.PlayerNumber .. "." );
}
Super.PlayerEntered( e );
} // of override void PlayerEntered( PlayerEvent e ) {}
int debugTraceLineIndex;
override void WorldTick() {
if ( w2level.allSectorsData.Size() != totalLevelSectors ) {
W2Global.Log( LL_Debug, GetClassName() .. "::WorldLoaded(). False sectors size: now " .. w2level.allSectorsData.Size() .. ", saved " .. totalLevelSectors .. ", really " .. level.sectors.Size() .. ". Recreating Weathremum level data..." );
CreateGeneralSectorsData();
}
if ( W2Global.GetLoglevel() >= LL_Detailed ) {
FLineTraceData ptrace;
PlayerPawn pl = players[ 0 ].mo;
pl.LineTrace( pl.angle, 256, pl.pitch, offsetz: players[ 0 ].ViewHeight, data: ptrace );
debugTraceLineIndex = ( ptrace.hitLine? ptrace.hitLine.Index() : -1 );
}
// Pseudo-non-blocking updating surface data for all sectors:
for ( int i = 0; i < updateSectorsMaxTickAmount; i++ ) {
Sector s = level.sectors[ updateSectorCurIndex ];
W2SectorData secdata = w2level.allSectorsData[ updateSectorCurIndex ];
if ( secdata.lastFloorTexture != s.GetTexture( Sector.FLOOR ) )
UpdateW2SectorSurfaceType( secdata, s );
updateSectorCurIndex = ( updateSectorCurIndex + 1 ) % totalLevelSectors;
}
// Winds handling (synchronized between clients):
if ( --globalWindVectorChangeCountdown <= 0 ) {
w2level.globalWindVector.x = clamp( w2level.globalWindVector.x + FRandom( -1.0, 1.0 ), -5.0, 5.0 );
w2level.globalWindVector.y = clamp( w2level.globalWindVector.y + FRandom( -1.0, 1.0 ), -5.0, 5.0 );
globalWindVectorChangeCountdown = Random( 35 * 5, 35 * 100 );
W2Global.Log( LL_Debug, GetClassName() .. "::WorldTick(). " .. TEXTCOLOR_CYAN .. "Global wind " .. LLCOLOR_DEBUG .. "changed to " .. w2level.globalWindVector .. ", left " .. globalWindVectorChangeCountdown .. " tics." );
}
w2level.blowWindVector *= 0.975;
if ( --blowWindVectorChangeCountdown <= 0 ) {
w2level.blowWindVector = ( FRandom( -5.0, 5.0 ), FRandom( -5.0, 5.0 ) );
blowWindVectorChangeCountdown = Random( 2, 35 * 20 );
W2Global.Log( LL_Debug, GetClassName() .. "::WorldTick(). " .. TEXTCOLOR_BROWN .. "Blow wind " .. LLCOLOR_DEBUG .. "changed to " .. w2level.blowWindVector .. ", left " .. blowWindVectorChangeCountdown .. " tics." );
}
// Thrust actors exposed to the wind direction.
// [McM]: actually not visible in-action...
/*Actor thrustee = NULL;
for ( int i = 500; i && ( thrustee = Actor( lastHandledActorIter.Next() ) ); i-- ) {
if ( !thrustee.bCORPSE )
thrustee.vel.xy += w2level.globalWindVector + w2level.blowWindVector;
}
if ( !thrustee )
lastHandledActorIter.Reinit();
*/
Super.WorldTick();
}
override void NetworkProcess( ConsoleEvent e ) {
/*if ( e.Name ~== "test_turn180" ) {
players[ e.Player ].mo.angle = ( players[ e.Player ].mo.angle + 180.0 ) % 360.0;
} else if ( e.Name ~== "test_turnto" ) {
players[ e.Player ].mo.angle = e.args[ 0 ] % 360.0;
}*/
Super.NetworkProcess( e );
}
/*override void RenderOverlay( RenderEvent e ) {
W2PlayerHandler playerhandler = playerHandlers[ consoleplayer ];
if ( !playerhandler ) {
Super.RenderOverlay( e );
return;
}
W2SectorData secdata = ( playerhandler.target.floorsector? w2level.allSectorsData[ playerhandler.target.floorsector.Index() ] : NULL );
String outStr = "Total sounds: " .. playerhandler.sndkeepers.Size() .. ".\n\n";
for ( int i = 0; i < playerhandler.sndkeepers.Size(); i++ ) {
W2SoundKeeper curkeeper = playerhandler.sndkeepers[ i ];
String debugstr = "";
String debugstr2 = curkeeper.w2typename;// .. "; " .. curkeeper.sndname;
switch ( curkeeper.status ) {
case W2HS_Active: debugstr = TEXTCOLOR_GREEN .. "on"; break;
case W2HS_StopSuggestion: debugstr = TEXTCOLOR_YELLOW .. "stopping"; break;
case W2HS_Off: debugstr = TEXTCOLOR_RED .. "off"; break;
default: debugstr = TEXTCOLOR_FIRE .. "unknown"; break;
}
String maincolor = ( secdata && secdata.w2type == i? TEXTCOLOR_DARKGREEN : TEXTCOLOR_GRAY );
//debugstr2.Replace( "weathremum", TEXTCOLOR_BLUE .. "[w2]" .. maincolor );
outStr.AppendFormat( "%s#%i (%s%s, type %i%s, \"%s%s\").\n" .. TEXTCOLOR_GRAY,
maincolor, i, debugstr, maincolor, curkeeper.w2type, maincolor, debugstr2, maincolor );
debugstr = " Left: ";
for ( int dir = 0; dir < W2SD_Quantity; dir++ ) {
if ( curkeeper.sndorigin[ dir ] )
outStr.AppendFormat( debugstr .. TEXTCOLOR_TEAL .. "dist " .. curkeeper.minlength[ dir ] .. " at " .. curkeeper.minposxyz[ dir ].xy .. TEXTCOLOR_GRAY .. ". ZDiff " .. curkeeper.minposxyz[ dir ].z );
else
outStr = outStr .. debugstr .. TEXTCOLOR_DARKGRAY .. "off (" .. curkeeper.minlength[ dir ] .. ")";
debugstr = TEXTCOLOR_GRAY .. "\n Right: ";
} // of for ( int dir = 0; dir < W2SD_Quantity; dir++ ) {}
outStr = outStr .. "\n\n";
}
Screen.DrawText( smallfont, Font.CR_GRAY, 30, 60, outStr,
DTA_KeepRatio, true, DTA_VirtualWidth, 1366, DTA_VirtualHeight, 768 );
if ( secdata )
Screen.DrawText( smallfont, Font.CR_GRAY, 1050, 100, "Current sector: " .. secdata.s.Index() .. TEXTCOLOR_DARKGRAY .. " (areatype " .. secdata.w2area .. ")",
DTA_KeepRatio, true, DTA_VirtualWidth, 1366, DTA_VirtualHeight, 768 );
if ( debugTraceLineIndex != -1 ) {
W2LinedefData ldata = w2level.allLinedefsData[ debugTraceLineIndex ];
Screen.DrawText( smallfont, Font.CR_GRAY, 1050, 110, "Line ID: " .. debugTraceLineIndex .. "; \n" .. TEXTCOLOR_BLUE ..
" ceil: " .. TEXTCOLOR_SAPPHIRE .. "fz " .. ldata.fceilz .. ", bz " .. ldata.bceilz .. "\n" .. TEXTCOLOR_BROWN ..
" flr : " .. TEXTCOLOR_TAN .. "fz " .. ldata.ffloorz .. ", bz " .. ldata.bfloorz .. "\n" .. TEXTCOLOR_DARKGREEN ..
"zdiffs: floors " .. ldata.floorsdiffz .. ", ceils " .. ldata.ceilsdiffz,
DTA_KeepRatio, true, DTA_VirtualWidth, 1366, DTA_VirtualHeight, 768 );
}
vector2 playerDir = Actor.AngleToVector( players[ consoleplayer ].mo.angle, 1.0 );
Screen.DrawText( smallfont, Font.CR_CYAN, 1050, 160, "Global wind: " .. ( playerDir dot ( w2level.globalWindVector / w2level.globalWindVector.Length() ) ) .. ", " .. TEXTCOLOR_GRAY .. "len " .. w2level.globalWindVector.Length(),
DTA_KeepRatio, true, DTA_VirtualWidth, 1366, DTA_VirtualHeight, 768 );
Screen.DrawText( smallfont, Font.CR_DARKBROWN, 1050, 170, "Blow wind: " .. ( playerDir dot ( w2level.blowWindVector / w2level.blowWindVector.Length() ) ) .. ", " .. TEXTCOLOR_DARKGRAY .. "len " .. w2level.blowWindVector.Length(),
DTA_KeepRatio, true, DTA_VirtualWidth, 1366, DTA_VirtualHeight, 768 );
Super.RenderOverlay( e );
}/* */
} // of class WeathremumHandler: EventHandler {}