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 record
27 Texture
: Cardinal; // Textures[Texture]
30 ATextureID
= array of record
31 Texture
: Cardinal; // Textures[Texture]
34 True: (AnTex
: TAnimationState
);
38 TPanel
= Class (TObject
)
42 mGUID
: Integer; // will be assigned in "g_map.pas"
45 FTextureIDs
: ATextureID
;
46 mMovingSpeed
: TDFPoint
;
47 mMovingStart
: TDFPoint
;
49 mMovingActive
: Boolean;
52 mOldMovingActive
: Boolean;
58 mEndSizeTrig
: Integer;
60 mNeedSend
: Boolean; // for network
63 function getx1 (): Integer; inline;
64 function gety1 (): Integer; inline;
65 function getvisvalid (): Boolean; inline;
67 function getMovingSpeedX (): Integer; inline;
68 procedure setMovingSpeedX (v
: Integer); inline;
69 function getMovingSpeedY (): Integer; inline;
70 procedure setMovingSpeedY (v
: Integer); inline;
72 function getMovingStartX (): Integer; inline;
73 procedure setMovingStartX (v
: Integer); inline;
74 function getMovingStartY (): Integer; inline;
75 procedure setMovingStartY (v
: Integer); inline;
77 function getMovingEndX (): Integer; inline;
78 procedure setMovingEndX (v
: Integer); inline;
79 function getMovingEndY (): Integer; inline;
80 procedure setMovingEndY (v
: Integer); inline;
82 function getSizeSpeedX (): Integer; inline;
83 procedure setSizeSpeedX (v
: Integer); inline;
84 function getSizeSpeedY (): Integer; inline;
85 procedure setSizeSpeedY (v
: Integer); inline;
87 function getSizeEndX (): Integer; inline;
88 procedure setSizeEndX (v
: Integer); inline;
89 function getSizeEndY (): Integer; inline;
90 procedure setSizeEndY (v
: Integer); inline;
93 FCurTexture
: Integer; // Íîìåð òåêóùåé òåêñòóðû
97 FOldX
, FOldY
: Integer;
98 FWidth
, FHeight
: Word;
105 // sorry, there fields are public to allow setting 'em in g_map; this should be fixed later
106 // for now, PLEASE, don't modify 'em, or all hell will break loose
107 arrIdx
: Integer; // index in one of internal arrays; sorry
108 tag
: Integer; // used in coldets and such; sorry; see g_map.GridTagXXX
109 proxyId
: Integer; // proxy id in map grid (DO NOT USE!)
110 mapId
: AnsiString; // taken directly from map file; dunno why it is here
111 hasTexTrigger
: Boolean; // HACK: true when there's a trigger than can change my texture
113 constructor Create(PanelRec
: TDynRecord
;
114 AddTextures
: TAddTextureArray
;
116 var Textures
: TLevelTextureArray
; aguid
: Integer);
117 destructor Destroy(); override;
120 procedure SetFrame(Frame
: Integer; Count
: Byte);
121 procedure NextTexture(AnimLoop
: Byte = 0);
122 procedure SetTexture(ID
: Integer; AnimLoop
: Byte = 0);
123 function GetTextureID(): Cardinal;
124 function GetTextureCount(): Integer;
125 function CanChangeTexture(): Boolean;
127 procedure SaveState (st
: TStream
);
128 procedure LoadState (st
: TStream
);
130 procedure positionChanged (); inline;
132 function getIsGBack (): Boolean; inline; // gRenderBackgrounds
133 function getIsGStep (): Boolean; inline; // gSteps
134 function getIsGWall (): Boolean; inline; // gWalls
135 function getIsGAcid1 (): Boolean; inline; // gAcid1
136 function getIsGAcid2 (): Boolean; inline; // gAcid2
137 function getIsGWater (): Boolean; inline; // gWater
138 function getIsGFore (): Boolean; inline; // gRenderForegrounds
139 function getIsGLift (): Boolean; inline; // gLifts
140 function getIsGBlockMon (): Boolean; inline; // gBlockMon
143 function gncNeedSend (): Boolean; inline;
144 procedure setDirty (); inline; // why `dirty`? 'cause i may introduce property `needSend` later
147 property visvalid
: Boolean read getvisvalid
; // panel is "visvalid" when it's width and height are positive
150 property guid
: Integer read mGUID
; // will be assigned in "g_map.pas"
151 property x0
: Integer read FX
;
152 property y0
: Integer read FY
;
153 property x1
: Integer read getx1
; // inclusive!
154 property y1
: Integer read gety1
; // inclusive!
155 property x
: Integer read FX write FX
;
156 property y
: Integer read FY write FY
;
157 property width
: Word read FWidth write FWidth
;
158 property height
: Word read FHeight write FHeight
;
159 property oldX
: Integer read FOldX
;
160 property oldY
: Integer read FOldY
;
161 property oldWidth
: Word read FOldW
;
162 property oldHeight
: Word read FOldH
;
163 property panelType
: Word read FPanelType write FPanelType
;
164 property enabled
: Boolean read FEnabled write FEnabled
;
165 property door
: Boolean read FDoor write FDoor
;
166 property liftType
: Byte read FLiftType write FLiftType
;
167 property lastAnimLoop
: Byte read FLastAnimLoop write FLastAnimLoop
;
169 property movingSpeedX
: Integer read getMovingSpeedX write setMovingSpeedX
;
170 property movingSpeedY
: Integer read getMovingSpeedY write setMovingSpeedY
;
171 property movingStartX
: Integer read getMovingStartX write setMovingStartX
;
172 property movingStartY
: Integer read getMovingStartY write setMovingStartY
;
173 property movingEndX
: Integer read getMovingEndX write setMovingEndX
;
174 property movingEndY
: Integer read getMovingEndY write setMovingEndY
;
175 property movingActive
: Boolean read mMovingActive write mMovingActive
;
176 property moveOnce
: Boolean read mMoveOnce write mMoveOnce
;
178 property sizeSpeedX
: Integer read getSizeSpeedX write setSizeSpeedX
;
179 property sizeSpeedY
: Integer read getSizeSpeedY write setSizeSpeedY
;
180 property sizeEndX
: Integer read getSizeEndX write setSizeEndX
;
181 property sizeEndY
: Integer read getSizeEndY write setSizeEndY
;
183 property isGBack
: Boolean read getIsGBack
;
184 property isGStep
: Boolean read getIsGStep
;
185 property isGWall
: Boolean read getIsGWall
;
186 property isGAcid1
: Boolean read getIsGAcid1
;
187 property isGAcid2
: Boolean read getIsGAcid2
;
188 property isGWater
: Boolean read getIsGWater
;
189 property isGFore
: Boolean read getIsGFore
;
190 property isGLift
: Boolean read getIsGLift
;
191 property isGBlockMon
: Boolean read getIsGBlockMon
;
194 property Alpha
: Byte read FAlpha
;
195 property Blending
: Boolean read FBlending
;
196 property TextureIDs
: ATextureID read FTextureIDs
;
199 property movingSpeed
: TDFPoint read mMovingSpeed write mMovingSpeed
;
200 property movingStart
: TDFPoint read mMovingStart write mMovingStart
;
201 property movingEnd
: TDFPoint read mMovingEnd write mMovingEnd
;
203 property sizeSpeed
: TDFSize read mSizeSpeed write mSizeSpeed
;
204 property sizeEnd
: TDFSize read mSizeEnd write mSizeEnd
;
206 property endPosTrigId
: Integer read mEndPosTrig write mEndPosTrig
;
207 property endSizeTrigId
: Integer read mEndSizeTrig write mEndSizeTrig
;
210 TPanelArray
= Array of TPanel
;
219 g_dbgpan_mplat_active
: Boolean = {$IF DEFINED(D2F_DEBUG)}true{$ELSE}true{$ENDIF};
220 g_dbgpan_mplat_step
: Boolean = false; // one step, and stop
229 g_basic
, g_map
, g_game
, g_weapons
, g_triggers
, g_items
,
230 g_console
, g_language
, g_monsters
, g_player
, g_grid
, e_log
, geom
, utils
, xstreams
234 PANEL_SIGNATURE
= $4C4E4150; // 'PANL'
238 function FindTextureByName (const name
: String): Integer;
242 if Textures
<> nil then
244 for i
:= 0 to High(Textures
) do
246 if Textures
[i
].TextureName
= name
then
255 constructor TPanel
.Create(PanelRec
: TDynRecord
;
256 AddTextures
: TAddTextureArray
;
258 var Textures
: TLevelTextureArray
; aguid
: Integer);
267 Width
:= PanelRec
.Width
;
268 Height
:= PanelRec
.Height
;
277 mapId
:= PanelRec
.id
;
280 mMovingSpeed
:= PanelRec
.moveSpeed
;
281 mMovingStart
:= PanelRec
.moveStart
;
282 mMovingEnd
:= PanelRec
.moveEnd
;
283 mMovingActive
:= PanelRec
['move_active'].value
;
284 mOldMovingActive
:= mMovingActive
;
285 mMoveOnce
:= PanelRec
.moveOnce
;
287 mSizeSpeed
:= PanelRec
.sizeSpeed
;
288 mSizeEnd
:= PanelRec
.sizeEnd
;
290 mEndPosTrig
:= PanelRec
.endPosTrig
;
291 mEndSizeTrig
:= PanelRec
.endSizeTrig
;
296 PanelType
:= PanelRec
.PanelType
;
299 LiftType
:= LIFTTYPE_UP
;
300 hasTexTrigger
:= False;
303 PANEL_OPENDOOR
: begin Enabled
:= False; Door
:= True; end;
304 PANEL_CLOSEDOOR
: Door
:= True;
305 PANEL_LIFTUP
: LiftType
:= LIFTTYPE_UP
; //???
306 PANEL_LIFTDOWN
: LiftType
:= LIFTTYPE_DOWN
;
307 PANEL_LIFTLEFT
: LiftType
:= LIFTTYPE_LEFT
;
308 PANEL_LIFTRIGHT
: LiftType
:= LIFTTYPE_RIGHT
;
312 if ByteBool(PanelRec
.Flags
and PANEL_FLAG_HIDE
) then
314 SetLength(FTextureIDs
, 0);
318 // Ïàíåëè, íå èñïîëüçóþùèå òåêñòóðû:
319 if ByteBool(PanelType
and
324 PANEL_BLOCKMON
)) then
326 SetLength(FTextureIDs
, 0);
331 // Åñëè ýòî æèäêîñòü áåç òåêñòóðû - ñïåöòåêñòóðó:
332 if WordBool(PanelType
and (PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
)) and
333 (not ByteBool(PanelRec
.Flags
and PANEL_FLAG_WATERTEXTURES
)) then
335 SetLength(FTextureIDs
, 1);
336 FTextureIDs
[0].Anim
:= False;
337 case PanelRec
.PanelType
of
338 PANEL_WATER
: FTextureIDs
[0].Texture
:= FindTextureByName(TEXTURE_NAME_WATER
);
339 PANEL_ACID1
: FTextureIDs
[0].Texture
:= FindTextureByName(TEXTURE_NAME_ACID1
);
340 PANEL_ACID2
: FTextureIDs
[0].Texture
:= FindTextureByName(TEXTURE_NAME_ACID2
);
346 SetLength(FTextureIDs
, Length(AddTextures
));
351 if CurTex
>= Length(FTextureIDs
) then
352 FCurTexture
:= Length(FTextureIDs
) - 1
354 FCurTexture
:= CurTex
;
356 for i
:= 0 to Length(FTextureIDs
)-1 do
358 FTextureIDs
[i
].Texture
:= AddTextures
[i
].Texture
;
359 FTextureIDs
[i
].Anim
:= Textures
[AddTextures
[i
].Texture
].FramesCount
> 0;
360 if FTextureIDs
[i
].Anim
then
361 begin // Àíèìèðîâàííàÿ òåêñòóðà
362 FTextureIDs
[i
].AnTex
:= TAnimationState
.Create(True, Textures
[AddTextures
[i
].Texture
].Speed
, Textures
[AddTextures
[i
].Texture
].FramesCount
);
366 // Òåêñòóð íåñêîëüêî - íóæíî ñîõðàíÿòü òåêóùóþ:
367 //if Length(FTextureIDs) > 1 then SaveIt := True;
369 if (PanelRec
.TextureRec
= nil) then tnum
:= -1 else tnum
:= PanelRec
.tagInt
;
370 if (tnum
< 0) then tnum
:= Length(Textures
);
372 // Åñëè íå ñïåöòåêñòóðà, òî çàäàåì ðàçìåðû:
373 if ({PanelRec.TextureNum}tnum
> High(Textures
)) then
375 e_WriteLog(Format('WTF?! tnum is out of limits! (%d : %d)', [tnum
, High(Textures
)]), TMsgType
.Warning
);
377 FBlending
:= ByteBool(0);
379 else if not g_Map_IsSpecialTexture(Textures
[{PanelRec.TextureNum}tnum
].TextureName
) then
381 FAlpha
:= PanelRec
.Alpha
;
382 FBlending
:= ByteBool(PanelRec
.Flags
and PANEL_FLAG_BLENDING
);
386 destructor TPanel
.Destroy();
390 for i
:= 0 to High(FTextureIDs
) do
391 if FTextureIDs
[i
].Anim
then
392 FTextureIDs
[i
].AnTex
.Free();
393 SetLength(FTextureIDs
, 0);
398 function TPanel
.getx1 (): Integer; inline; begin result
:= X
+Width
-1; end;
399 function TPanel
.gety1 (): Integer; inline; begin result
:= Y
+Height
-1; end;
400 function TPanel
.getvisvalid (): Boolean; inline; begin result
:= (Width
> 0) and (Height
> 0); end;
402 function TPanel
.getMovingSpeedX (): Integer; inline; begin result
:= mMovingSpeed
.X
; end;
403 procedure TPanel
.setMovingSpeedX (v
: Integer); inline; begin mMovingSpeed
.X
:= v
; end;
404 function TPanel
.getMovingSpeedY (): Integer; inline; begin result
:= mMovingSpeed
.Y
; end;
405 procedure TPanel
.setMovingSpeedY (v
: Integer); inline; begin mMovingSpeed
.Y
:= v
; end;
407 function TPanel
.getMovingStartX (): Integer; inline; begin result
:= mMovingStart
.X
; end;
408 procedure TPanel
.setMovingStartX (v
: Integer); inline; begin mMovingStart
.X
:= v
; end;
409 function TPanel
.getMovingStartY (): Integer; inline; begin result
:= mMovingStart
.Y
; end;
410 procedure TPanel
.setMovingStartY (v
: Integer); inline; begin mMovingStart
.Y
:= v
; end;
412 function TPanel
.getMovingEndX (): Integer; inline; begin result
:= mMovingEnd
.X
; end;
413 procedure TPanel
.setMovingEndX (v
: Integer); inline; begin mMovingEnd
.X
:= v
; end;
414 function TPanel
.getMovingEndY (): Integer; inline; begin result
:= mMovingEnd
.Y
; end;
415 procedure TPanel
.setMovingEndY (v
: Integer); inline; begin mMovingEnd
.Y
:= v
; end;
417 function TPanel
.getSizeSpeedX (): Integer; inline; begin result
:= mSizeSpeed
.w
; end;
418 procedure TPanel
.setSizeSpeedX (v
: Integer); inline; begin mSizeSpeed
.w
:= v
; end;
419 function TPanel
.getSizeSpeedY (): Integer; inline; begin result
:= mSizeSpeed
.h
; end;
420 procedure TPanel
.setSizeSpeedY (v
: Integer); inline; begin mSizeSpeed
.h
:= v
; end;
422 function TPanel
.getSizeEndX (): Integer; inline; begin result
:= mSizeEnd
.w
; end;
423 procedure TPanel
.setSizeEndX (v
: Integer); inline; begin mSizeEnd
.w
:= v
; end;
424 function TPanel
.getSizeEndY (): Integer; inline; begin result
:= mSizeEnd
.h
; end;
425 procedure TPanel
.setSizeEndY (v
: Integer); inline; begin mSizeEnd
.h
:= v
; end;
427 function TPanel
.getIsGBack (): Boolean; inline; begin result
:= ((tag
and GridTagBack
) <> 0); end;
428 function TPanel
.getIsGStep (): Boolean; inline; begin result
:= ((tag
and GridTagStep
) <> 0); end;
429 function TPanel
.getIsGWall (): Boolean; inline; begin result
:= ((tag
and (GridTagWall
or GridTagDoor
)) <> 0); end;
430 function TPanel
.getIsGAcid1 (): Boolean; inline; begin result
:= ((tag
and GridTagAcid1
) <> 0); end;
431 function TPanel
.getIsGAcid2 (): Boolean; inline; begin result
:= ((tag
and GridTagAcid2
) <> 0); end;
432 function TPanel
.getIsGWater (): Boolean; inline; begin result
:= ((tag
and GridTagWater
) <> 0); end;
433 function TPanel
.getIsGFore (): Boolean; inline; begin result
:= ((tag
and GridTagFore
) <> 0); end;
434 function TPanel
.getIsGLift (): Boolean; inline; begin result
:= ((tag
and GridTagLift
) <> 0); end;
435 function TPanel
.getIsGBlockMon (): Boolean; inline; begin result
:= ((tag
and GridTagBlockMon
) <> 0); end;
437 function TPanel
.gncNeedSend (): Boolean; inline; begin result
:= mNeedSend
; mNeedSend
:= false; end;
438 procedure TPanel
.setDirty (); inline; begin mNeedSend
:= true; end;
440 procedure TPanel
.positionChanged (); inline;
442 px
, py
, pw
, ph
: Integer;
444 if (proxyId
>= 0) then
446 mapGrid
.getBodyDims(proxyId
, px
, py
, pw
, ph
);
447 if (px
<> x
) or (py
<> y
) or (pw
<> Width
) or (ph
<> Height
) then
450 e_LogWritefln('panel moved: arridx=%s; guid=%s; proxyid=%s; old:(%s,%s)-(%sx%s); new:(%s,%s)-(%sx%s)',
451 [arrIdx, mGUID, proxyId, px, py, pw, ph, x, y, width, height]);
454 g_Mark(px
, py
, pw
, ph
, MARK_WALL
, false);
456 if (Width
< 1) or (Height
< 1) then
458 mapGrid
.proxyEnabled
[proxyId
] := false;
462 mapGrid
.proxyEnabled
[proxyId
] := Enabled
;
463 if (pw
<> Width
) or (ph
<> Height
) then
465 //writeln('panel resize!');
466 mapGrid
.moveResizeBody(proxyId
, X
, Y
, Width
, Height
)
470 mapGrid
.moveBody(proxyId
, X
, Y
);
473 g_Mark(X
, Y
, Width
, Height
, MARK_WALL
);
482 monCheckList
: array of TMonster
= nil;
483 monCheckListUsed
: Integer = 0;
485 procedure TPanel
.Update();
488 nx
, ny
, nw
, nh
: Integer;
489 ex
, ey
, nex
, ney
: Integer;
493 // return `true` if we should move by dx,dy
494 function tryMPlatMove (px
, py
, pw
, ph
: Integer; out dx
, dy
: Integer; out squash
: Boolean; ontop
: PBoolean=nil): Boolean;
505 pdx
:= mMovingSpeed
.X
;
506 pdy
:= mMovingSpeed
.Y
;
507 // standing on the platform?
510 if (ontop
<> nil) then ontop
^ := true;
511 // yes, move with it; but skip steps (no need to process size change here, 'cause platform top cannot be changed with it)
512 mapGrid
.traceBox(tex
, tey
, px
, py
, pw
, ph
, pdx
, pdy
, (GridTagWall
or GridTagDoor
));
516 if (ontop
<> nil) then ontop
^ := false;
517 // not standing on the platform: trace platform to see if it hits the entity
518 // first, process size change (as we cannot sweeptest both move and size change)
519 // but we don't have to check for pushing if the panel is shrinking
522 if (szdx
> 0) or (szdy
> 0) then
524 // ignore shrinking dimension
525 if (szdx
< 0) then szdx
:= 0;
526 if (szdy
< 0) then szdy
:= 0;
527 // move platform by szd* back, and check for szd* movement
528 if sweepAABB(ox
-szdx
, oy
-szdy
, nw
, nh
, szdx
, szdy
, px
, py
, pw
, ph
, @u0
) then
530 // yes, platform hits the entity, push the entity in the resizing direction
531 u0
:= 1.0-u0
; // how much path left?
532 szdx
:= trunc(szdx
*u0
);
533 szdy
:= trunc(szdy
*u0
);
534 if (szdx
<> 0) or (szdy
<> 0) then
536 // has some path to go, trace the entity
537 trtag
:= (GridTagWall
or GridTagDoor
);
538 // if we're moving down, consider steps too
539 if (szdy
> 0) then trtag
:= trtag
or GridTagStep
;
540 mapGrid
.traceBox(tex
, tey
, px
, py
, pw
, ph
, szdx
, szdy
, trtag
);
544 // second, process platform movement, using te* as entity starting point
545 if sweepAABB(ox
, oy
, nw
, nh
, pdx
, pdy
, tex
, tey
, pw
, ph
, @u0
) then
547 //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]);
548 // yes, platform hits the entity, push the entity in the direction of the platform
549 u0
:= 1.0-u0
; // how much path left?
550 pdx
:= trunc(pdx
*u0
);
551 pdy
:= trunc(pdy
*u0
);
552 //e_LogWritefln(' platsweep; uleft=%s; pd=(%s,%s)', [u0, pdx, pdy]);
553 if (pdx
<> 0) or (pdy
<> 0) then
555 // has some path to go, trace the entity
556 trtag
:= (GridTagWall
or GridTagDoor
);
557 // if we're moving down, consider steps too
558 if (pdy
> 0) then trtag
:= trtag
or GridTagStep
;
559 mapGrid
.traceBox(tex
, tey
, px
, py
, pw
, ph
, pdx
, pdy
, trtag
);
563 // done with entity movement, new coords are in te*
566 result
:= (dx
<> 0) or (dy
<> 0);
567 if not conveyor
and ((tag
and (GridTagWall
or GridTagDoor
)) <> 0) then
569 // check for squashing; as entity cannot be pushed into a wall, check only collision with the platform itself
570 squash
:= g_Collide(tex
, tey
, pw
, ph
, nx
, ny
, nw
, nh
); // squash, if still in platform
574 function monCollect (mon
: TMonster
): Boolean;
576 result
:= false; // don't stop
577 if (monCheckListUsed
>= Length(monCheckList
)) then SetLength(monCheckList
, monCheckListUsed
+128);
578 monCheckList
[monCheckListUsed
] := mon
;
579 Inc(monCheckListUsed
);
583 cx0
, cy0
, cx1
, cy1
, cw
, ch
: Integer;
585 px
, py
, pw
, ph
, pdx
, pdy
: Integer;
595 actMoveTrig
: Boolean;
596 actSizeTrig
: Boolean;
598 if (not Enabled
) or (Width
< 1) or (Height
< 1) then exit
;
600 if (FCurTexture
>= 0) and
601 (FTextureIDs
[FCurTexture
].Anim
) and
602 (FTextureIDs
[FCurTexture
].AnTex
<> nil) and
605 FTextureIDs
[FCurTexture
].AnTex
.Update();
606 FCurFrame
:= FTextureIDs
[FCurTexture
].AnTex
.CurrentFrame
;
607 FCurFrameCount
:= FTextureIDs
[FCurTexture
].AnTex
.CurrentCounter
;
610 if not g_dbgpan_mplat_active
then exit
;
612 if (mOldMovingActive
<> mMovingActive
) then mNeedSend
:= true;
613 mOldMovingActive
:= mMovingActive
;
615 if not mMovingActive
then exit
;
616 if mMovingSpeed
.isZero
and mSizeSpeed
.isZero
then exit
;
618 //TODO: write wall size change processing
623 * collect all monsters and players (aka entities) along the possible platform path
624 * if entity is standing on a platform:
625 * try to move it along the platform path, checking wall collisions
626 * if entity is NOT standing on a platform, but hit with sweeped platform aabb:
628 * if we can't push entity all the way, squash it
635 // the mplat acts as a stationary conveyor belt when it's locked within a movement rect of zero area
636 conveyor
:= (mMovingEnd
.X
= mMovingStart
.X
) and (mMovingEnd
.Y
= mMovingStart
.Y
)
637 and (mMovingEnd
.X
= X
) and (mMovingEnd
.Y
= Y
);
639 nw
:= mpw
+mSizeSpeed
.w
;
640 nh
:= mph
+mSizeSpeed
.h
;
645 nx
+= mMovingSpeed
.X
;
646 ny
+= mMovingSpeed
.Y
;
649 // force network updates only if some sudden change happened
650 // set the flag here, so we can sync affected monsters
651 if not mSizeSpeed
.isZero
and (nw
= mSizeEnd
.w
) and (nh
= mSizeEnd
.h
) then
655 else if ((mMovingSpeed
.X
< 0) and (nx
<= mMovingStart
.X
)) or ((mMovingSpeed
.X
> 0) and (nx
>= mMovingEnd
.X
)) then
659 else if ((mMovingSpeed
.Y
< 0) and (ny
<= mMovingStart
.Y
)) or ((mMovingSpeed
.Y
> 0) and (ny
>= mMovingEnd
.Y
)) then
664 // if pannel disappeared, we don't have to do anything
665 if (nw
> 0) and (nh
> 0) then
676 cx1
:= nmax(ex
, nex
);
677 cy1
:= nmax(ey
, ney
);
686 // process "obstacle" panels
687 if ((tag
and GridTagObstacle
) <> 0) then
689 // temporarily turn off this panel, so it won't interfere with collision checks
690 mapGrid
.proxyEnabled
[proxyId
] := false;
693 for f
:= 0 to High(gPlayers
) do
696 if (plr
= nil) or (not plr
.alive
) then continue
;
697 plr
.getMapBox(px
, py
, pw
, ph
);
698 if not g_Collide(px
, py
, pw
, ph
, cx0
, cy0
, cw
, ch
) then continue
;
699 if tryMPlatMove(px
, py
, pw
, ph
, pdx
, pdy
, squash
) then
702 plr
.moveBy(pdx
, pdy
); // this will call `positionChanged()` for us
704 // squash player, if necessary
705 if not g_Game_IsClient
and squash
then plr
.Damage(15000, 0, 0, 0, HIT_TRAP
);
709 for f
:= 0 to High(gGibs
) do
712 if not gib
.alive
then continue
;
713 gib
.getMapBox(px
, py
, pw
, ph
);
714 if not g_Collide(px
, py
, pw
, ph
, cx0
, cy0
, cw
, ch
) then continue
;
715 if tryMPlatMove(px
, py
, pw
, ph
, pdx
, pdy
, squash
, @ontop
) then
718 gib
.moveBy(pdx
, pdy
); // this will call `positionChanged()` for us
722 // move and push corpses
723 for f
:= 0 to High(gCorpses
) do
726 if (cor
= nil) then continue
;
727 cor
.getMapBox(px
, py
, pw
, ph
);
728 if not g_Collide(px
, py
, pw
, ph
, cx0
, cy0
, cw
, ch
) then continue
;
729 if tryMPlatMove(px
, py
, pw
, ph
, pdx
, pdy
, squash
, @ontop
) then
732 cor
.moveBy(pdx
, pdy
); // this will call `positionChanged()` for us
736 // move and push flags
737 if gGameSettings
.GameMode
= GM_CTF
then
738 for f
:= FLAG_RED
to FLAG_BLUE
do
741 if (flg
.State
in [FLAG_STATE_NONE
, FLAG_STATE_CAPTURED
]) then continue
;
742 px
:= flg
.Obj
.X
+flg
.Obj
.Rect
.X
;
743 py
:= flg
.Obj
.Y
+flg
.Obj
.Rect
.Y
;
744 pw
:= flg
.Obj
.Rect
.Width
;
745 ph
:= flg
.Obj
.Rect
.Height
;
746 if not g_Collide(px
, py
, pw
, ph
, cx0
, cy0
, cw
, ch
) then continue
;
747 if tryMPlatMove(px
, py
, pw
, ph
, pdx
, pdy
, squash
, @ontop
) then
748 if (pdx
<> 0) or (pdy
<> 0) then
750 flg
.Obj
.X
:= flg
.Obj
.X
+ pdx
;
751 flg
.Obj
.Y
:= flg
.Obj
.Y
+ pdy
;
752 flg
.NeedSend
:= true;
756 // move and push items
757 itm
:= g_Items_NextAlive(-1);
762 itm
.getMapBox(px
, py
, pw
, ph
);
763 if g_Collide(px
, py
, pw
, ph
, cx0
, cy0
, cw
, ch
) then
764 if tryMPlatMove(px
, py
, pw
, ph
, pdx
, pdy
, squash
, @ontop
) then
765 itm
.moveBy(pdx
, pdy
); // this will call `positionChanged()` for us
767 itm
:= g_Items_NextAlive(itm
.myId
);
771 monCheckListUsed
:= 0;
772 g_Mons_ForEachAt(cx0
, cy0
, cw
, ch
, monCollect
);
774 // process collected monsters
775 if (monCheckListUsed
> 0) then
777 mpfrid
:= g_Mons_getNewMPlatFrameId();
778 for f
:= 0 to monCheckListUsed
do
780 mon
:= monCheckList
[f
];
781 if (mon
= nil) or (not mon
.alive
) or (mon
.mplatCheckFrameId
= mpfrid
) then continue
;
782 mon
.mplatCheckFrameId
:= mpfrid
;
783 mon
.getMapBox(px
, py
, pw
, ph
);
784 //if not g_Collide(px, py, pw, ph, cx0, cy0, cw, ch) then continue;
785 if tryMPlatMove(px
, py
, pw
, ph
, pdx
, pdy
, squash
) then
788 mon
.moveBy(pdx
, pdy
); // this will call `positionChanged()` for us
789 //???FIXME: do we really need to send monsters over the net?
790 // i don't think so, as dead reckoning should take care of 'em
791 // ok, send new monster position only if platform is going to change it's direction
792 if mNeedSend
then mon
.setDirty();
794 // squash monster, if necessary
795 if not g_Game_IsClient
and squash
then mon
.Damage(15000, 0, 0, 0, HIT_TRAP
);
799 // restore panel state
800 mapGrid
.proxyEnabled
[proxyId
] := true;
815 actMoveTrig
:= false;
816 actSizeTrig
:= false;
818 // `mNeedSend` was set above
821 if not mSizeSpeed
.isZero
and (nw
= mSizeEnd
.w
) and (nh
= mSizeEnd
.h
) then
826 if (nw
< 1) or (nh
< 1) then mMovingActive
:= false; //HACK!
831 // reverse moving direction, if necessary
832 if ((mMovingSpeed
.X
< 0) and (nx
<= mMovingStart
.X
)) or ((mMovingSpeed
.X
> 0) and (nx
>= mMovingEnd
.X
)) then
834 if mMoveOnce
then mMovingActive
:= false else mMovingSpeed
.X
:= -mMovingSpeed
.X
;
838 if ((mMovingSpeed
.Y
< 0) and (ny
<= mMovingStart
.Y
)) or ((mMovingSpeed
.Y
> 0) and (ny
>= mMovingEnd
.Y
)) then
840 if mMoveOnce
then mMovingActive
:= false else mMovingSpeed
.Y
:= -mMovingSpeed
.Y
;
844 if (mOldMovingActive
<> mMovingActive
) then mNeedSend
:= true;
845 mOldMovingActive
:= mMovingActive
;
848 if not g_Game_IsClient
then
850 if actMoveTrig
then g_Triggers_Press(mEndPosTrig
, ACTIVATE_CUSTOM
);
851 if actSizeTrig
then g_Triggers_Press(mEndSizeTrig
, ACTIVATE_CUSTOM
);
854 // some triggers may activate this, don't delay sending
855 //TODO: when triggers will be able to control speed and size, check that here too
856 if (mOldMovingActive
<> mMovingActive
) then mNeedSend
:= true;
857 mOldMovingActive
:= mMovingActive
;
862 procedure TPanel
.SetFrame(Frame
: Integer; Count
: Byte);
864 function ClampInt(X
, A
, B
: Integer): Integer;
867 if X
< A
then Result
:= A
else if X
> B
then Result
:= B
;
871 if Enabled
and (FCurTexture
>= 0) and
872 (FTextureIDs
[FCurTexture
].Anim
) and
873 (FTextureIDs
[FCurTexture
].AnTex
<> nil) and
874 (Width
> 0) and (Height
> 0) and (FAlpha
< 255) then
876 FCurFrame
:= ClampInt(Frame
, 0, FTextureIDs
[FCurTexture
].AnTex
.TotalFrames
- 1);
877 FCurFrameCount
:= Count
;
878 FTextureIDs
[FCurTexture
].AnTex
.CurrentFrame
:= FCurFrame
;
879 FTextureIDs
[FCurTexture
].AnTex
.CurrentCounter
:= FCurFrameCount
;
883 procedure TPanel
.NextTexture(AnimLoop
: Byte = 0);
885 Assert(FCurTexture
>= -1, 'FCurTexture < -1');
888 if Length(FTextureIDs
) = 0 then
891 // Òîëüêî îäíà òåêñòóðà:
892 if Length(FTextureIDs
) = 1 then
894 if FCurTexture
= 0 then
900 // Áîëüøå îäíîé òåêñòóðû:
904 // Ñëåäóþùåé íåò - âîçâðàò ê íà÷àëó:
905 if FCurTexture
>= Length(FTextureIDs
) then
909 // Ïåðåêëþ÷èëèñü íà âèäèìóþ àíèì. òåêñòóðó:
910 if (FCurTexture
>= 0) and FTextureIDs
[FCurTexture
].Anim
then
912 if (FTextureIDs
[FCurTexture
].AnTex
= nil) then
914 g_FatalError(_lc
[I_GAME_ERROR_SWITCH_TEXTURE
]);
919 FTextureIDs
[FCurTexture
].AnTex
.Loop
:= True
922 FTextureIDs
[FCurTexture
].AnTex
.Loop
:= False;
924 FTextureIDs
[FCurTexture
].AnTex
.Reset();
927 LastAnimLoop
:= AnimLoop
;
930 procedure TPanel
.SetTexture(ID
: Integer; AnimLoop
: Byte = 0);
932 if (ID
>= -1) and (ID
< Length(FTextureIDs
)) then
935 // Ïåðåêëþ÷èëèñü íà âèäèìóþ àíèì. òåêñòóðó:
936 if (FCurTexture
>= 0) and FTextureIDs
[FCurTexture
].Anim
then
938 if (FTextureIDs
[FCurTexture
].AnTex
= nil) then
940 g_FatalError(_lc
[I_GAME_ERROR_SWITCH_TEXTURE
]);
945 FTextureIDs
[FCurTexture
].AnTex
.Loop
:= True
948 FTextureIDs
[FCurTexture
].AnTex
.Loop
:= False;
950 FTextureIDs
[FCurTexture
].AnTex
.Reset();
953 LastAnimLoop
:= AnimLoop
;
956 function TPanel
.GetTextureID(): DWORD
;
957 var Texture
: Integer;
959 Result
:= LongWord(TEXTURE_NONE
);
960 if (FCurTexture
>= 0) then
962 Texture
:= FTextureIDs
[FCurTexture
].Texture
;
963 case Textures
[Texture
].TextureName
of
964 TEXTURE_NAME_WATER
: Result
:= DWORD(TEXTURE_SPECIAL_WATER
);
965 TEXTURE_NAME_ACID1
: Result
:= DWORD(TEXTURE_SPECIAL_ACID1
);
966 TEXTURE_NAME_ACID2
: Result
:= DWORD(TEXTURE_SPECIAL_ACID2
);
971 function TPanel
.GetTextureCount(): Integer;
973 Result
:= Length(FTextureIDs
);
974 if Enabled
and (FCurTexture
>= 0) then
975 if (FTextureIDs
[FCurTexture
].Anim
) and
976 (FTextureIDs
[FCurTexture
].AnTex
<> nil) and
977 (Width
> 0) and (Height
> 0) and (FAlpha
< 255) then
978 Result
:= Result
+ 100;
981 function TPanel
.CanChangeTexture(): Boolean;
983 Result
:= (GetTextureCount() > 1) or hasTexTrigger
;
987 PAN_SAVE_VERSION
= 1;
989 procedure TPanel
.SaveState (st
: TStream
);
993 if (st
= nil) then exit
;
996 utils
.writeSign(st
, 'PANL');
997 utils
.writeInt(st
, Byte(PAN_SAVE_VERSION
));
998 // Îòêðûòà/çàêðûòà, åñëè äâåðü
999 utils
.writeBool(st
, FEnabled
);
1000 // Íàïðàâëåíèå ëèôòà, åñëè ëèôò
1001 utils
.writeInt(st
, Byte(FLiftType
));
1002 // Íîìåð òåêóùåé òåêñòóðû
1003 utils
.writeInt(st
, Integer(FCurTexture
));
1004 // Êîîðäèíàòû è ðàçìåð
1005 utils
.writeInt(st
, Integer(FX
));
1006 utils
.writeInt(st
, Integer(FY
));
1007 utils
.writeInt(st
, Word(FWidth
));
1008 utils
.writeInt(st
, Word(FHeight
));
1009 // Àíèìèðîâàíà ëè òåêóùàÿ òåêñòóðà
1010 if (FCurTexture
>= 0) and (FTextureIDs
[FCurTexture
].Anim
) then
1012 assert(FTextureIDs
[FCurTexture
].AnTex
<> nil, 'TPanel.SaveState: No animation object');
1019 utils
.writeBool(st
, anim
);
1020 // Åñëè äà - ñîõðàíÿåì àíèìàöèþ
1021 if anim
then FTextureIDs
[FCurTexture
].AnTex
.SaveState(st
, FAlpha
, FBlending
);
1023 // moving platform state
1024 utils
.writeInt(st
, Integer(mMovingSpeed
.X
));
1025 utils
.writeInt(st
, Integer(mMovingSpeed
.Y
));
1026 utils
.writeInt(st
, Integer(mMovingStart
.X
));
1027 utils
.writeInt(st
, Integer(mMovingStart
.Y
));
1028 utils
.writeInt(st
, Integer(mMovingEnd
.X
));
1029 utils
.writeInt(st
, Integer(mMovingEnd
.Y
));
1031 utils
.writeInt(st
, Integer(mSizeSpeed
.w
));
1032 utils
.writeInt(st
, Integer(mSizeSpeed
.h
));
1033 utils
.writeInt(st
, Integer(mSizeEnd
.w
));
1034 utils
.writeInt(st
, Integer(mSizeEnd
.h
));
1036 utils
.writeBool(st
, mMovingActive
);
1037 utils
.writeBool(st
, mMoveOnce
);
1039 utils
.writeInt(st
, Integer(mEndPosTrig
));
1040 utils
.writeInt(st
, Integer(mEndSizeTrig
));
1044 procedure TPanel
.LoadState (st
: TStream
);
1046 if (st
= nil) then exit
;
1049 if not utils
.checkSign(st
, 'PANL') then raise XStreamError
.create('wrong panel signature');
1050 if (utils
.readByte(st
) <> PAN_SAVE_VERSION
) then raise XStreamError
.create('wrong panel version');
1051 // Îòêðûòà/çàêðûòà, åñëè äâåðü
1052 FEnabled
:= utils
.readBool(st
);
1053 // Íàïðàâëåíèå ëèôòà, åñëè ëèôò
1054 FLiftType
:= utils
.readByte(st
);
1055 // Íîìåð òåêóùåé òåêñòóðû
1056 FCurTexture
:= utils
.readLongInt(st
);
1057 // Êîîðäèíàòû è ðàçìåð
1058 FX
:= utils
.readLongInt(st
);
1059 FY
:= utils
.readLongInt(st
);
1062 FWidth
:= utils
.readWord(st
);
1063 FHeight
:= utils
.readWord(st
);
1066 // Àíèìèðîâàííàÿ ëè òåêóùàÿ òåêñòóðà
1067 if utils
.readBool(st
) then
1069 // Åñëè äà - çàãðóæàåì àíèìàöèþ
1070 Assert((FCurTexture
>= 0) and
1071 (FTextureIDs
[FCurTexture
].Anim
) and
1072 (FTextureIDs
[FCurTexture
].AnTex
<> nil),
1073 'TPanel.LoadState: No animation object');
1074 FTextureIDs
[FCurTexture
].AnTex
.LoadState(st
, FAlpha
, FBlending
);
1077 // moving platform state
1078 mMovingSpeed
.X
:= utils
.readLongInt(st
);
1079 mMovingSpeed
.Y
:= utils
.readLongInt(st
);
1080 mMovingStart
.X
:= utils
.readLongInt(st
);
1081 mMovingStart
.Y
:= utils
.readLongInt(st
);
1082 mMovingEnd
.X
:= utils
.readLongInt(st
);
1083 mMovingEnd
.Y
:= utils
.readLongInt(st
);
1085 mSizeSpeed
.w
:= utils
.readLongInt(st
);
1086 mSizeSpeed
.h
:= utils
.readLongInt(st
);
1087 mSizeEnd
.w
:= utils
.readLongInt(st
);
1088 mSizeEnd
.h
:= utils
.readLongInt(st
);
1090 mMovingActive
:= utils
.readBool(st
);
1091 mMoveOnce
:= utils
.readBool(st
);
1093 mEndPosTrig
:= utils
.readLongInt(st
);
1094 mEndSizeTrig
:= utils
.readLongInt(st
);
1097 //mapGrid.proxyEnabled[proxyId] := FEnabled; // done in g_map.pas