1 (* Copyright (C) Doom 2D: Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License ONLY.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 {$INCLUDE ../shared/a_modes.inc}
23 MAPDEF
, g_textures
, xdynrec
;
26 TAddTextureArray
= Array of
32 ATextureID
= array of record
34 False: (Tex
: Cardinal);
35 True: (AnTex
: TAnimation
);
39 TPanel
= Class (TObject
)
43 mGUID
: Integer; // will be assigned in "g_map.pas"
48 FTextureIDs
: ATextureID
;
49 mMovingSpeed
: TDFPoint
;
50 mMovingStart
: TDFPoint
;
52 mMovingActive
: Boolean;
55 mOldMovingActive
: Boolean;
61 mEndSizeTrig
: Integer;
63 mNeedSend
: Boolean; // for network
66 function getx1 (): Integer; inline;
67 function gety1 (): Integer; inline;
68 function getvisvalid (): Boolean; inline;
70 function getMovingSpeedX (): Integer; inline;
71 procedure setMovingSpeedX (v
: Integer); inline;
72 function getMovingSpeedY (): Integer; inline;
73 procedure setMovingSpeedY (v
: Integer); inline;
75 function getMovingStartX (): Integer; inline;
76 procedure setMovingStartX (v
: Integer); inline;
77 function getMovingStartY (): Integer; inline;
78 procedure setMovingStartY (v
: Integer); inline;
80 function getMovingEndX (): Integer; inline;
81 procedure setMovingEndX (v
: Integer); inline;
82 function getMovingEndY (): Integer; inline;
83 procedure setMovingEndY (v
: Integer); inline;
85 function getSizeSpeedX (): Integer; inline;
86 procedure setSizeSpeedX (v
: Integer); inline;
87 function getSizeSpeedY (): Integer; inline;
88 procedure setSizeSpeedY (v
: Integer); inline;
90 function getSizeEndX (): Integer; inline;
91 procedure setSizeEndX (v
: Integer); inline;
92 function getSizeEndY (): Integer; inline;
93 procedure setSizeEndY (v
: Integer); inline;
96 FCurTexture
: Integer; // Íîìåð òåêóùåé òåêñòóðû
100 FWidth
, FHeight
: Word;
106 // sorry, there fields are public to allow setting 'em in g_map; this should be fixed later
107 // for now, PLEASE, don't modify 'em, or all hell will break loose
108 arrIdx
: Integer; // index in one of internal arrays; sorry
109 tag
: Integer; // used in coldets and such; sorry; see g_map.GridTagXXX
110 proxyId
: Integer; // proxy id in map grid (DO NOT USE!)
111 mapId
: AnsiString; // taken directly from map file; dunno why it is here
112 hasTexTrigger
: Boolean; // HACK: true when there's a trigger than can change my texture
114 constructor Create(PanelRec
: TDynRecord
;
115 AddTextures
: TAddTextureArray
;
117 var Textures
: TLevelTextureArray
; aguid
: Integer);
118 destructor Destroy(); override;
121 procedure SetFrame(Frame
: Integer; Count
: Byte);
122 procedure NextTexture(AnimLoop
: Byte = 0);
123 procedure SetTexture(ID
: Integer; AnimLoop
: Byte = 0);
124 function GetTextureID(): Cardinal;
125 function GetTextureCount(): Integer;
126 function CanChangeTexture(): Boolean;
128 procedure SaveState (st
: TStream
);
129 procedure LoadState (st
: TStream
);
131 procedure positionChanged (); inline;
133 function getIsGBack (): Boolean; inline; // gRenderBackgrounds
134 function getIsGStep (): Boolean; inline; // gSteps
135 function getIsGWall (): Boolean; inline; // gWalls
136 function getIsGAcid1 (): Boolean; inline; // gAcid1
137 function getIsGAcid2 (): Boolean; inline; // gAcid2
138 function getIsGWater (): Boolean; inline; // gWater
139 function getIsGFore (): Boolean; inline; // gRenderForegrounds
140 function getIsGLift (): Boolean; inline; // gLifts
141 function getIsGBlockMon (): Boolean; inline; // gBlockMon
144 function gncNeedSend (): Boolean; inline;
145 procedure setDirty (); inline; // why `dirty`? 'cause i may introduce property `needSend` later
148 property visvalid
: Boolean read getvisvalid
; // panel is "visvalid" when it's width and height are positive
151 property guid
: Integer read mGUID
; // will be assigned in "g_map.pas"
152 property x0
: Integer read FX
;
153 property y0
: Integer read FY
;
154 property x1
: Integer read getx1
; // inclusive!
155 property y1
: Integer read gety1
; // inclusive!
156 property x
: Integer read FX write FX
;
157 property y
: Integer read FY write FY
;
158 property width
: Word read FWidth write FWidth
;
159 property height
: Word read FHeight write FHeight
;
160 property panelType
: Word read FPanelType write FPanelType
;
161 property enabled
: Boolean read FEnabled write FEnabled
;
162 property door
: Boolean read FDoor write FDoor
;
163 property liftType
: Byte read FLiftType write FLiftType
;
164 property lastAnimLoop
: Byte read FLastAnimLoop write FLastAnimLoop
;
166 property movingSpeedX
: Integer read getMovingSpeedX write setMovingSpeedX
;
167 property movingSpeedY
: Integer read getMovingSpeedY write setMovingSpeedY
;
168 property movingStartX
: Integer read getMovingStartX write setMovingStartX
;
169 property movingStartY
: Integer read getMovingStartY write setMovingStartY
;
170 property movingEndX
: Integer read getMovingEndX write setMovingEndX
;
171 property movingEndY
: Integer read getMovingEndY write setMovingEndY
;
172 property movingActive
: Boolean read mMovingActive write mMovingActive
;
173 property moveOnce
: Boolean read mMoveOnce write mMoveOnce
;
175 property sizeSpeedX
: Integer read getSizeSpeedX write setSizeSpeedX
;
176 property sizeSpeedY
: Integer read getSizeSpeedY write setSizeSpeedY
;
177 property sizeEndX
: Integer read getSizeEndX write setSizeEndX
;
178 property sizeEndY
: Integer read getSizeEndY write setSizeEndY
;
180 property isGBack
: Boolean read getIsGBack
;
181 property isGStep
: Boolean read getIsGStep
;
182 property isGWall
: Boolean read getIsGWall
;
183 property isGAcid1
: Boolean read getIsGAcid1
;
184 property isGAcid2
: Boolean read getIsGAcid2
;
185 property isGWater
: Boolean read getIsGWater
;
186 property isGFore
: Boolean read getIsGFore
;
187 property isGLift
: Boolean read getIsGLift
;
188 property isGBlockMon
: Boolean read getIsGBlockMon
;
191 property Alpha
: Byte read FAlpha
;
192 property TextureWidth
: Word read FTextureWidth
;
193 property TextureHeight
: Word read FTextureHeight
;
194 property Blending
: Boolean read FBlending
;
195 property TextureIDs
: ATextureID read FTextureIDs
;
198 property movingSpeed
: TDFPoint read mMovingSpeed write mMovingSpeed
;
199 property movingStart
: TDFPoint read mMovingStart write mMovingStart
;
200 property movingEnd
: TDFPoint read mMovingEnd write mMovingEnd
;
202 property sizeSpeed
: TDFSize read mSizeSpeed write mSizeSpeed
;
203 property sizeEnd
: TDFSize read mSizeEnd write mSizeEnd
;
205 property endPosTrigId
: Integer read mEndPosTrig write mEndPosTrig
;
206 property endSizeTrigId
: Integer read mEndSizeTrig write mEndSizeTrig
;
209 TPanelArray
= Array of TPanel
;
218 g_dbgpan_mplat_active
: Boolean = {$IF DEFINED(D2F_DEBUG)}true{$ELSE}true{$ENDIF};
219 g_dbgpan_mplat_step
: Boolean = false; // one step, and stop
225 {$INCLUDE ../nogl/noGLuses.inc}
226 e_texture
, g_basic
, g_map
, g_game
, g_gfx
, g_weapons
, g_triggers
,
227 g_console
, g_language
, g_monsters
, g_player
, g_grid
, e_log
, geom
, utils
, xstreams
;
230 PANEL_SIGNATURE
= $4C4E4150; // 'PANL'
234 constructor TPanel
.Create(PanelRec
: TDynRecord
;
235 AddTextures
: TAddTextureArray
;
237 var Textures
: TLevelTextureArray
; aguid
: Integer);
244 Width
:= PanelRec
.Width
;
245 Height
:= PanelRec
.Height
;
252 mapId
:= PanelRec
.id
;
255 mMovingSpeed
:= PanelRec
.moveSpeed
;
256 mMovingStart
:= PanelRec
.moveStart
;
257 mMovingEnd
:= PanelRec
.moveEnd
;
258 mMovingActive
:= PanelRec
['move_active'].value
;
259 mOldMovingActive
:= mMovingActive
;
260 mMoveOnce
:= PanelRec
.moveOnce
;
262 mSizeSpeed
:= PanelRec
.sizeSpeed
;
263 mSizeEnd
:= PanelRec
.sizeEnd
;
265 mEndPosTrig
:= PanelRec
.endPosTrig
;
266 mEndSizeTrig
:= PanelRec
.endSizeTrig
;
271 PanelType
:= PanelRec
.PanelType
;
274 LiftType
:= LIFTTYPE_UP
;
275 hasTexTrigger
:= False;
278 PANEL_OPENDOOR
: begin Enabled
:= False; Door
:= True; end;
279 PANEL_CLOSEDOOR
: Door
:= True;
280 PANEL_LIFTUP
: LiftType
:= LIFTTYPE_UP
; //???
281 PANEL_LIFTDOWN
: LiftType
:= LIFTTYPE_DOWN
;
282 PANEL_LIFTLEFT
: LiftType
:= LIFTTYPE_LEFT
;
283 PANEL_LIFTRIGHT
: LiftType
:= LIFTTYPE_RIGHT
;
287 if ByteBool(PanelRec
.Flags
and PANEL_FLAG_HIDE
) then
289 SetLength(FTextureIDs
, 0);
293 // Ïàíåëè, íå èñïîëüçóþùèå òåêñòóðû:
294 if ByteBool(PanelType
and
299 PANEL_BLOCKMON
)) then
301 SetLength(FTextureIDs
, 0);
306 // Åñëè ýòî æèäêîñòü áåç òåêñòóðû - ñïåöòåêñòóðó:
307 if WordBool(PanelType
and (PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
)) and
308 (not ByteBool(PanelRec
.Flags
and PANEL_FLAG_WATERTEXTURES
)) then
310 SetLength(FTextureIDs
, 1);
311 FTextureIDs
[0].Anim
:= False;
313 case PanelRec
.PanelType
of
315 FTextureIDs
[0].Tex
:= LongWord(TEXTURE_SPECIAL_WATER
);
317 FTextureIDs
[0].Tex
:= LongWord(TEXTURE_SPECIAL_ACID1
);
319 FTextureIDs
[0].Tex
:= LongWord(TEXTURE_SPECIAL_ACID2
);
326 SetLength(FTextureIDs
, Length(AddTextures
));
331 if CurTex
>= Length(FTextureIDs
) then
332 FCurTexture
:= Length(FTextureIDs
) - 1
334 FCurTexture
:= CurTex
;
336 for i
:= 0 to Length(FTextureIDs
)-1 do
338 FTextureIDs
[i
].Anim
:= AddTextures
[i
].Anim
;
339 if FTextureIDs
[i
].Anim
then
340 begin // Àíèìèðîâàííàÿ òåêñòóðà
341 FTextureIDs
[i
].AnTex
:=
342 TAnimation
.Create(Textures
[AddTextures
[i
].Texture
].FramesID
,
343 True, Textures
[AddTextures
[i
].Texture
].Speed
);
344 FTextureIDs
[i
].AnTex
.Blending
:= ByteBool(PanelRec
.Flags
and PANEL_FLAG_BLENDING
);
345 FTextureIDs
[i
].AnTex
.Alpha
:= PanelRec
.Alpha
;
348 begin // Îáû÷íàÿ òåêñòóðà
349 FTextureIDs
[i
].Tex
:= Textures
[AddTextures
[i
].Texture
].TextureID
;
353 // Òåêñòóð íåñêîëüêî - íóæíî ñîõðàíÿòü òåêóùóþ:
354 //if Length(FTextureIDs) > 1 then SaveIt := True;
356 if (PanelRec
.TextureRec
= nil) then tnum
:= -1 else tnum
:= PanelRec
.tagInt
;
357 if (tnum
< 0) then tnum
:= Length(Textures
);
359 // Åñëè íå ñïåöòåêñòóðà, òî çàäàåì ðàçìåðû:
360 if ({PanelRec.TextureNum}tnum
> High(Textures
)) then
362 e_WriteLog(Format('WTF?! tnum is out of limits! (%d : %d)', [tnum
, High(Textures
)]), TMsgType
.Warning
);
366 FBlending
:= ByteBool(0);
368 else if not g_Map_IsSpecialTexture(Textures
[{PanelRec.TextureNum}tnum
].TextureName
) then
370 FTextureWidth
:= Textures
[{PanelRec.TextureNum}tnum
].Width
;
371 FTextureHeight
:= Textures
[{PanelRec.TextureNum}tnum
].Height
;
372 FAlpha
:= PanelRec
.Alpha
;
373 FBlending
:= ByteBool(PanelRec
.Flags
and PANEL_FLAG_BLENDING
);
377 destructor TPanel
.Destroy();
381 for i
:= 0 to High(FTextureIDs
) do
382 if FTextureIDs
[i
].Anim
then
383 FTextureIDs
[i
].AnTex
.Free();
384 SetLength(FTextureIDs
, 0);
389 function TPanel
.getx1 (): Integer; inline; begin result
:= X
+Width
-1; end;
390 function TPanel
.gety1 (): Integer; inline; begin result
:= Y
+Height
-1; end;
391 function TPanel
.getvisvalid (): Boolean; inline; begin result
:= (Width
> 0) and (Height
> 0); end;
393 function TPanel
.getMovingSpeedX (): Integer; inline; begin result
:= mMovingSpeed
.X
; end;
394 procedure TPanel
.setMovingSpeedX (v
: Integer); inline; begin mMovingSpeed
.X
:= v
; end;
395 function TPanel
.getMovingSpeedY (): Integer; inline; begin result
:= mMovingSpeed
.Y
; end;
396 procedure TPanel
.setMovingSpeedY (v
: Integer); inline; begin mMovingSpeed
.Y
:= v
; end;
398 function TPanel
.getMovingStartX (): Integer; inline; begin result
:= mMovingStart
.X
; end;
399 procedure TPanel
.setMovingStartX (v
: Integer); inline; begin mMovingStart
.X
:= v
; end;
400 function TPanel
.getMovingStartY (): Integer; inline; begin result
:= mMovingStart
.Y
; end;
401 procedure TPanel
.setMovingStartY (v
: Integer); inline; begin mMovingStart
.Y
:= v
; end;
403 function TPanel
.getMovingEndX (): Integer; inline; begin result
:= mMovingEnd
.X
; end;
404 procedure TPanel
.setMovingEndX (v
: Integer); inline; begin mMovingEnd
.X
:= v
; end;
405 function TPanel
.getMovingEndY (): Integer; inline; begin result
:= mMovingEnd
.Y
; end;
406 procedure TPanel
.setMovingEndY (v
: Integer); inline; begin mMovingEnd
.Y
:= v
; end;
408 function TPanel
.getSizeSpeedX (): Integer; inline; begin result
:= mSizeSpeed
.w
; end;
409 procedure TPanel
.setSizeSpeedX (v
: Integer); inline; begin mSizeSpeed
.w
:= v
; end;
410 function TPanel
.getSizeSpeedY (): Integer; inline; begin result
:= mSizeSpeed
.h
; end;
411 procedure TPanel
.setSizeSpeedY (v
: Integer); inline; begin mSizeSpeed
.h
:= v
; end;
413 function TPanel
.getSizeEndX (): Integer; inline; begin result
:= mSizeEnd
.w
; end;
414 procedure TPanel
.setSizeEndX (v
: Integer); inline; begin mSizeEnd
.w
:= v
; end;
415 function TPanel
.getSizeEndY (): Integer; inline; begin result
:= mSizeEnd
.h
; end;
416 procedure TPanel
.setSizeEndY (v
: Integer); inline; begin mSizeEnd
.h
:= v
; end;
418 function TPanel
.getIsGBack (): Boolean; inline; begin result
:= ((tag
and GridTagBack
) <> 0); end;
419 function TPanel
.getIsGStep (): Boolean; inline; begin result
:= ((tag
and GridTagStep
) <> 0); end;
420 function TPanel
.getIsGWall (): Boolean; inline; begin result
:= ((tag
and (GridTagWall
or GridTagDoor
)) <> 0); end;
421 function TPanel
.getIsGAcid1 (): Boolean; inline; begin result
:= ((tag
and GridTagAcid1
) <> 0); end;
422 function TPanel
.getIsGAcid2 (): Boolean; inline; begin result
:= ((tag
and GridTagAcid2
) <> 0); end;
423 function TPanel
.getIsGWater (): Boolean; inline; begin result
:= ((tag
and GridTagWater
) <> 0); end;
424 function TPanel
.getIsGFore (): Boolean; inline; begin result
:= ((tag
and GridTagFore
) <> 0); end;
425 function TPanel
.getIsGLift (): Boolean; inline; begin result
:= ((tag
and GridTagLift
) <> 0); end;
426 function TPanel
.getIsGBlockMon (): Boolean; inline; begin result
:= ((tag
and GridTagBlockMon
) <> 0); end;
428 function TPanel
.gncNeedSend (): Boolean; inline; begin result
:= mNeedSend
; mNeedSend
:= false; end;
429 procedure TPanel
.setDirty (); inline; begin mNeedSend
:= true; end;
431 procedure TPanel
.positionChanged (); inline;
433 px
, py
, pw
, ph
: Integer;
435 if (proxyId
>= 0) then
437 mapGrid
.getBodyDims(proxyId
, px
, py
, pw
, ph
);
438 if (px
<> x
) or (py
<> y
) or (pw
<> Width
) or (ph
<> Height
) then
441 e_LogWritefln('panel moved: arridx=%s; guid=%s; proxyid=%s; old:(%s,%s)-(%sx%s); new:(%s,%s)-(%sx%s)',
442 [arrIdx, mGUID, proxyId, px, py, pw, ph, x, y, width, height]);
444 g_Mark(px
, py
, pw
, ph
, MARK_WALL
, false);
445 if (Width
< 1) or (Height
< 1) then
447 mapGrid
.proxyEnabled
[proxyId
] := false;
451 mapGrid
.proxyEnabled
[proxyId
] := Enabled
;
452 if (pw
<> Width
) or (ph
<> Height
) then
454 //writeln('panel resize!');
455 mapGrid
.moveResizeBody(proxyId
, X
, Y
, Width
, Height
)
459 mapGrid
.moveBody(proxyId
, X
, Y
);
461 g_Mark(X
, Y
, Width
, Height
, MARK_WALL
);
469 monCheckList
: array of TMonster
= nil;
470 monCheckListUsed
: Integer = 0;
472 procedure TPanel
.Update();
475 nx
, ny
, nw
, nh
: Integer;
476 ex
, ey
, nex
, ney
: Integer;
479 // return `true` if we should move by dx,dy
480 function tryMPlatMove (px
, py
, pw
, ph
: Integer; out dx
, dy
: Integer; out squash
: Boolean; ontop
: PBoolean=nil): Boolean;
491 pdx
:= mMovingSpeed
.X
;
492 pdy
:= mMovingSpeed
.Y
;
493 // standing on the platform?
496 if (ontop
<> nil) then ontop
^ := true;
497 // yes, move with it; but skip steps (no need to process size change here, 'cause platform top cannot be changed with it)
498 mapGrid
.traceBox(tex
, tey
, px
, py
, pw
, ph
, pdx
, pdy
, (GridTagWall
or GridTagDoor
));
502 if (ontop
<> nil) then ontop
^ := false;
503 // not standing on the platform: trace platform to see if it hits the entity
504 // first, process size change (as we cannot sweeptest both move and size change)
505 // but we don't have to check for pushing if the panel is shrinking
508 if (szdx
> 0) or (szdy
> 0) then
510 // ignore shrinking dimension
511 if (szdx
< 0) then szdx
:= 0;
512 if (szdy
< 0) then szdy
:= 0;
513 // move platform by szd* back, and check for szd* movement
514 if sweepAABB(ox
-szdx
, oy
-szdy
, nw
, nh
, szdx
, szdy
, px
, py
, pw
, ph
, @u0
) then
516 // yes, platform hits the entity, push the entity in the resizing direction
517 u0
:= 1.0-u0
; // how much path left?
518 szdx
:= trunc(szdx
*u0
);
519 szdy
:= trunc(szdy
*u0
);
520 if (szdx
<> 0) or (szdy
<> 0) then
522 // has some path to go, trace the entity
523 trtag
:= (GridTagWall
or GridTagDoor
);
524 // if we're moving down, consider steps too
525 if (szdy
> 0) then trtag
:= trtag
or GridTagStep
;
526 mapGrid
.traceBox(tex
, tey
, px
, py
, pw
, ph
, szdx
, szdy
, trtag
);
530 // second, process platform movement, using te* as entity starting point
531 if sweepAABB(ox
, oy
, nw
, nh
, pdx
, pdy
, tex
, tey
, pw
, ph
, @u0
) then
533 //e_LogWritefln('T: platsweep; u0=%s; u1=%s; hedge=%s; sweepAABB(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)', [u0, u1, hedge, ox, oy, mpw, mph, pdx, pdy, px-1, py-1, pw+2, ph+2]);
534 // yes, platform hits the entity, push the entity in the direction of the platform
535 u0
:= 1.0-u0
; // how much path left?
536 pdx
:= trunc(pdx
*u0
);
537 pdy
:= trunc(pdy
*u0
);
538 //e_LogWritefln(' platsweep; uleft=%s; pd=(%s,%s)', [u0, pdx, pdy]);
539 if (pdx
<> 0) or (pdy
<> 0) then
541 // has some path to go, trace the entity
542 trtag
:= (GridTagWall
or GridTagDoor
);
543 // if we're moving down, consider steps too
544 if (pdy
> 0) then trtag
:= trtag
or GridTagStep
;
545 mapGrid
.traceBox(tex
, tey
, px
, py
, pw
, ph
, pdx
, pdy
, trtag
);
549 // done with entity movement, new coords are in te*
552 result
:= (dx
<> 0) or (dy
<> 0);
553 if ((tag
and (GridTagWall
or GridTagDoor
)) <> 0) then
555 // check for squashing; as entity cannot be pushed into a wall, check only collision with the platform itself
556 squash
:= g_Collide(tex
, tey
, pw
, ph
, nx
, ny
, nw
, nh
); // squash, if still in platform
560 function monCollect (mon
: TMonster
): Boolean;
562 result
:= false; // don't stop
563 if (monCheckListUsed
>= Length(monCheckList
)) then SetLength(monCheckList
, monCheckListUsed
+128);
564 monCheckList
[monCheckListUsed
] := mon
;
565 Inc(monCheckListUsed
);
569 cx0
, cy0
, cx1
, cy1
, cw
, ch
: Integer;
571 px
, py
, pw
, ph
, pdx
, pdy
: Integer;
579 actMoveTrig
: Boolean;
580 actSizeTrig
: Boolean;
582 if (not Enabled
) or (Width
< 1) or (Height
< 1) then exit
;
584 if (FCurTexture
>= 0) and
585 (FTextureIDs
[FCurTexture
].Anim
) and
586 (FTextureIDs
[FCurTexture
].AnTex
<> nil) and
589 FTextureIDs
[FCurTexture
].AnTex
.Update();
590 FCurFrame
:= FTextureIDs
[FCurTexture
].AnTex
.CurrentFrame
;
591 FCurFrameCount
:= FTextureIDs
[FCurTexture
].AnTex
.CurrentCounter
;
594 if not g_dbgpan_mplat_active
then exit
;
596 if (mOldMovingActive
<> mMovingActive
) then mNeedSend
:= true;
597 mOldMovingActive
:= mMovingActive
;
599 if not mMovingActive
then exit
;
600 if mMovingSpeed
.isZero
and mSizeSpeed
.isZero
then exit
;
602 //TODO: write wall size change processing
607 * collect all monsters and players (aka entities) along the possible platform path
608 * if entity is standing on a platform:
609 * try to move it along the platform path, checking wall collisions
610 * if entity is NOT standing on a platform, but hit with sweeped platform aabb:
612 * if we can't push entity all the way, squash it
619 nw
:= mpw
+mSizeSpeed
.w
;
620 nh
:= mph
+mSizeSpeed
.h
;
621 nx
:= ox
+mMovingSpeed
.X
;
622 ny
:= oy
+mMovingSpeed
.Y
;
624 // force network updates only if some sudden change happened
625 // set the flag here, so we can sync affected monsters
626 if not mSizeSpeed
.isZero
and (nw
= mSizeEnd
.w
) and (nh
= mSizeEnd
.h
) then
630 else if ((mMovingSpeed
.X
< 0) and (nx
<= mMovingStart
.X
)) or ((mMovingSpeed
.X
> 0) and (nx
>= mMovingEnd
.X
)) then
634 else if ((mMovingSpeed
.Y
< 0) and (ny
<= mMovingStart
.Y
)) or ((mMovingSpeed
.Y
> 0) and (ny
>= mMovingEnd
.Y
)) then
639 // if pannel disappeared, we don't have to do anything
640 if (nw
> 0) and (nh
> 0) then
651 cx1
:= nmax(ex
, nex
);
652 cy1
:= nmax(ey
, ney
);
661 // process "obstacle" panels
662 if ((tag
and GridTagObstacle
) <> 0) then
664 // temporarily turn off this panel, so it won't interfere with collision checks
665 mapGrid
.proxyEnabled
[proxyId
] := false;
668 for f
:= 0 to High(gPlayers
) do
671 if (plr
= nil) or (not plr
.alive
) then continue
;
672 plr
.getMapBox(px
, py
, pw
, ph
);
673 if not g_Collide(px
, py
, pw
, ph
, cx0
, cy0
, cw
, ch
) then continue
;
674 if tryMPlatMove(px
, py
, pw
, ph
, pdx
, pdy
, squash
) then
677 plr
.moveBy(pdx
, pdy
); // this will call `positionChanged()` for us
679 // squash player, if necessary
680 if not g_Game_IsClient
and squash
then plr
.Damage(15000, 0, 0, 0, HIT_TRAP
);
684 for f
:= 0 to High(gGibs
) do
687 if not gib
.alive
then continue
;
688 gib
.getMapBox(px
, py
, pw
, ph
);
689 if not g_Collide(px
, py
, pw
, ph
, cx0
, cy0
, cw
, ch
) then continue
;
690 if tryMPlatMove(px
, py
, pw
, ph
, pdx
, pdy
, squash
, @ontop
) then
693 gib
.moveBy(pdx
, pdy
); // this will call `positionChanged()` for us
697 // move and push corpses
698 for f
:= 0 to High(gCorpses
) do
701 if (cor
= nil) then continue
;
702 cor
.getMapBox(px
, py
, pw
, ph
);
703 if not g_Collide(px
, py
, pw
, ph
, cx0
, cy0
, cw
, ch
) then continue
;
704 if tryMPlatMove(px
, py
, pw
, ph
, pdx
, pdy
, squash
, @ontop
) then
707 cor
.moveBy(pdx
, pdy
); // this will call `positionChanged()` for us
712 monCheckListUsed
:= 0;
713 g_Mons_ForEachAt(cx0
, cy0
, cw
, ch
, monCollect
);
715 // process collected monsters
716 if (monCheckListUsed
> 0) then
718 mpfrid
:= g_Mons_getNewMPlatFrameId();
719 for f
:= 0 to monCheckListUsed
do
721 mon
:= monCheckList
[f
];
722 if (mon
= nil) or (not mon
.alive
) or (mon
.mplatCheckFrameId
= mpfrid
) then continue
;
723 mon
.mplatCheckFrameId
:= mpfrid
;
724 mon
.getMapBox(px
, py
, pw
, ph
);
725 //if not g_Collide(px, py, pw, ph, cx0, cy0, cw, ch) then continue;
726 if tryMPlatMove(px
, py
, pw
, ph
, pdx
, pdy
, squash
) then
729 mon
.moveBy(pdx
, pdy
); // this will call `positionChanged()` for us
730 //???FIXME: do we really need to send monsters over the net?
731 // i don't think so, as dead reckoning should take care of 'em
732 // ok, send new monster position only if platform is going to change it's direction
733 if mNeedSend
then mon
.setDirty();
735 // squash monster, if necessary
736 if not g_Game_IsClient
and squash
then mon
.Damage(15000, 0, 0, 0, HIT_TRAP
);
740 // restore panel state
741 mapGrid
.proxyEnabled
[proxyId
] := true;
752 actMoveTrig
:= false;
753 actSizeTrig
:= false;
755 // `mNeedSend` was set above
758 if not mSizeSpeed
.isZero
and (nw
= mSizeEnd
.w
) and (nh
= mSizeEnd
.h
) then
763 if (nw
< 1) or (nh
< 1) then mMovingActive
:= false; //HACK!
766 // reverse moving direction, if necessary
767 if ((mMovingSpeed
.X
< 0) and (nx
<= mMovingStart
.X
)) or ((mMovingSpeed
.X
> 0) and (nx
>= mMovingEnd
.X
)) then
769 if mMoveOnce
then mMovingActive
:= false else mMovingSpeed
.X
:= -mMovingSpeed
.X
;
773 if ((mMovingSpeed
.Y
< 0) and (ny
<= mMovingStart
.Y
)) or ((mMovingSpeed
.Y
> 0) and (ny
>= mMovingEnd
.Y
)) then
775 if mMoveOnce
then mMovingActive
:= false else mMovingSpeed
.Y
:= -mMovingSpeed
.Y
;
779 if (mOldMovingActive
<> mMovingActive
) then mNeedSend
:= true;
780 mOldMovingActive
:= mMovingActive
;
782 if not g_Game_IsClient
then
784 if actMoveTrig
then g_Triggers_Press(mEndPosTrig
, ACTIVATE_CUSTOM
);
785 if actSizeTrig
then g_Triggers_Press(mEndSizeTrig
, ACTIVATE_CUSTOM
);
788 // some triggers may activate this, don't delay sending
789 //TODO: when triggers will be able to control speed and size, check that here too
790 if (mOldMovingActive
<> mMovingActive
) then mNeedSend
:= true;
791 mOldMovingActive
:= mMovingActive
;
796 procedure TPanel
.SetFrame(Frame
: Integer; Count
: Byte);
798 function ClampInt(X
, A
, B
: Integer): Integer;
801 if X
< A
then Result
:= A
else if X
> B
then Result
:= B
;
805 if Enabled
and (FCurTexture
>= 0) and
806 (FTextureIDs
[FCurTexture
].Anim
) and
807 (FTextureIDs
[FCurTexture
].AnTex
<> nil) and
808 (Width
> 0) and (Height
> 0) and (FAlpha
< 255) then
810 FCurFrame
:= ClampInt(Frame
, 0, FTextureIDs
[FCurTexture
].AnTex
.TotalFrames
- 1);
811 FCurFrameCount
:= Count
;
812 FTextureIDs
[FCurTexture
].AnTex
.CurrentFrame
:= FCurFrame
;
813 FTextureIDs
[FCurTexture
].AnTex
.CurrentCounter
:= FCurFrameCount
;
817 procedure TPanel
.NextTexture(AnimLoop
: Byte = 0);
819 Assert(FCurTexture
>= -1, 'FCurTexture < -1');
822 if Length(FTextureIDs
) = 0 then
825 // Òîëüêî îäíà òåêñòóðà:
826 if Length(FTextureIDs
) = 1 then
828 if FCurTexture
= 0 then
834 // Áîëüøå îäíîé òåêñòóðû:
838 // Ñëåäóþùåé íåò - âîçâðàò ê íà÷àëó:
839 if FCurTexture
>= Length(FTextureIDs
) then
843 // Ïåðåêëþ÷èëèñü íà âèäèìóþ àíèì. òåêñòóðó:
844 if (FCurTexture
>= 0) and FTextureIDs
[FCurTexture
].Anim
then
846 if (FTextureIDs
[FCurTexture
].AnTex
= nil) then
848 g_FatalError(_lc
[I_GAME_ERROR_SWITCH_TEXTURE
]);
853 FTextureIDs
[FCurTexture
].AnTex
.Loop
:= True
856 FTextureIDs
[FCurTexture
].AnTex
.Loop
:= False;
858 FTextureIDs
[FCurTexture
].AnTex
.Reset();
861 LastAnimLoop
:= AnimLoop
;
864 procedure TPanel
.SetTexture(ID
: Integer; AnimLoop
: Byte = 0);
866 if (ID
>= -1) and (ID
< Length(FTextureIDs
)) then
869 // Ïåðåêëþ÷èëèñü íà âèäèìóþ àíèì. òåêñòóðó:
870 if (FCurTexture
>= 0) and FTextureIDs
[FCurTexture
].Anim
then
872 if (FTextureIDs
[FCurTexture
].AnTex
= nil) then
874 g_FatalError(_lc
[I_GAME_ERROR_SWITCH_TEXTURE
]);
879 FTextureIDs
[FCurTexture
].AnTex
.Loop
:= True
882 FTextureIDs
[FCurTexture
].AnTex
.Loop
:= False;
884 FTextureIDs
[FCurTexture
].AnTex
.Reset();
887 LastAnimLoop
:= AnimLoop
;
890 function TPanel
.GetTextureID(): DWORD
;
892 Result
:= LongWord(TEXTURE_NONE
);
894 if (FCurTexture
>= 0) then
896 if FTextureIDs
[FCurTexture
].Anim
then
897 Result
:= FTextureIDs
[FCurTexture
].AnTex
.FramesID
899 Result
:= FTextureIDs
[FCurTexture
].Tex
;
903 function TPanel
.GetTextureCount(): Integer;
905 Result
:= Length(FTextureIDs
);
906 if Enabled
and (FCurTexture
>= 0) then
907 if (FTextureIDs
[FCurTexture
].Anim
) and
908 (FTextureIDs
[FCurTexture
].AnTex
<> nil) and
909 (Width
> 0) and (Height
> 0) and (FAlpha
< 255) then
910 Result
:= Result
+ 100;
913 function TPanel
.CanChangeTexture(): Boolean;
915 Result
:= (GetTextureCount() > 1) or hasTexTrigger
;
919 PAN_SAVE_VERSION
= 1;
921 procedure TPanel
.SaveState (st
: TStream
);
925 if (st
= nil) then exit
;
928 utils
.writeSign(st
, 'PANL');
929 utils
.writeInt(st
, Byte(PAN_SAVE_VERSION
));
930 // Îòêðûòà/çàêðûòà, åñëè äâåðü
931 utils
.writeBool(st
, FEnabled
);
932 // Íàïðàâëåíèå ëèôòà, åñëè ëèôò
933 utils
.writeInt(st
, Byte(FLiftType
));
934 // Íîìåð òåêóùåé òåêñòóðû
935 utils
.writeInt(st
, Integer(FCurTexture
));
936 // Êîîðäèíàòû è ðàçìåð
937 utils
.writeInt(st
, Integer(FX
));
938 utils
.writeInt(st
, Integer(FY
));
939 utils
.writeInt(st
, Word(FWidth
));
940 utils
.writeInt(st
, Word(FHeight
));
941 // Àíèìèðîâàíà ëè òåêóùàÿ òåêñòóðà
942 if (FCurTexture
>= 0) and (FTextureIDs
[FCurTexture
].Anim
) then
944 assert(FTextureIDs
[FCurTexture
].AnTex
<> nil, 'TPanel.SaveState: No animation object');
951 utils
.writeBool(st
, anim
);
952 // Åñëè äà - ñîõðàíÿåì àíèìàöèþ
953 if anim
then FTextureIDs
[FCurTexture
].AnTex
.SaveState(st
);
955 // moving platform state
956 utils
.writeInt(st
, Integer(mMovingSpeed
.X
));
957 utils
.writeInt(st
, Integer(mMovingSpeed
.Y
));
958 utils
.writeInt(st
, Integer(mMovingStart
.X
));
959 utils
.writeInt(st
, Integer(mMovingStart
.Y
));
960 utils
.writeInt(st
, Integer(mMovingEnd
.X
));
961 utils
.writeInt(st
, Integer(mMovingEnd
.Y
));
963 utils
.writeInt(st
, Integer(mSizeSpeed
.w
));
964 utils
.writeInt(st
, Integer(mSizeSpeed
.h
));
965 utils
.writeInt(st
, Integer(mSizeEnd
.w
));
966 utils
.writeInt(st
, Integer(mSizeEnd
.h
));
968 utils
.writeBool(st
, mMovingActive
);
969 utils
.writeBool(st
, mMoveOnce
);
971 utils
.writeInt(st
, Integer(mEndPosTrig
));
972 utils
.writeInt(st
, Integer(mEndSizeTrig
));
976 procedure TPanel
.LoadState (st
: TStream
);
978 if (st
= nil) then exit
;
981 if not utils
.checkSign(st
, 'PANL') then raise XStreamError
.create('wrong panel signature');
982 if (utils
.readByte(st
) <> PAN_SAVE_VERSION
) then raise XStreamError
.create('wrong panel version');
983 // Îòêðûòà/çàêðûòà, åñëè äâåðü
984 FEnabled
:= utils
.readBool(st
);
985 // Íàïðàâëåíèå ëèôòà, åñëè ëèôò
986 FLiftType
:= utils
.readByte(st
);
987 // Íîìåð òåêóùåé òåêñòóðû
988 FCurTexture
:= utils
.readLongInt(st
);
989 // Êîîðäèíàòû è ðàçìåð
990 FX
:= utils
.readLongInt(st
);
991 FY
:= utils
.readLongInt(st
);
992 FWidth
:= utils
.readWord(st
);
993 FHeight
:= utils
.readWord(st
);
994 // Àíèìèðîâàííàÿ ëè òåêóùàÿ òåêñòóðà
995 if utils
.readBool(st
) then
997 // Åñëè äà - çàãðóæàåì àíèìàöèþ
998 Assert((FCurTexture
>= 0) and
999 (FTextureIDs
[FCurTexture
].Anim
) and
1000 (FTextureIDs
[FCurTexture
].AnTex
<> nil),
1001 'TPanel.LoadState: No animation object');
1002 FTextureIDs
[FCurTexture
].AnTex
.LoadState(st
);
1005 // moving platform state
1006 mMovingSpeed
.X
:= utils
.readLongInt(st
);
1007 mMovingSpeed
.Y
:= utils
.readLongInt(st
);
1008 mMovingStart
.X
:= utils
.readLongInt(st
);
1009 mMovingStart
.Y
:= utils
.readLongInt(st
);
1010 mMovingEnd
.X
:= utils
.readLongInt(st
);
1011 mMovingEnd
.Y
:= utils
.readLongInt(st
);
1013 mSizeSpeed
.w
:= utils
.readLongInt(st
);
1014 mSizeSpeed
.h
:= utils
.readLongInt(st
);
1015 mSizeEnd
.w
:= utils
.readLongInt(st
);
1016 mSizeEnd
.h
:= utils
.readLongInt(st
);
1018 mMovingActive
:= utils
.readBool(st
);
1019 mMoveOnce
:= utils
.readBool(st
);
1021 mEndPosTrig
:= utils
.readLongInt(st
);
1022 mEndSizeTrig
:= utils
.readLongInt(st
);
1025 //mapGrid.proxyEnabled[proxyId] := FEnabled; // done in g_map.pas