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, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 {$INCLUDE ../shared/a_modes.inc}
23 MAPDEF
, BinEditor
, g_textures
, xdynrec
;
26 TAddTextureArray
= Array of
32 TPanel
= Class (TObject
)
36 mGUID
: Integer; // will be assigned in "g_map.pas"
44 False: (Tex
: Cardinal);
45 True: (AnTex
: TAnimation
);
48 mMovingSpeed
: TDFPoint
;
49 mMovingStart
: TDFPoint
;
51 mMovingActive
: Boolean;
54 function getx1 (): Integer; inline;
55 function gety1 (): Integer; inline;
56 function getvisvalid (): Boolean; inline;
58 function getMovingSpeedX (): Integer; inline;
59 procedure setMovingSpeedX (v
: Integer); inline;
60 function getMovingSpeedY (): Integer; inline;
61 procedure setMovingSpeedY (v
: Integer); inline;
63 function getMovingStartX (): Integer; inline;
64 procedure setMovingStartX (v
: Integer); inline;
65 function getMovingStartY (): Integer; inline;
66 procedure setMovingStartY (v
: Integer); inline;
68 function getMovingEndX (): Integer; inline;
69 procedure setMovingEndX (v
: Integer); inline;
70 function getMovingEndY (): Integer; inline;
71 procedure setMovingEndY (v
: Integer); inline;
74 FCurTexture
: Integer; // Íîìåð òåêóùåé òåêñòóðû
78 FWidth
, FHeight
: Word;
80 FSaveIt
: Boolean; // Ñîõðàíÿòü ïðè SaveState?
86 // sorry, there fields are public to allow setting 'em in g_map; this should be fixed later
87 // for now, PLEASE, don't modify 'em, or all hell will break loose
88 arrIdx
: Integer; // index in one of internal arrays; sorry
89 tag
: Integer; // used in coldets and such; sorry; see g_map.GridTagXXX
90 proxyId
: Integer; // proxy id in map grid (DO NOT USE!)
91 mapId
: AnsiString; // taken directly from map file; dunno why it is here
93 constructor Create(PanelRec
: TDynRecord
;
94 AddTextures
: TAddTextureArray
;
96 var Textures
: TLevelTextureArray
; aguid
: Integer);
97 destructor Destroy(); override;
100 procedure DrawShadowVolume(lightX
: Integer; lightY
: Integer; radius
: Integer);
102 procedure SetFrame(Frame
: Integer; Count
: Byte);
103 procedure NextTexture(AnimLoop
: Byte = 0);
104 procedure SetTexture(ID
: Integer; AnimLoop
: Byte = 0);
105 function GetTextureID(): Cardinal;
106 function GetTextureCount(): Integer;
108 procedure SaveState(var Mem
: TBinMemoryWriter
);
109 procedure LoadState(var Mem
: TBinMemoryReader
);
111 procedure positionChanged (); inline;
113 function getIsGBack (): Boolean; inline; // gRenderBackgrounds
114 function getIsGStep (): Boolean; inline; // gSteps
115 function getIsGWall (): Boolean; inline; // gWalls
116 function getIsGAcid1 (): Boolean; inline; // gAcid1
117 function getIsGAcid2 (): Boolean; inline; // gAcid2
118 function getIsGWater (): Boolean; inline; // gWater
119 function getIsGFore (): Boolean; inline; // gRenderForegrounds
120 function getIsGLift (): Boolean; inline; // gLifts
121 function getIsGBlockMon (): Boolean; inline; // gBlockMon
124 property visvalid
: Boolean read getvisvalid
; // panel is "visvalid" when it's width and height are positive
127 property guid
: Integer read mGUID
; // will be assigned in "g_map.pas"
128 property x0
: Integer read FX
;
129 property y0
: Integer read FY
;
130 property x1
: Integer read getx1
; // inclusive!
131 property y1
: Integer read gety1
; // inclusive!
132 property x
: Integer read FX write FX
;
133 property y
: Integer read FY write FY
;
134 property width
: Word read FWidth write FWidth
;
135 property height
: Word read FHeight write FHeight
;
136 property panelType
: Word read FPanelType write FPanelType
;
137 property saveIt
: Boolean read FSaveIt write FSaveIt
; // Ñîõðàíÿòü ïðè SaveState?
138 property enabled
: Boolean read FEnabled write FEnabled
; // Ñîõðàíÿòü ïðè SaveState?
139 property door
: Boolean read FDoor write FDoor
; // Ñîõðàíÿòü ïðè SaveState?
140 property moved
: Boolean read FMoved write FMoved
; // Ñîõðàíÿòü ïðè SaveState?
141 property liftType
: Byte read FLiftType write FLiftType
; // Ñîõðàíÿòü ïðè SaveState?
142 property lastAnimLoop
: Byte read FLastAnimLoop write FLastAnimLoop
; // Ñîõðàíÿòü ïðè SaveState?
144 property movingSpeedX
: Integer read getMovingSpeedX write setMovingSpeedX
;
145 property movingSpeedY
: Integer read getMovingSpeedY write setMovingSpeedY
;
146 property movingStartX
: Integer read getMovingStartX write setMovingStartX
;
147 property movingStartY
: Integer read getMovingStartY write setMovingStartY
;
148 property movingEndX
: Integer read getMovingEndX write setMovingEndX
;
149 property movingEndY
: Integer read getMovingEndY write setMovingEndY
;
150 property movingActive
: Boolean read mMovingActive write mMovingActive
;
152 property isGBack
: Boolean read getIsGBack
;
153 property isGStep
: Boolean read getIsGStep
;
154 property isGWall
: Boolean read getIsGWall
;
155 property isGAcid1
: Boolean read getIsGAcid1
;
156 property isGAcid2
: Boolean read getIsGAcid2
;
157 property isGWater
: Boolean read getIsGWater
;
158 property isGFore
: Boolean read getIsGFore
;
159 property isGLift
: Boolean read getIsGLift
;
160 property isGBlockMon
: Boolean read getIsGBlockMon
;
163 property movingSpeed
: TDFPoint read mMovingSpeed write mMovingSpeed
;
164 property movingStart
: TDFPoint read mMovingStart write mMovingStart
;
165 property movingEnd
: TDFPoint read mMovingEnd write mMovingEnd
;
168 TPanelArray
= Array of TPanel
;
173 SysUtils
, g_basic
, g_map
, g_game
, g_gfx
, e_graphics
, g_weapons
,
174 g_console
, g_language
, g_monsters
, g_player
, e_log
, GL
;
177 PANEL_SIGNATURE
= $4C4E4150; // 'PANL'
181 constructor TPanel
.Create(PanelRec
: TDynRecord
;
182 AddTextures
: TAddTextureArray
;
184 var Textures
: TLevelTextureArray
; aguid
: Integer);
190 Width
:= PanelRec
.Width
;
191 Height
:= PanelRec
.Height
;
199 mapId
:= PanelRec
.id
;
202 mMovingSpeed
:= PanelRec
.moveSpeed
;
203 mMovingStart
:= PanelRec
.moveStart
;
204 mMovingEnd
:= PanelRec
.moveEnd
;
205 mMovingActive
:= PanelRec
['move_active'].varvalue
;
208 PanelType
:= PanelRec
.PanelType
;
246 if ByteBool(PanelRec
.Flags
and PANEL_FLAG_HIDE
) then
248 SetLength(FTextureIDs
, 0);
252 // Ïàíåëè, íå èñïîëüçóþùèå òåêñòóðû:
253 if ByteBool(PanelType
and
258 PANEL_BLOCKMON
)) then
260 SetLength(FTextureIDs
, 0);
265 // Åñëè ýòî æèäêîñòü áåç òåêñòóðû - ñïåöòåêñòóðó:
266 if WordBool(PanelType
and (PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
)) and
267 (not ByteBool(PanelRec
.Flags
and PANEL_FLAG_WATERTEXTURES
)) then
269 SetLength(FTextureIDs
, 1);
270 FTextureIDs
[0].Anim
:= False;
272 case PanelRec
.PanelType
of
274 FTextureIDs
[0].Tex
:= LongWord(TEXTURE_SPECIAL_WATER
);
276 FTextureIDs
[0].Tex
:= LongWord(TEXTURE_SPECIAL_ACID1
);
278 FTextureIDs
[0].Tex
:= LongWord(TEXTURE_SPECIAL_ACID2
);
285 SetLength(FTextureIDs
, Length(AddTextures
));
290 if CurTex
>= Length(FTextureIDs
) then
291 FCurTexture
:= Length(FTextureIDs
) - 1
293 FCurTexture
:= CurTex
;
295 for i
:= 0 to Length(FTextureIDs
)-1 do
297 FTextureIDs
[i
].Anim
:= AddTextures
[i
].Anim
;
298 if FTextureIDs
[i
].Anim
then
299 begin // Àíèìèðîâàííàÿ òåêñòóðà
300 FTextureIDs
[i
].AnTex
:=
301 TAnimation
.Create(Textures
[AddTextures
[i
].Texture
].FramesID
,
302 True, Textures
[AddTextures
[i
].Texture
].Speed
);
303 FTextureIDs
[i
].AnTex
.Blending
:= ByteBool(PanelRec
.Flags
and PANEL_FLAG_BLENDING
);
304 FTextureIDs
[i
].AnTex
.Alpha
:= PanelRec
.Alpha
;
308 begin // Îáû÷íàÿ òåêñòóðà
309 FTextureIDs
[i
].Tex
:= Textures
[AddTextures
[i
].Texture
].TextureID
;
313 // Òåêñòóð íåñêîëüêî - íóæíî ñîõðàíÿòü òåêóùóþ:
314 if Length(FTextureIDs
) > 1 then
317 // Åñëè íå ñïåöòåêñòóðà, òî çàäàåì ðàçìåðû:
318 if PanelRec
.TextureNum
> High(Textures
) then
320 e_WriteLog(Format('WTF?! PanelRec.TextureNum is out of limits! (%d : %d)', [PanelRec
.TextureNum
, High(Textures
)]), MSG_FATALERROR
);
324 FBlending
:= ByteBool(0);
326 else if not g_Map_IsSpecialTexture(Textures
[PanelRec
.TextureNum
].TextureName
) then
328 FTextureWidth
:= Textures
[PanelRec
.TextureNum
].Width
;
329 FTextureHeight
:= Textures
[PanelRec
.TextureNum
].Height
;
330 FAlpha
:= PanelRec
.Alpha
;
331 FBlending
:= ByteBool(PanelRec
.Flags
and PANEL_FLAG_BLENDING
);
335 destructor TPanel
.Destroy();
339 for i
:= 0 to High(FTextureIDs
) do
340 if FTextureIDs
[i
].Anim
then
341 FTextureIDs
[i
].AnTex
.Free();
342 SetLength(FTextureIDs
, 0);
347 function TPanel
.getx1 (): Integer; inline; begin result
:= X
+Width
-1; end;
348 function TPanel
.gety1 (): Integer; inline; begin result
:= Y
+Height
-1; end;
349 function TPanel
.getvisvalid (): Boolean; inline; begin result
:= (Width
> 0) and (Height
> 0); end;
351 function TPanel
.getMovingSpeedX (): Integer; inline; begin result
:= mMovingSpeed
.X
; end;
352 procedure TPanel
.setMovingSpeedX (v
: Integer); inline; begin mMovingSpeed
.X
:= v
; end;
353 function TPanel
.getMovingSpeedY (): Integer; inline; begin result
:= mMovingSpeed
.Y
; end;
354 procedure TPanel
.setMovingSpeedY (v
: Integer); inline; begin mMovingSpeed
.Y
:= v
; end;
356 function TPanel
.getMovingStartX (): Integer; inline; begin result
:= mMovingStart
.X
; end;
357 procedure TPanel
.setMovingStartX (v
: Integer); inline; begin mMovingStart
.X
:= v
; end;
358 function TPanel
.getMovingStartY (): Integer; inline; begin result
:= mMovingStart
.Y
; end;
359 procedure TPanel
.setMovingStartY (v
: Integer); inline; begin mMovingStart
.Y
:= v
; end;
361 function TPanel
.getMovingEndX (): Integer; inline; begin result
:= mMovingEnd
.X
; end;
362 procedure TPanel
.setMovingEndX (v
: Integer); inline; begin mMovingEnd
.X
:= v
; end;
363 function TPanel
.getMovingEndY (): Integer; inline; begin result
:= mMovingEnd
.Y
; end;
364 procedure TPanel
.setMovingEndY (v
: Integer); inline; begin mMovingEnd
.Y
:= v
; end;
366 function TPanel
.getIsGBack (): Boolean; inline; begin result
:= ((tag
and GridTagBack
) <> 0); end;
367 function TPanel
.getIsGStep (): Boolean; inline; begin result
:= ((tag
and GridTagStep
) <> 0); end;
368 function TPanel
.getIsGWall (): Boolean; inline; begin result
:= ((tag
and (GridTagWall
or GridTagDoor
)) <> 0); end;
369 function TPanel
.getIsGAcid1 (): Boolean; inline; begin result
:= ((tag
and GridTagAcid1
) <> 0); end;
370 function TPanel
.getIsGAcid2 (): Boolean; inline; begin result
:= ((tag
and GridTagAcid2
) <> 0); end;
371 function TPanel
.getIsGWater (): Boolean; inline; begin result
:= ((tag
and GridTagWater
) <> 0); end;
372 function TPanel
.getIsGFore (): Boolean; inline; begin result
:= ((tag
and GridTagFore
) <> 0); end;
373 function TPanel
.getIsGLift (): Boolean; inline; begin result
:= ((tag
and GridTagLift
) <> 0); end;
374 function TPanel
.getIsGBlockMon (): Boolean; inline; begin result
:= ((tag
and GridTagBlockMon
) <> 0); end;
376 procedure TPanel
.Draw();
382 if {Enabled and} (FCurTexture
>= 0) and
383 (Width
> 0) and (Height
> 0) and (FAlpha
< 255) and
384 ((g_dbg_scale
<> 1.0) or g_Collide(X
, Y
, Width
, Height
, sX
, sY
, sWidth
, sHeight
)) then
386 if FTextureIDs
[FCurTexture
].Anim
then
387 begin // Àíèìèðîâàííàÿ òåêñòóðà
388 if FTextureIDs
[FCurTexture
].AnTex
= nil then
391 for xx
:= 0 to (Width
div FTextureWidth
)-1 do
392 for yy
:= 0 to (Height
div FTextureHeight
)-1 do
393 FTextureIDs
[FCurTexture
].AnTex
.Draw(
394 X
+ xx
*FTextureWidth
,
395 Y
+ yy
*FTextureHeight
, M_NONE
);
398 begin // Îáû÷íàÿ òåêñòóðà
399 case FTextureIDs
[FCurTexture
].Tex
of
400 LongWord(TEXTURE_SPECIAL_WATER
):
401 e_DrawFillQuad(X
, Y
, X
+Width
-1, Y
+Height
-1,
402 0, 0, 255, 0, B_FILTER
);
403 LongWord(TEXTURE_SPECIAL_ACID1
):
404 e_DrawFillQuad(X
, Y
, X
+Width
-1, Y
+Height
-1,
405 0, 128, 0, 0, B_FILTER
);
406 LongWord(TEXTURE_SPECIAL_ACID2
):
407 e_DrawFillQuad(X
, Y
, X
+Width
-1, Y
+Height
-1,
408 128, 0, 0, 0, B_FILTER
);
409 LongWord(TEXTURE_NONE
):
410 if g_Texture_Get('NOTEXTURE', NoTextureID
) then
412 e_GetTextureSize(NoTextureID
, @NW
, @NH
);
413 e_DrawFill(NoTextureID
, X
, Y
, Width
div NW
, Height
div NH
,
417 xx
:= X
+ (Width
div 2);
418 yy
:= Y
+ (Height
div 2);
419 e_DrawFillQuad(X
, Y
, xx
, yy
,
421 e_DrawFillQuad(xx
, Y
, X
+Width
-1, yy
,
423 e_DrawFillQuad(X
, yy
, xx
, Y
+Height
-1,
425 e_DrawFillQuad(xx
, yy
, X
+Width
-1, Y
+Height
-1,
430 e_DrawFill(FTextureIDs
[FCurTexture
].Tex
, X
, Y
,
431 Width
div FTextureWidth
,
432 Height
div FTextureHeight
,
433 FAlpha
, True, FBlending
);
439 procedure TPanel
.DrawShadowVolume(lightX
: Integer; lightY
: Integer; radius
: Integer);
440 procedure extrude (x
: Integer; y
: Integer);
442 glVertex2i(x
+(x
-lightX
)*500, y
+(y
-lightY
)*500);
443 //e_WriteLog(Format(' : (%d,%d)', [x+(x-lightX)*300, y+(y-lightY)*300]), MSG_WARNING);
446 procedure drawLine (x0
: Integer; y0
: Integer; x1
: Integer; y1
: Integer);
448 // does this side facing the light?
449 if ((x1
-x0
)*(lightY
-y0
)-(lightX
-x0
)*(y1
-y0
) >= 0) then exit
;
450 //e_WriteLog(Format('lightpan: (%d,%d)-(%d,%d)', [x0, y0, x1, y1]), MSG_WARNING);
451 // this edge is facing the light, extrude and draw it
459 if radius
< 4 then exit
;
460 if Enabled
and (FCurTexture
>= 0) and (Width
> 0) and (Height
> 0) and (FAlpha
< 255) and g_Collide(X
, Y
, Width
, Height
, sX
, sY
, sWidth
, sHeight
) then
462 if not FTextureIDs
[FCurTexture
].Anim
then
464 case FTextureIDs
[FCurTexture
].Tex
of
465 LongWord(TEXTURE_SPECIAL_WATER
): exit
;
466 LongWord(TEXTURE_SPECIAL_ACID1
): exit
;
467 LongWord(TEXTURE_SPECIAL_ACID2
): exit
;
468 LongWord(TEXTURE_NONE
): exit
;
471 if (X
+Width
< lightX
-radius
) then exit
;
472 if (Y
+Height
< lightY
-radius
) then exit
;
473 if (X
> lightX
+radius
) then exit
;
474 if (Y
> lightY
+radius
) then exit
;
475 //e_DrawFill(FTextureIDs[FCurTexture].Tex, X, Y, Width div FTextureWidth, Height div FTextureHeight, FAlpha, True, FBlending);
478 drawLine(x
, y
, x
+width
, y
); // top
479 drawLine(x
+width
, y
, x
+width
, y
+height
); // right
480 drawLine(x
+width
, y
+height
, x
, y
+height
); // bottom
481 drawLine(x
, y
+height
, x
, y
); // left
487 procedure TPanel
.positionChanged (); inline;
489 px
, py
, pw
, ph
: Integer;
491 if (proxyId
>= 0) then
493 monsGrid
.getBodyDims(proxyId
, px
, py
, pw
, ph
);
494 if (px
<> x
) or (py
<> y
) or (pw
<> Width
) or (ph
<> Height
) then
496 g_Mark(px
, py
, pw
, ph
, MARK_WALL
, false);
497 if (pw
<> Width
) or (ph
<> Height
) then mapGrid
.moveResizeBody(proxyId
, X
, Y
, Width
, Height
)
498 else mapGrid
.moveBody(proxyId
, X
, Y
);
499 g_Mark(X
, Y
, Width
, Height
, MARK_WALL
);
506 monMoveList
: array of TMonster
= nil;
507 monMoveListUsed
: Integer = 0;
509 procedure TPanel
.Update();
513 function doPush (px
, py
, pw
, ph
: Integer; out dx
, dy
: Integer): Boolean;
515 result
:= g_Collide(px
, py
, pw
, ph
, nx
, ny
, Width
, Height
);
519 if (mMovingSpeed
.X
< 0) then dx
:= nx
-(px
+pw
)
520 else if (mMovingSpeed
.X
> 0) then dx
:= (nx
+Width
)-px
522 if (mMovingSpeed
.Y
< 0) then dy
:= ny
-(py
+ph
)
523 else if (mMovingSpeed
.Y
> 0) then dy
:= (ny
+Height
)-py
533 function monMove (mon
: TMonster
): Boolean;
535 result
:= false; // don't stop
536 //mon.GameX := mon.GameX+mMovingSpeed.X;
537 //mon.GameY := mon.GameY+mMovingSpeed.Y;
538 mon
.setPosition(mon
.GameX
+mMovingSpeed
.X
, mon
.GameY
+mMovingSpeed
.Y
, false); // we can't call `positionChanged()` in grid callback
539 if (monMoveListUsed
>= Length(monMoveList
)) then SetLength(monMoveList
, monMoveListUsed
+64);
540 monMoveList
[monMoveListUsed
] := mon
;
541 Inc(monMoveListUsed
);
544 function monPush (mon
: TMonster
): Boolean;
546 px
, py
, pw
, ph
, dx
, dy
: Integer;
548 result
:= false; // don't stop
549 mon
.getMapBox(px
, py
, pw
, ph
);
550 if doPush(px
, py
, pw
, ph
, dx
, dy
) then
552 //mon.GameX := mon.GameX+dx;
553 //mon.GameY := mon.GameY+dy;
554 mon
.setPosition(mon
.GameX
+dx
, mon
.GameY
+dy
, false); // we can't call `positionChanged()` in grid callback
555 if (monMoveListUsed
>= Length(monMoveList
)) then SetLength(monMoveList
, monMoveListUsed
+64);
556 monMoveList
[monMoveListUsed
] := mon
;
557 Inc(monMoveListUsed
);
561 procedure plrMove (plr
: TPlayer
);
563 px
, py
, pw
, ph
, dx
, dy
: Integer;
565 if (plr
= nil) then exit
;
566 plr
.getMapBox(px
, py
, pw
, ph
);
570 if doPush(px
, py
, pw
, ph
, dx
, dy
) then
572 plr
.GameX
:= plr
.GameX
+dx
;
573 plr
.GameY
:= plr
.GameY
+dy
;
574 plr
.positionChanged();
575 // check if we're squashed
578 plr
.getMapBox(px
, py
, pw
, ph
);
579 if g_Map_CollidePanel(px
, py
, pw
, ph
, (PANEL_WALL
or PANEL_OPENDOOR
or PANEL_CLOSEDOOR
)) then
581 plr
.Damage(15000, 0, 0, 0, HIT_TRAP
);
587 if (px
+pw
<= X
) then exit
;
588 if (px
>= X
+Width
) then exit
;
589 plr
.GameX
:= plr
.GameX
+mMovingSpeed
.X
;
590 plr
.GameY
:= plr
.GameY
+mMovingSpeed
.Y
;
591 plr
.positionChanged();
597 px
, py
, pw
, ph
: Integer;
599 if Enabled
and (FCurTexture
>= 0) and
600 (FTextureIDs
[FCurTexture
].Anim
) and
601 (FTextureIDs
[FCurTexture
].AnTex
<> nil) and
602 (Width
> 0) and (Height
> 0) and (FAlpha
< 255) then
604 FTextureIDs
[FCurTexture
].AnTex
.Update();
605 FCurFrame
:= FTextureIDs
[FCurTexture
].AnTex
.CurrentFrame
;
606 FCurFrameCount
:= FTextureIDs
[FCurTexture
].AnTex
.CurrentCounter
;
609 if mMovingActive
and (not mMovingSpeed
.isZero
) then
611 monMoveListUsed
:= 0;
612 nx
:= X
+mMovingSpeed
.X
;
613 ny
:= Y
+mMovingSpeed
.Y
;
614 // move monsters on lifts
615 g_Mons_ForEachAt(X
, Y
-1, Width
, 1, monMove
);
621 g_Mons_ForEachAt(nx
, ny
, Width
, Height
, monPush
);
622 // move and push players
623 for f
:= 0 to High(gPlayers
) do plrMove(gPlayers
[f
]);
624 // reverse moving direction, if necessary
625 if (mMovingSpeed
.X
< 0) and (nx
<= mMovingStart
.X
) then mMovingSpeed
.X
:= -mMovingSpeed
.X
626 else if (mMovingSpeed
.X
> 0) and (nx
>= mMovingEnd
.X
) then mMovingSpeed
.X
:= -mMovingSpeed
.X
;
627 if (mMovingSpeed
.Y
< 0) and (ny
<= mMovingStart
.Y
) then mMovingSpeed
.Y
:= -mMovingSpeed
.Y
628 else if (mMovingSpeed
.Y
> 0) and (ny
>= mMovingEnd
.Y
) then mMovingSpeed
.Y
:= -mMovingSpeed
.Y
;
629 // notify moved monsters about their movement
630 for f
:= 0 to monMoveListUsed
-1 do
632 monMoveList
[f
].positionChanged();
634 for f
:= 0 to monMoveListUsed
-1 do
636 mon
:= monMoveList
[f
];
637 // check if it is squashed
640 mon
.getMapBox(px
, py
, pw
, ph
);
641 if g_Map_CollidePanel(px
, py
, pw
, ph
, (PANEL_WALL
or PANEL_OPENDOOR
or PANEL_CLOSEDOOR
)) then
643 mon
.Damage(15000, 0, 0, 0, HIT_TRAP
);
650 procedure TPanel
.SetFrame(Frame
: Integer; Count
: Byte);
652 function ClampInt(X
, A
, B
: Integer): Integer;
655 if X
< A
then Result
:= A
else if X
> B
then Result
:= B
;
659 if Enabled
and (FCurTexture
>= 0) and
660 (FTextureIDs
[FCurTexture
].Anim
) and
661 (FTextureIDs
[FCurTexture
].AnTex
<> nil) and
662 (Width
> 0) and (Height
> 0) and (FAlpha
< 255) then
664 FCurFrame
:= ClampInt(Frame
, 0, FTextureIDs
[FCurTexture
].AnTex
.TotalFrames
);
665 FCurFrameCount
:= Count
;
666 FTextureIDs
[FCurTexture
].AnTex
.CurrentFrame
:= FCurFrame
;
667 FTextureIDs
[FCurTexture
].AnTex
.CurrentCounter
:= FCurFrameCount
;
671 procedure TPanel
.NextTexture(AnimLoop
: Byte = 0);
673 Assert(FCurTexture
>= -1, 'FCurTexture < -1');
676 if Length(FTextureIDs
) = 0 then
679 // Òîëüêî îäíà òåêñòóðà:
680 if Length(FTextureIDs
) = 1 then
682 if FCurTexture
= 0 then
688 // Áîëüøå îäíîé òåêñòóðû:
692 // Ñëåäóþùåé íåò - âîçâðàò ê íà÷àëó:
693 if FCurTexture
>= Length(FTextureIDs
) then
697 // Ïåðåêëþ÷èëèñü íà âèäèìóþ àíèì. òåêñòóðó:
698 if (FCurTexture
>= 0) and FTextureIDs
[FCurTexture
].Anim
then
700 if (FTextureIDs
[FCurTexture
].AnTex
= nil) then
702 g_FatalError(_lc
[I_GAME_ERROR_SWITCH_TEXTURE
]);
707 FTextureIDs
[FCurTexture
].AnTex
.Loop
:= True
710 FTextureIDs
[FCurTexture
].AnTex
.Loop
:= False;
712 FTextureIDs
[FCurTexture
].AnTex
.Reset();
715 LastAnimLoop
:= AnimLoop
;
718 procedure TPanel
.SetTexture(ID
: Integer; AnimLoop
: Byte = 0);
721 if Length(FTextureIDs
) = 0 then
724 // Òîëüêî îäíà òåêñòóðà:
725 if Length(FTextureIDs
) = 1 then
727 if (ID
= 0) or (ID
= -1) then
731 // Áîëüøå îäíîé òåêñòóðû:
733 if (ID
>= -1) and (ID
<= High(FTextureIDs
)) then
737 // Ïåðåêëþ÷èëèñü íà âèäèìóþ àíèì. òåêñòóðó:
738 if (FCurTexture
>= 0) and FTextureIDs
[FCurTexture
].Anim
then
740 if (FTextureIDs
[FCurTexture
].AnTex
= nil) then
742 g_FatalError(_lc
[I_GAME_ERROR_SWITCH_TEXTURE
]);
747 FTextureIDs
[FCurTexture
].AnTex
.Loop
:= True
750 FTextureIDs
[FCurTexture
].AnTex
.Loop
:= False;
752 FTextureIDs
[FCurTexture
].AnTex
.Reset();
755 LastAnimLoop
:= AnimLoop
;
758 function TPanel
.GetTextureID(): DWORD
;
760 Result
:= LongWord(TEXTURE_NONE
);
762 if (FCurTexture
>= 0) then
764 if FTextureIDs
[FCurTexture
].Anim
then
765 Result
:= FTextureIDs
[FCurTexture
].AnTex
.FramesID
767 Result
:= FTextureIDs
[FCurTexture
].Tex
;
771 function TPanel
.GetTextureCount(): Integer;
773 Result
:= Length(FTextureIDs
);
774 if Enabled
and (FCurTexture
>= 0) then
775 if (FTextureIDs
[FCurTexture
].Anim
) and
776 (FTextureIDs
[FCurTexture
].AnTex
<> nil) and
777 (Width
> 0) and (Height
> 0) and (FAlpha
< 255) then
778 Result
:= Result
+ 100;
781 procedure TPanel
.SaveState(Var Mem
: TBinMemoryWriter
);
786 if (Mem
= nil) then exit
;
787 //if not SaveIt then exit;
790 sig
:= PANEL_SIGNATURE
; // 'PANL'
792 // Îòêðûòà/çàêðûòà, åñëè äâåðü:
793 Mem
.WriteBoolean(FEnabled
);
794 // Íàïðàâëåíèå ëèôòà, åñëè ëèôò:
795 Mem
.WriteByte(FLiftType
);
796 // Íîìåð òåêóùåé òåêñòóðû:
797 Mem
.WriteInt(FCurTexture
);
801 // Àíèìèðîâàííàÿ ëè òåêóùàÿ òåêñòóðà:
802 if (FCurTexture
>= 0) and (FTextureIDs
[FCurTexture
].Anim
) then
804 Assert(FTextureIDs
[FCurTexture
].AnTex
<> nil,
805 'TPanel.SaveState: No animation object');
810 Mem
.WriteBoolean(anim
);
811 // Åñëè äà - ñîõðàíÿåì àíèìàöèþ:
813 FTextureIDs
[FCurTexture
].AnTex
.SaveState(Mem
);
814 // moving platform state
815 Mem
.WriteInt(mMovingSpeed
.X
);
816 Mem
.WriteInt(mMovingSpeed
.Y
);
817 Mem
.WriteInt(mMovingStart
.X
);
818 Mem
.WriteInt(mMovingStart
.Y
);
819 Mem
.WriteInt(mMovingEnd
.X
);
820 Mem
.WriteInt(mMovingEnd
.Y
);
821 Mem
.WriteBoolean(mMovingActive
);
824 procedure TPanel
.LoadState(var Mem
: TBinMemoryReader
);
830 if (Mem
= nil) then exit
;
831 //if not SaveIt then exit;
835 if sig
<> PANEL_SIGNATURE
then // 'PANL'
837 raise EBinSizeError
.Create('TPanel.LoadState: Wrong Panel Signature');
839 // Îòêðûòà/çàêðûòà, åñëè äâåðü:
840 Mem
.ReadBoolean(FEnabled
);
841 // Íàïðàâëåíèå ëèôòà, åñëè ëèôò:
842 Mem
.ReadByte(FLiftType
);
843 // Íîìåð òåêóùåé òåêñòóðû:
844 Mem
.ReadInt(FCurTexture
);
850 //e_LogWritefln('panel %s(%s): old=(%s,%s); new=(%s,%s); delta=(%s,%s)', [arrIdx, proxyId, ox, oy, FX, FY, FX-ox, FY-oy]);
851 // Àíèìèðîâàííàÿ ëè òåêóùàÿ òåêñòóðà:
852 Mem
.ReadBoolean(anim
);
853 // Åñëè äà - çàãðóæàåì àíèìàöèþ:
856 Assert((FCurTexture
>= 0) and
857 (FTextureIDs
[FCurTexture
].Anim
) and
858 (FTextureIDs
[FCurTexture
].AnTex
<> nil),
859 'TPanel.LoadState: No animation object');
860 FTextureIDs
[FCurTexture
].AnTex
.LoadState(Mem
);
862 // moving platform state
863 Mem
.ReadInt(mMovingSpeed
.X
);
864 Mem
.ReadInt(mMovingSpeed
.Y
);
865 Mem
.ReadInt(mMovingStart
.X
);
866 Mem
.ReadInt(mMovingStart
.Y
);
867 Mem
.ReadInt(mMovingEnd
.X
);
868 Mem
.ReadInt(mMovingEnd
.Y
);
869 Mem
.ReadBoolean(mMovingActive
);
872 //mapGrid.proxyEnabled[proxyId] := FEnabled; // done in g_map.pas