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_animations
, xdynrec
;
26 TLevelTexture
= record
27 TextureName
: AnsiString; // as stored in wad
28 FullName
: AnsiString; // full path to texture // !!! merge it with TextureName
29 framesCount
, speed
: Byte;
32 TLevelTextureArray
= array of TLevelTexture
;
34 TAddTextureArray
= array of record
35 Texture
: Cardinal; // Textures[Texture]
38 ATextureID
= array of record
39 Texture
: Cardinal; // Textures[Texture]
44 TPanel
= Class (TObject
)
48 mGUID
: Integer; // will be assigned in "g_map.pas"
51 FTextureIDs
: ATextureID
;
52 mMovingSpeed
: TDFPoint
;
53 mMovingStart
: TDFPoint
;
55 mMovingActive
: Boolean;
58 mOldMovingActive
: Boolean;
64 mEndSizeTrig
: Integer;
66 mNeedSend
: Boolean; // for network
69 function getx1 (): Integer; inline;
70 function gety1 (): Integer; inline;
71 function getvisvalid (): Boolean; inline;
73 function getMovingSpeedX (): Integer; inline;
74 procedure setMovingSpeedX (v
: Integer); inline;
75 function getMovingSpeedY (): Integer; inline;
76 procedure setMovingSpeedY (v
: Integer); inline;
78 function getMovingStartX (): Integer; inline;
79 procedure setMovingStartX (v
: Integer); inline;
80 function getMovingStartY (): Integer; inline;
81 procedure setMovingStartY (v
: Integer); inline;
83 function getMovingEndX (): Integer; inline;
84 procedure setMovingEndX (v
: Integer); inline;
85 function getMovingEndY (): Integer; inline;
86 procedure setMovingEndY (v
: Integer); inline;
88 function getSizeSpeedX (): Integer; inline;
89 procedure setSizeSpeedX (v
: Integer); inline;
90 function getSizeSpeedY (): Integer; inline;
91 procedure setSizeSpeedY (v
: Integer); inline;
93 function getSizeEndX (): Integer; inline;
94 procedure setSizeEndX (v
: Integer); inline;
95 function getSizeEndY (): Integer; inline;
96 procedure setSizeEndY (v
: Integer); inline;
99 FCurTexture
: Integer; // Íîìåð òåêóùåé òåêñòóðû
101 FCurFrameCount
: Byte;
103 FOldX
, FOldY
: Integer;
104 FWidth
, FHeight
: Word;
111 // sorry, there fields are public to allow setting 'em in g_map; this should be fixed later
112 // for now, PLEASE, don't modify 'em, or all hell will break loose
113 arrIdx
: Integer; // index in one of internal arrays; sorry
114 tag
: Integer; // used in coldets and such; sorry; see g_map.GridTagXXX
115 proxyId
: Integer; // proxy id in map grid (DO NOT USE!)
116 mapId
: AnsiString; // taken directly from map file; dunno why it is here
117 hasTexTrigger
: Boolean; // HACK: true when there's a trigger than can change my texture
119 constructor Create(PanelRec
: TDynRecord
;
120 AddTextures
: TAddTextureArray
;
122 var Textures
: TLevelTextureArray
; aguid
: Integer);
123 destructor Destroy(); override;
126 procedure SetFrame(Frame
: Integer; Count
: Byte);
127 procedure NextTexture(AnimLoop
: Byte = 0);
128 procedure SetTexture(ID
: Integer; AnimLoop
: Byte = 0);
129 function GetTextureID(): Cardinal;
130 function GetTextureCount(): Integer;
131 function CanChangeTexture(): Boolean;
133 procedure SaveState (st
: TStream
);
134 procedure LoadState (st
: TStream
);
136 procedure positionChanged (); inline;
138 function getIsGBack (): Boolean; inline; // gRenderBackgrounds
139 function getIsGStep (): Boolean; inline; // gSteps
140 function getIsGWall (): Boolean; inline; // gWalls
141 function getIsGAcid1 (): Boolean; inline; // gAcid1
142 function getIsGAcid2 (): Boolean; inline; // gAcid2
143 function getIsGWater (): Boolean; inline; // gWater
144 function getIsGFore (): Boolean; inline; // gRenderForegrounds
145 function getIsGLift (): Boolean; inline; // gLifts
146 function getIsGBlockMon (): Boolean; inline; // gBlockMon
149 function gncNeedSend (): Boolean; inline;
150 procedure setDirty (); inline; // why `dirty`? 'cause i may introduce property `needSend` later
153 property visvalid
: Boolean read getvisvalid
; // panel is "visvalid" when it's width and height are positive
156 property guid
: Integer read mGUID
; // will be assigned in "g_map.pas"
157 property x0
: Integer read FX
;
158 property y0
: Integer read FY
;
159 property x1
: Integer read getx1
; // inclusive!
160 property y1
: Integer read gety1
; // inclusive!
161 property x
: Integer read FX write FX
;
162 property y
: Integer read FY write FY
;
163 property width
: Word read FWidth write FWidth
;
164 property height
: Word read FHeight write FHeight
;
165 property oldX
: Integer read FOldX
;
166 property oldY
: Integer read FOldY
;
167 property oldWidth
: Word read FOldW
;
168 property oldHeight
: Word read FOldH
;
169 property panelType
: Word read FPanelType write FPanelType
;
170 property enabled
: Boolean read FEnabled write FEnabled
;
171 property door
: Boolean read FDoor write FDoor
;
172 property liftType
: Byte read FLiftType write FLiftType
;
173 property lastAnimLoop
: Byte read FLastAnimLoop write FLastAnimLoop
;
175 property movingSpeedX
: Integer read getMovingSpeedX write setMovingSpeedX
;
176 property movingSpeedY
: Integer read getMovingSpeedY write setMovingSpeedY
;
177 property movingStartX
: Integer read getMovingStartX write setMovingStartX
;
178 property movingStartY
: Integer read getMovingStartY write setMovingStartY
;
179 property movingEndX
: Integer read getMovingEndX write setMovingEndX
;
180 property movingEndY
: Integer read getMovingEndY write setMovingEndY
;
181 property movingActive
: Boolean read mMovingActive write mMovingActive
;
182 property moveOnce
: Boolean read mMoveOnce write mMoveOnce
;
184 property sizeSpeedX
: Integer read getSizeSpeedX write setSizeSpeedX
;
185 property sizeSpeedY
: Integer read getSizeSpeedY write setSizeSpeedY
;
186 property sizeEndX
: Integer read getSizeEndX write setSizeEndX
;
187 property sizeEndY
: Integer read getSizeEndY write setSizeEndY
;
189 property isGBack
: Boolean read getIsGBack
;
190 property isGStep
: Boolean read getIsGStep
;
191 property isGWall
: Boolean read getIsGWall
;
192 property isGAcid1
: Boolean read getIsGAcid1
;
193 property isGAcid2
: Boolean read getIsGAcid2
;
194 property isGWater
: Boolean read getIsGWater
;
195 property isGFore
: Boolean read getIsGFore
;
196 property isGLift
: Boolean read getIsGLift
;
197 property isGBlockMon
: Boolean read getIsGBlockMon
;
200 property Alpha
: Byte read FAlpha
;
201 property Blending
: Boolean read FBlending
;
202 property TextureIDs
: ATextureID read FTextureIDs
;
205 property movingSpeed
: TDFPoint read mMovingSpeed write mMovingSpeed
;
206 property movingStart
: TDFPoint read mMovingStart write mMovingStart
;
207 property movingEnd
: TDFPoint read mMovingEnd write mMovingEnd
;
209 property sizeSpeed
: TDFSize read mSizeSpeed write mSizeSpeed
;
210 property sizeEnd
: TDFSize read mSizeEnd write mSizeEnd
;
212 property endPosTrigId
: Integer read mEndPosTrig write mEndPosTrig
;
213 property endSizeTrigId
: Integer read mEndSizeTrig write mEndSizeTrig
;
216 TPanelArray
= Array of TPanel
;
225 g_dbgpan_mplat_active
: Boolean = {$IF DEFINED(D2F_DEBUG)}true{$ELSE}true{$ENDIF};
226 g_dbgpan_mplat_step
: Boolean = false; // one step, and stop
238 {$IFDEF ENABLE_CORPSES}
241 g_basic
, g_map
, g_game
, g_weapons
, g_triggers
, g_items
,
242 g_console
, g_language
, g_monsters
, g_player
, g_grid
, e_log
, geom
, utils
, xstreams
246 PANEL_SIGNATURE
= $4C4E4150; // 'PANL'
250 function FindTextureByName (const name
: String): Integer;
254 if Textures
<> nil then
256 for i
:= 0 to High(Textures
) do
258 if Textures
[i
].TextureName
= name
then
267 constructor TPanel
.Create(PanelRec
: TDynRecord
;
268 AddTextures
: TAddTextureArray
;
270 var Textures
: TLevelTextureArray
; aguid
: Integer);
279 Width
:= PanelRec
.Width
;
280 Height
:= PanelRec
.Height
;
289 mapId
:= PanelRec
.id
;
292 mMovingSpeed
:= PanelRec
.moveSpeed
;
293 mMovingStart
:= PanelRec
.moveStart
;
294 mMovingEnd
:= PanelRec
.moveEnd
;
295 mMovingActive
:= PanelRec
['move_active'].value
;
296 mOldMovingActive
:= mMovingActive
;
297 mMoveOnce
:= PanelRec
.moveOnce
;
299 mSizeSpeed
:= PanelRec
.sizeSpeed
;
300 mSizeEnd
:= PanelRec
.sizeEnd
;
302 mEndPosTrig
:= PanelRec
.endPosTrig
;
303 mEndSizeTrig
:= PanelRec
.endSizeTrig
;
308 PanelType
:= PanelRec
.PanelType
;
311 LiftType
:= LIFTTYPE_UP
;
312 hasTexTrigger
:= False;
315 PANEL_OPENDOOR
: begin Enabled
:= False; Door
:= True; end;
316 PANEL_CLOSEDOOR
: Door
:= True;
317 PANEL_LIFTUP
: LiftType
:= LIFTTYPE_UP
; //???
318 PANEL_LIFTDOWN
: LiftType
:= LIFTTYPE_DOWN
;
319 PANEL_LIFTLEFT
: LiftType
:= LIFTTYPE_LEFT
;
320 PANEL_LIFTRIGHT
: LiftType
:= LIFTTYPE_RIGHT
;
324 if ByteBool(PanelRec
.Flags
and PANEL_FLAG_HIDE
) then
326 SetLength(FTextureIDs
, 0);
330 // Ïàíåëè, íå èñïîëüçóþùèå òåêñòóðû:
331 if ByteBool(PanelType
and
336 PANEL_BLOCKMON
)) then
338 SetLength(FTextureIDs
, 0);
343 // Åñëè ýòî æèäêîñòü áåç òåêñòóðû - ñïåöòåêñòóðó:
344 if WordBool(PanelType
and (PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
)) and
345 (not ByteBool(PanelRec
.Flags
and PANEL_FLAG_WATERTEXTURES
)) then
347 SetLength(FTextureIDs
, 1);
348 case PanelRec
.PanelType
of
349 PANEL_WATER
: FTextureIDs
[0].Texture
:= FindTextureByName(TEXTURE_NAME_WATER
);
350 PANEL_ACID1
: FTextureIDs
[0].Texture
:= FindTextureByName(TEXTURE_NAME_ACID1
);
351 PANEL_ACID2
: FTextureIDs
[0].Texture
:= FindTextureByName(TEXTURE_NAME_ACID2
);
357 SetLength(FTextureIDs
, Length(AddTextures
));
362 if CurTex
>= Length(FTextureIDs
) then
363 FCurTexture
:= Length(FTextureIDs
) - 1
365 FCurTexture
:= CurTex
;
367 for i
:= 0 to Length(FTextureIDs
)-1 do
369 FTextureIDs
[i
].Texture
:= AddTextures
[i
].Texture
;
370 if Textures
[AddTextures
[i
].Texture
].FramesCount
> 0 then
371 FTextureIDs
[i
].AnTex
:= TAnimState
.Create(True, Textures
[AddTextures
[i
].Texture
].Speed
, Textures
[AddTextures
[i
].Texture
].FramesCount
)
373 FTextureIDs
[i
].AnTex
.Invalidate
;
376 // Òåêñòóð íåñêîëüêî - íóæíî ñîõðàíÿòü òåêóùóþ:
377 //if Length(FTextureIDs) > 1 then SaveIt := True;
379 if (PanelRec
.TextureRec
= nil) then tnum
:= -1 else tnum
:= PanelRec
.tagInt
;
380 if (tnum
< 0) then tnum
:= Length(Textures
);
382 // Åñëè íå ñïåöòåêñòóðà, òî çàäàåì ðàçìåðû:
383 if ({PanelRec.TextureNum}tnum
> High(Textures
)) then
385 e_WriteLog(Format('WTF?! tnum is out of limits! (%d : %d)', [tnum
, High(Textures
)]), TMsgType
.Warning
);
387 FBlending
:= ByteBool(0);
389 else if not g_Map_IsSpecialTexture(Textures
[{PanelRec.TextureNum}tnum
].TextureName
) then
391 FAlpha
:= PanelRec
.Alpha
;
392 FBlending
:= ByteBool(PanelRec
.Flags
and PANEL_FLAG_BLENDING
);
396 destructor TPanel
.Destroy();
398 SetLength(FTextureIDs
, 0);
402 function TPanel
.getx1 (): Integer; inline; begin result
:= X
+Width
-1; end;
403 function TPanel
.gety1 (): Integer; inline; begin result
:= Y
+Height
-1; end;
404 function TPanel
.getvisvalid (): Boolean; inline; begin result
:= (Width
> 0) and (Height
> 0); end;
406 function TPanel
.getMovingSpeedX (): Integer; inline; begin result
:= mMovingSpeed
.X
; end;
407 procedure TPanel
.setMovingSpeedX (v
: Integer); inline; begin mMovingSpeed
.X
:= v
; end;
408 function TPanel
.getMovingSpeedY (): Integer; inline; begin result
:= mMovingSpeed
.Y
; end;
409 procedure TPanel
.setMovingSpeedY (v
: Integer); inline; begin mMovingSpeed
.Y
:= v
; end;
411 function TPanel
.getMovingStartX (): Integer; inline; begin result
:= mMovingStart
.X
; end;
412 procedure TPanel
.setMovingStartX (v
: Integer); inline; begin mMovingStart
.X
:= v
; end;
413 function TPanel
.getMovingStartY (): Integer; inline; begin result
:= mMovingStart
.Y
; end;
414 procedure TPanel
.setMovingStartY (v
: Integer); inline; begin mMovingStart
.Y
:= v
; end;
416 function TPanel
.getMovingEndX (): Integer; inline; begin result
:= mMovingEnd
.X
; end;
417 procedure TPanel
.setMovingEndX (v
: Integer); inline; begin mMovingEnd
.X
:= v
; end;
418 function TPanel
.getMovingEndY (): Integer; inline; begin result
:= mMovingEnd
.Y
; end;
419 procedure TPanel
.setMovingEndY (v
: Integer); inline; begin mMovingEnd
.Y
:= v
; end;
421 function TPanel
.getSizeSpeedX (): Integer; inline; begin result
:= mSizeSpeed
.w
; end;
422 procedure TPanel
.setSizeSpeedX (v
: Integer); inline; begin mSizeSpeed
.w
:= v
; end;
423 function TPanel
.getSizeSpeedY (): Integer; inline; begin result
:= mSizeSpeed
.h
; end;
424 procedure TPanel
.setSizeSpeedY (v
: Integer); inline; begin mSizeSpeed
.h
:= v
; end;
426 function TPanel
.getSizeEndX (): Integer; inline; begin result
:= mSizeEnd
.w
; end;
427 procedure TPanel
.setSizeEndX (v
: Integer); inline; begin mSizeEnd
.w
:= v
; end;
428 function TPanel
.getSizeEndY (): Integer; inline; begin result
:= mSizeEnd
.h
; end;
429 procedure TPanel
.setSizeEndY (v
: Integer); inline; begin mSizeEnd
.h
:= v
; end;
431 function TPanel
.getIsGBack (): Boolean; inline; begin result
:= ((tag
and GridTagBack
) <> 0); end;
432 function TPanel
.getIsGStep (): Boolean; inline; begin result
:= ((tag
and GridTagStep
) <> 0); end;
433 function TPanel
.getIsGWall (): Boolean; inline; begin result
:= ((tag
and (GridTagWall
or GridTagDoor
)) <> 0); end;
434 function TPanel
.getIsGAcid1 (): Boolean; inline; begin result
:= ((tag
and GridTagAcid1
) <> 0); end;
435 function TPanel
.getIsGAcid2 (): Boolean; inline; begin result
:= ((tag
and GridTagAcid2
) <> 0); end;
436 function TPanel
.getIsGWater (): Boolean; inline; begin result
:= ((tag
and GridTagWater
) <> 0); end;
437 function TPanel
.getIsGFore (): Boolean; inline; begin result
:= ((tag
and GridTagFore
) <> 0); end;
438 function TPanel
.getIsGLift (): Boolean; inline; begin result
:= ((tag
and GridTagLift
) <> 0); end;
439 function TPanel
.getIsGBlockMon (): Boolean; inline; begin result
:= ((tag
and GridTagBlockMon
) <> 0); end;
441 function TPanel
.gncNeedSend (): Boolean; inline; begin result
:= mNeedSend
; mNeedSend
:= false; end;
442 procedure TPanel
.setDirty (); inline; begin mNeedSend
:= true; end;
444 procedure TPanel
.positionChanged (); inline;
446 px
, py
, pw
, ph
: Integer;
448 if (proxyId
>= 0) then
450 mapGrid
.getBodyDims(proxyId
, px
, py
, pw
, ph
);
451 if (px
<> x
) or (py
<> y
) or (pw
<> Width
) or (ph
<> Height
) then
454 e_LogWritefln('panel moved: arridx=%s; guid=%s; proxyid=%s; old:(%s,%s)-(%sx%s); new:(%s,%s)-(%sx%s)',
455 [arrIdx, mGUID, proxyId, px, py, pw, ph, x, y, width, height]);
458 g_Mark(px
, py
, pw
, ph
, MARK_WALL
, false);
460 if (Width
< 1) or (Height
< 1) then
462 mapGrid
.proxyEnabled
[proxyId
] := false;
466 mapGrid
.proxyEnabled
[proxyId
] := Enabled
;
467 if (pw
<> Width
) or (ph
<> Height
) then
469 //writeln('panel resize!');
470 mapGrid
.moveResizeBody(proxyId
, X
, Y
, Width
, Height
)
474 mapGrid
.moveBody(proxyId
, X
, Y
);
477 g_Mark(X
, Y
, Width
, Height
, MARK_WALL
);
486 monCheckList
: array of TMonster
= nil;
487 monCheckListUsed
: Integer = 0;
489 procedure TPanel
.Update();
492 nx
, ny
, nw
, nh
: Integer;
493 ex
, ey
, nex
, ney
: Integer;
497 // return `true` if we should move by dx,dy
498 function tryMPlatMove (px
, py
, pw
, ph
: Integer; out dx
, dy
: Integer; out squash
: Boolean; ontop
: PBoolean=nil): Boolean;
509 pdx
:= mMovingSpeed
.X
;
510 pdy
:= mMovingSpeed
.Y
;
511 // standing on the platform?
514 if (ontop
<> nil) then ontop
^ := true;
515 // yes, move with it; but skip steps (no need to process size change here, 'cause platform top cannot be changed with it)
516 mapGrid
.traceBox(tex
, tey
, px
, py
, pw
, ph
, pdx
, pdy
, (GridTagWall
or GridTagDoor
));
520 if (ontop
<> nil) then ontop
^ := false;
521 // not standing on the platform: trace platform to see if it hits the entity
522 // first, process size change (as we cannot sweeptest both move and size change)
523 // but we don't have to check for pushing if the panel is shrinking
526 if (szdx
> 0) or (szdy
> 0) then
528 // ignore shrinking dimension
529 if (szdx
< 0) then szdx
:= 0;
530 if (szdy
< 0) then szdy
:= 0;
531 // move platform by szd* back, and check for szd* movement
532 if sweepAABB(ox
-szdx
, oy
-szdy
, nw
, nh
, szdx
, szdy
, px
, py
, pw
, ph
, @u0
) then
534 // yes, platform hits the entity, push the entity in the resizing direction
535 u0
:= 1.0-u0
; // how much path left?
536 szdx
:= trunc(szdx
*u0
);
537 szdy
:= trunc(szdy
*u0
);
538 if (szdx
<> 0) or (szdy
<> 0) then
540 // has some path to go, trace the entity
541 trtag
:= (GridTagWall
or GridTagDoor
);
542 // if we're moving down, consider steps too
543 if (szdy
> 0) then trtag
:= trtag
or GridTagStep
;
544 mapGrid
.traceBox(tex
, tey
, px
, py
, pw
, ph
, szdx
, szdy
, trtag
);
548 // second, process platform movement, using te* as entity starting point
549 if sweepAABB(ox
, oy
, nw
, nh
, pdx
, pdy
, tex
, tey
, pw
, ph
, @u0
) then
551 //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]);
552 // yes, platform hits the entity, push the entity in the direction of the platform
553 u0
:= 1.0-u0
; // how much path left?
554 pdx
:= trunc(pdx
*u0
);
555 pdy
:= trunc(pdy
*u0
);
556 //e_LogWritefln(' platsweep; uleft=%s; pd=(%s,%s)', [u0, pdx, pdy]);
557 if (pdx
<> 0) or (pdy
<> 0) then
559 // has some path to go, trace the entity
560 trtag
:= (GridTagWall
or GridTagDoor
);
561 // if we're moving down, consider steps too
562 if (pdy
> 0) then trtag
:= trtag
or GridTagStep
;
563 mapGrid
.traceBox(tex
, tey
, px
, py
, pw
, ph
, pdx
, pdy
, trtag
);
567 // done with entity movement, new coords are in te*
570 result
:= (dx
<> 0) or (dy
<> 0);
571 if not conveyor
and ((tag
and (GridTagWall
or GridTagDoor
)) <> 0) then
573 // check for squashing; as entity cannot be pushed into a wall, check only collision with the platform itself
574 squash
:= g_Collide(tex
, tey
, pw
, ph
, nx
, ny
, nw
, nh
); // squash, if still in platform
578 function monCollect (mon
: TMonster
): Boolean;
580 result
:= false; // don't stop
581 if (monCheckListUsed
>= Length(monCheckList
)) then SetLength(monCheckList
, monCheckListUsed
+128);
582 monCheckList
[monCheckListUsed
] := mon
;
583 Inc(monCheckListUsed
);
587 cx0
, cy0
, cx1
, cy1
, cw
, ch
: Integer;
589 px
, py
, pw
, ph
, pdx
, pdy
: Integer;
595 {$IFDEF ENABLE_CORPSES}
603 actMoveTrig
: Boolean;
604 actSizeTrig
: Boolean;
606 if (not Enabled
) or (Width
< 1) or (Height
< 1) then exit
;
608 if (FCurTexture
>= 0) and (FTextureIDs
[FCurTexture
].AnTex
.IsValid()) and (FAlpha
< 255) then
610 FTextureIDs
[FCurTexture
].AnTex
.Update();
611 FCurFrame
:= FTextureIDs
[FCurTexture
].AnTex
.CurrentFrame
;
612 FCurFrameCount
:= FTextureIDs
[FCurTexture
].AnTex
.CurrentCounter
;
615 if not g_dbgpan_mplat_active
then exit
;
617 if (mOldMovingActive
<> mMovingActive
) then mNeedSend
:= true;
618 mOldMovingActive
:= mMovingActive
;
620 if not mMovingActive
then exit
;
621 if mMovingSpeed
.isZero
and mSizeSpeed
.isZero
then exit
;
623 //TODO: write wall size change processing
628 * collect all monsters and players (aka entities) along the possible platform path
629 * if entity is standing on a platform:
630 * try to move it along the platform path, checking wall collisions
631 * if entity is NOT standing on a platform, but hit with sweeped platform aabb:
633 * if we can't push entity all the way, squash it
640 // the mplat acts as a stationary conveyor belt when it's locked within a movement rect of zero area
641 conveyor
:= (mMovingEnd
.X
= mMovingStart
.X
) and (mMovingEnd
.Y
= mMovingStart
.Y
)
642 and (mMovingEnd
.X
= X
) and (mMovingEnd
.Y
= Y
);
644 nw
:= mpw
+mSizeSpeed
.w
;
645 nh
:= mph
+mSizeSpeed
.h
;
650 nx
+= mMovingSpeed
.X
;
651 ny
+= mMovingSpeed
.Y
;
654 // force network updates only if some sudden change happened
655 // set the flag here, so we can sync affected monsters
656 if not mSizeSpeed
.isZero
and (nw
= mSizeEnd
.w
) and (nh
= mSizeEnd
.h
) then
660 else if ((mMovingSpeed
.X
< 0) and (nx
<= mMovingStart
.X
)) or ((mMovingSpeed
.X
> 0) and (nx
>= mMovingEnd
.X
)) then
664 else if ((mMovingSpeed
.Y
< 0) and (ny
<= mMovingStart
.Y
)) or ((mMovingSpeed
.Y
> 0) and (ny
>= mMovingEnd
.Y
)) then
669 // if pannel disappeared, we don't have to do anything
670 if (nw
> 0) and (nh
> 0) then
681 cx1
:= nmax(ex
, nex
);
682 cy1
:= nmax(ey
, ney
);
691 // process "obstacle" panels
692 if ((tag
and GridTagObstacle
) <> 0) then
694 // temporarily turn off this panel, so it won't interfere with collision checks
695 mapGrid
.proxyEnabled
[proxyId
] := false;
698 for f
:= 0 to High(gPlayers
) do
701 if (plr
= nil) or (not plr
.alive
) then continue
;
702 plr
.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
) then
707 plr
.moveBy(pdx
, pdy
); // this will call `positionChanged()` for us
709 // squash player, if necessary
710 if not g_Game_IsClient
and squash
then plr
.Damage(15000, 0, 0, 0, HIT_TRAP
);
715 for f
:= 0 to High(gGibs
) do
718 if not gib
.alive
then continue
;
719 gib
.getMapBox(px
, py
, pw
, ph
);
720 if not g_Collide(px
, py
, pw
, ph
, cx0
, cy0
, cw
, ch
) then continue
;
721 if tryMPlatMove(px
, py
, pw
, ph
, pdx
, pdy
, squash
, @ontop
) then
724 gib
.moveBy(pdx
, pdy
); // this will call `positionChanged()` for us
729 {$IFDEF ENABLE_CORPSES}
730 // move and push corpses
731 for f
:= 0 to High(gCorpses
) do
734 if (cor
= nil) then continue
;
735 cor
.getMapBox(px
, py
, pw
, ph
);
736 if not g_Collide(px
, py
, pw
, ph
, cx0
, cy0
, cw
, ch
) then continue
;
737 if tryMPlatMove(px
, py
, pw
, ph
, pdx
, pdy
, squash
, @ontop
) then
740 cor
.moveBy(pdx
, pdy
); // this will call `positionChanged()` for us
745 // move and push flags
746 if gGameSettings
.GameMode
= GM_CTF
then
747 for f
:= FLAG_RED
to FLAG_BLUE
do
750 if (flg
.State
in [FLAG_STATE_NONE
, FLAG_STATE_CAPTURED
]) then continue
;
751 px
:= flg
.Obj
.X
+flg
.Obj
.Rect
.X
;
752 py
:= flg
.Obj
.Y
+flg
.Obj
.Rect
.Y
;
753 pw
:= flg
.Obj
.Rect
.Width
;
754 ph
:= flg
.Obj
.Rect
.Height
;
755 if not g_Collide(px
, py
, pw
, ph
, cx0
, cy0
, cw
, ch
) then continue
;
756 if tryMPlatMove(px
, py
, pw
, ph
, pdx
, pdy
, squash
, @ontop
) then
757 if (pdx
<> 0) or (pdy
<> 0) then
759 flg
.Obj
.X
:= flg
.Obj
.X
+ pdx
;
760 flg
.Obj
.Y
:= flg
.Obj
.Y
+ pdy
;
761 flg
.NeedSend
:= true;
765 // move and push items
766 itm
:= g_Items_NextAlive(-1);
771 itm
.getMapBox(px
, py
, pw
, ph
);
772 if g_Collide(px
, py
, pw
, ph
, cx0
, cy0
, cw
, ch
) then
773 if tryMPlatMove(px
, py
, pw
, ph
, pdx
, pdy
, squash
, @ontop
) then
774 itm
.moveBy(pdx
, pdy
); // this will call `positionChanged()` for us
776 itm
:= g_Items_NextAlive(itm
.myId
);
780 monCheckListUsed
:= 0;
781 g_Mons_ForEachAt(cx0
, cy0
, cw
, ch
, monCollect
);
783 // process collected monsters
784 if (monCheckListUsed
> 0) then
786 mpfrid
:= g_Mons_getNewMPlatFrameId();
787 for f
:= 0 to monCheckListUsed
do
789 mon
:= monCheckList
[f
];
790 if (mon
= nil) or (not mon
.alive
) or (mon
.mplatCheckFrameId
= mpfrid
) then continue
;
791 mon
.mplatCheckFrameId
:= mpfrid
;
792 mon
.getMapBox(px
, py
, pw
, ph
);
793 //if not g_Collide(px, py, pw, ph, cx0, cy0, cw, ch) then continue;
794 if tryMPlatMove(px
, py
, pw
, ph
, pdx
, pdy
, squash
) then
797 mon
.moveBy(pdx
, pdy
); // this will call `positionChanged()` for us
798 //???FIXME: do we really need to send monsters over the net?
799 // i don't think so, as dead reckoning should take care of 'em
800 // ok, send new monster position only if platform is going to change it's direction
801 if mNeedSend
then mon
.setDirty();
803 // squash monster, if necessary
804 if not g_Game_IsClient
and squash
then mon
.Damage(15000, 0, 0, 0, HIT_TRAP
);
808 // restore panel state
809 mapGrid
.proxyEnabled
[proxyId
] := true;
824 actMoveTrig
:= false;
825 actSizeTrig
:= false;
827 // `mNeedSend` was set above
830 if not mSizeSpeed
.isZero
and (nw
= mSizeEnd
.w
) and (nh
= mSizeEnd
.h
) then
835 if (nw
< 1) or (nh
< 1) then mMovingActive
:= false; //HACK!
840 // reverse moving direction, if necessary
841 if ((mMovingSpeed
.X
< 0) and (nx
<= mMovingStart
.X
)) or ((mMovingSpeed
.X
> 0) and (nx
>= mMovingEnd
.X
)) then
843 if mMoveOnce
then mMovingActive
:= false else mMovingSpeed
.X
:= -mMovingSpeed
.X
;
847 if ((mMovingSpeed
.Y
< 0) and (ny
<= mMovingStart
.Y
)) or ((mMovingSpeed
.Y
> 0) and (ny
>= mMovingEnd
.Y
)) then
849 if mMoveOnce
then mMovingActive
:= false else mMovingSpeed
.Y
:= -mMovingSpeed
.Y
;
853 if (mOldMovingActive
<> mMovingActive
) then mNeedSend
:= true;
854 mOldMovingActive
:= mMovingActive
;
857 if not g_Game_IsClient
then
859 if actMoveTrig
then g_Triggers_Press(mEndPosTrig
, ACTIVATE_CUSTOM
);
860 if actSizeTrig
then g_Triggers_Press(mEndSizeTrig
, ACTIVATE_CUSTOM
);
863 // some triggers may activate this, don't delay sending
864 //TODO: when triggers will be able to control speed and size, check that here too
865 if (mOldMovingActive
<> mMovingActive
) then mNeedSend
:= true;
866 mOldMovingActive
:= mMovingActive
;
871 procedure TPanel
.SetFrame(Frame
: Integer; Count
: Byte);
873 function ClampInt(X
, A
, B
: Integer): Integer;
876 if X
< A
then Result
:= A
else if X
> B
then Result
:= B
;
880 if Enabled
and (FCurTexture
>= 0) and (FTextureIDs
[FCurTexture
].AnTex
.IsValid()) and (Width
> 0) and (Height
> 0) and (FAlpha
< 255) then
882 FCurFrame
:= ClampInt(Frame
, 0, FTextureIDs
[FCurTexture
].AnTex
.TotalFrames
- 1);
883 FCurFrameCount
:= Count
;
884 FTextureIDs
[FCurTexture
].AnTex
.CurrentFrame
:= FCurFrame
;
885 FTextureIDs
[FCurTexture
].AnTex
.CurrentCounter
:= FCurFrameCount
;
889 procedure TPanel
.NextTexture(AnimLoop
: Byte = 0);
891 Assert(FCurTexture
>= -1, 'FCurTexture < -1');
894 if Length(FTextureIDs
) = 0 then
897 // Òîëüêî îäíà òåêñòóðà:
898 if Length(FTextureIDs
) = 1 then
900 if FCurTexture
= 0 then
906 // Áîëüøå îäíîé òåêñòóðû:
910 // Ñëåäóþùåé íåò - âîçâðàò ê íà÷àëó:
911 if FCurTexture
>= Length(FTextureIDs
) then
915 // Ïåðåêëþ÷èëèñü íà âèäèìóþ àíèì. òåêñòóðó:
916 if (FCurTexture
>= 0) and FTextureIDs
[FCurTexture
].AnTex
.IsValid() then
919 FTextureIDs
[FCurTexture
].AnTex
.Loop
:= True
920 else if AnimLoop
= 2 then
921 FTextureIDs
[FCurTexture
].AnTex
.Loop
:= False;
922 FTextureIDs
[FCurTexture
].AnTex
.Reset();
925 LastAnimLoop
:= AnimLoop
;
928 procedure TPanel
.SetTexture(ID
: Integer; AnimLoop
: Byte = 0);
930 if (ID
>= -1) and (ID
< Length(FTextureIDs
)) then
933 // Ïåðåêëþ÷èëèñü íà âèäèìóþ àíèì. òåêñòóðó:
934 if (FCurTexture
>= 0) and FTextureIDs
[FCurTexture
].AnTex
.IsValid() then
937 FTextureIDs
[FCurTexture
].AnTex
.Loop
:= True
938 else if AnimLoop
= 2 then
939 FTextureIDs
[FCurTexture
].AnTex
.Loop
:= False;
940 FTextureIDs
[FCurTexture
].AnTex
.Reset();
943 LastAnimLoop
:= AnimLoop
;
946 function TPanel
.GetTextureID(): DWORD
;
947 var Texture
: Integer;
949 Result
:= LongWord(TEXTURE_NONE
);
950 if (FCurTexture
>= 0) then
952 Texture
:= FTextureIDs
[FCurTexture
].Texture
;
953 case Textures
[Texture
].TextureName
of
954 TEXTURE_NAME_WATER
: Result
:= DWORD(TEXTURE_SPECIAL_WATER
);
955 TEXTURE_NAME_ACID1
: Result
:= DWORD(TEXTURE_SPECIAL_ACID1
);
956 TEXTURE_NAME_ACID2
: Result
:= DWORD(TEXTURE_SPECIAL_ACID2
);
961 function TPanel
.GetTextureCount(): Integer;
963 Result
:= Length(FTextureIDs
);
964 if Enabled
and (FCurTexture
>= 0) then
965 if (FTextureIDs
[FCurTexture
].AnTex
.IsValid()) and (Width
> 0) and (Height
> 0) and (FAlpha
< 255) then
966 Result
:= Result
+ 100;
969 function TPanel
.CanChangeTexture(): Boolean;
971 Result
:= (GetTextureCount() > 1) or hasTexTrigger
;
975 PAN_SAVE_VERSION
= 1;
977 procedure TPanel
.SaveState (st
: TStream
);
981 if (st
= nil) then exit
;
984 utils
.writeSign(st
, 'PANL');
985 utils
.writeInt(st
, Byte(PAN_SAVE_VERSION
));
986 // Îòêðûòà/çàêðûòà, åñëè äâåðü
987 utils
.writeBool(st
, FEnabled
);
988 // Íàïðàâëåíèå ëèôòà, åñëè ëèôò
989 utils
.writeInt(st
, Byte(FLiftType
));
990 // Íîìåð òåêóùåé òåêñòóðû
991 utils
.writeInt(st
, Integer(FCurTexture
));
992 // Êîîðäèíàòû è ðàçìåð
993 utils
.writeInt(st
, Integer(FX
));
994 utils
.writeInt(st
, Integer(FY
));
995 utils
.writeInt(st
, Word(FWidth
));
996 utils
.writeInt(st
, Word(FHeight
));
997 // Àíèìèðîâàíà ëè òåêóùàÿ òåêñòóðà
998 anim
:= (FCurTexture
>= 0) and (FTextureIDs
[FCurTexture
].AnTex
.IsValid());
999 utils
.writeBool(st
, anim
);
1000 // Åñëè äà - ñîõðàíÿåì àíèìàöèþ
1001 if anim
then FTextureIDs
[FCurTexture
].AnTex
.SaveState(st
, FAlpha
, FBlending
);
1003 // moving platform state
1004 utils
.writeInt(st
, Integer(mMovingSpeed
.X
));
1005 utils
.writeInt(st
, Integer(mMovingSpeed
.Y
));
1006 utils
.writeInt(st
, Integer(mMovingStart
.X
));
1007 utils
.writeInt(st
, Integer(mMovingStart
.Y
));
1008 utils
.writeInt(st
, Integer(mMovingEnd
.X
));
1009 utils
.writeInt(st
, Integer(mMovingEnd
.Y
));
1011 utils
.writeInt(st
, Integer(mSizeSpeed
.w
));
1012 utils
.writeInt(st
, Integer(mSizeSpeed
.h
));
1013 utils
.writeInt(st
, Integer(mSizeEnd
.w
));
1014 utils
.writeInt(st
, Integer(mSizeEnd
.h
));
1016 utils
.writeBool(st
, mMovingActive
);
1017 utils
.writeBool(st
, mMoveOnce
);
1019 utils
.writeInt(st
, Integer(mEndPosTrig
));
1020 utils
.writeInt(st
, Integer(mEndSizeTrig
));
1024 procedure TPanel
.LoadState (st
: TStream
);
1026 if (st
= nil) then exit
;
1029 if not utils
.checkSign(st
, 'PANL') then raise XStreamError
.create('wrong panel signature');
1030 if (utils
.readByte(st
) <> PAN_SAVE_VERSION
) then raise XStreamError
.create('wrong panel version');
1031 // Îòêðûòà/çàêðûòà, åñëè äâåðü
1032 FEnabled
:= utils
.readBool(st
);
1033 // Íàïðàâëåíèå ëèôòà, åñëè ëèôò
1034 FLiftType
:= utils
.readByte(st
);
1035 // Íîìåð òåêóùåé òåêñòóðû
1036 FCurTexture
:= utils
.readLongInt(st
);
1037 // Êîîðäèíàòû è ðàçìåð
1038 FX
:= utils
.readLongInt(st
);
1039 FY
:= utils
.readLongInt(st
);
1042 FWidth
:= utils
.readWord(st
);
1043 FHeight
:= utils
.readWord(st
);
1046 // Àíèìèðîâàííàÿ ëè òåêóùàÿ òåêñòóðà
1047 if utils
.readBool(st
) then
1049 // Åñëè äà - çàãðóæàåì àíèìàöèþ
1050 Assert((FCurTexture
>= 0) and (FTextureIDs
[FCurTexture
].AnTex
.IsValid()), 'TPanel.LoadState: No animation object');
1051 FTextureIDs
[FCurTexture
].AnTex
.LoadState(st
, FAlpha
, FBlending
);
1054 // moving platform state
1055 mMovingSpeed
.X
:= utils
.readLongInt(st
);
1056 mMovingSpeed
.Y
:= utils
.readLongInt(st
);
1057 mMovingStart
.X
:= utils
.readLongInt(st
);
1058 mMovingStart
.Y
:= utils
.readLongInt(st
);
1059 mMovingEnd
.X
:= utils
.readLongInt(st
);
1060 mMovingEnd
.Y
:= utils
.readLongInt(st
);
1062 mSizeSpeed
.w
:= utils
.readLongInt(st
);
1063 mSizeSpeed
.h
:= utils
.readLongInt(st
);
1064 mSizeEnd
.w
:= utils
.readLongInt(st
);
1065 mSizeEnd
.h
:= utils
.readLongInt(st
);
1067 mMovingActive
:= utils
.readBool(st
);
1068 mMoveOnce
:= utils
.readBool(st
);
1070 mEndPosTrig
:= utils
.readLongInt(st
);
1071 mEndSizeTrig
:= utils
.readLongInt(st
);
1074 //mapGrid.proxyEnabled[proxyId] := FEnabled; // done in g_map.pas