From: Ketmar Dark Date: Sat, 19 Aug 2017 13:58:31 +0000 (+0300) Subject: added `.positionChanged()` to (almost) all entities; don't forget to call it after... X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=0fdf4d69047801a6a8d789df6def4a47015e9ae4;p=d2df-sdl.git added `.positionChanged()` to (almost) all entities; don't forget to call it after changing entity coords! --- diff --git a/src/game/g_items.pas b/src/game/g_items.pas index 9e6e2e0..e35fd33 100644 --- a/src/game/g_items.pas +++ b/src/game/g_items.pas @@ -33,6 +33,8 @@ Type SpawnTrigger: Integer; Obj: TObj; Animation: TAnimation; + + procedure positionChanged (); //WARNING! call this after monster position was changed, or coldet will not work right! end; procedure g_Items_LoadData(); @@ -400,6 +402,7 @@ begin if Fall then begin m := g_Obj_Move(@Obj, True, True); + positionChanged(); // this updates spatial accelerators // Ñîïðîòèâëåíèå âîçäóõà: if gTime mod (GAME_TICK*2) = 0 then @@ -520,6 +523,7 @@ begin Obj.Vel.Y := 0; Obj.Accel.X := 0; Obj.Accel.Y := 0; + positionChanged(); // this updates spatial accelerators Live := True; @@ -678,4 +682,9 @@ begin end; end; + +procedure TItem.positionChanged (); +begin +end; + end. diff --git a/src/game/g_monsters.pas b/src/game/g_monsters.pas index 57e3ce9..0d8f384 100644 --- a/src/game/g_monsters.pas +++ b/src/game/g_monsters.pas @@ -128,6 +128,8 @@ type procedure CatchFire(Attacker: Word); procedure OnFireFlame(Times: DWORD = 1); + procedure positionChanged (); //WARNING! call this after monster position was changed, or coldet will not work right! + property MonsterType: Byte read FMonsterType; property MonsterHealth: Integer read FHealth write FHealth; property MonsterAmmo: Integer read FAmmo write FAmmo; @@ -1447,6 +1449,8 @@ begin FState := STATE_SLEEP; FCurAnim := ANIM_SLEEP; + positionChanged(); // this updates spatial accelerators + if g_Game_IsNet and g_Game_IsServer then begin MH_SEND_MonsterPos(FUID); @@ -1686,6 +1690,7 @@ begin c, True, False); g_Obj_Push(@gItems[it].Obj, (FObj.Vel.X div 2)-3+Random(7), (FObj.Vel.Y div 2)-Random(4)); + positionChanged(); // this updates spatial accelerators if g_Game_IsServer and g_Game_IsNet then MH_SEND_ItemSpawn(True, it); end; @@ -2022,6 +2027,7 @@ begin if gTime mod (GAME_TICK*2) <> 0 then begin g_Obj_Move(@FObj, fall, True, True); + positionChanged(); // this updates spatial accelerators Exit; end; @@ -2032,6 +2038,7 @@ begin // Äâèãàåìñÿ: st := g_Obj_Move(@FObj, fall, True, True); + positionChanged(); // this updates spatial accelerators // Âûëåòåë çà êàðòó - óäàëÿåì è çàïóñêàåì òðèããåðû: if WordBool(st and MOVE_FALLOUT) or (FObj.X < -1000) or @@ -2421,14 +2428,23 @@ begin b := Abs(FObj.Vel.X); if b > 1 then b := b * (Random(8 div b) + 1); for a := 0 to High(gGibs) do + begin if gGibs[a].Live and g_Obj_Collide(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y+FObj.Rect.Height-4, FObj.Rect.Width, 8, @gGibs[a].Obj) and (Random(3) = 0) then + begin // Ïèíàåì êóñêè if FObj.Vel.X < 0 then - g_Obj_PushA(@gGibs[a].Obj, b, Random(61)+120) // íàëåâî + begin + g_Obj_PushA(@gGibs[a].Obj, b, Random(61)+120); // íàëåâî + end else + begin g_Obj_PushA(@gGibs[a].Obj, b, Random(61)); // íàïðàâî + end; + positionChanged(); // this updates spatial accelerators + end; + end; end; // Áîññû ìîãóò ïèíàòü òðóïû: if (FMonsterType in [MONSTER_CYBER, MONSTER_SPIDER, MONSTER_ROBO]) and @@ -2979,6 +2995,7 @@ begin if gTime mod (GAME_TICK*2) <> 0 then begin g_Obj_Move(@FObj, fall, True, True); + positionChanged(); // this updates spatial accelerators Exit; end; @@ -2989,6 +3006,7 @@ begin // Äâèãàåìñÿ: st := g_Obj_Move(@FObj, fall, True, True); + positionChanged(); // this updates spatial accelerators // Âûëåòåë çà êàðòó - óäàëÿåì è çàïóñêàåì òðèããåðû: if WordBool(st and MOVE_FALLOUT) or (FObj.X < -1000) or @@ -3242,14 +3260,23 @@ begin b := Abs(FObj.Vel.X); if b > 1 then b := b * (Random(8 div b) + 1); for a := 0 to High(gGibs) do + begin if gGibs[a].Live and g_Obj_Collide(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y+FObj.Rect.Height-4, FObj.Rect.Width, 8, @gGibs[a].Obj) and (Random(3) = 0) then + begin // Ïèíàåì êóñêè if FObj.Vel.X < 0 then - g_Obj_PushA(@gGibs[a].Obj, b, Random(61)+120) // íàëåâî + begin + g_Obj_PushA(@gGibs[a].Obj, b, Random(61)+120); // íàëåâî + end else + begin g_Obj_PushA(@gGibs[a].Obj, b, Random(61)); // íàïðàâî + end; + positionChanged(); // this updates spatial accelerators + end; + end; end; // Áîññû ìîãóò ïèíàòü òðóïû: if (FMonsterType in [MONSTER_CYBER, MONSTER_SPIDER, MONSTER_ROBO]) and @@ -4211,4 +4238,9 @@ begin end; end; +//WARNING! call this after monster position was changed, or coldet will not work right! +procedure TMonster.positionChanged (); +begin +end; + end. diff --git a/src/game/g_netmsg.pas b/src/game/g_netmsg.pas index a0fb6ed..237c9de 100644 --- a/src/game/g_netmsg.pas +++ b/src/game/g_netmsg.pas @@ -2625,6 +2625,8 @@ begin SetHealth(MHealth); SetState(MState); + + positionChanged(); // this updates spatial accelerators end; end; @@ -2645,6 +2647,7 @@ begin GameVelX := e_Raw_Read_LongInt(P); GameVelY := e_Raw_Read_LongInt(P); GameDirection := TDirection(e_Raw_Read_Byte(P)); + positionChanged(); // this updates spatial accelerators end; end; diff --git a/src/game/g_player.pas b/src/game/g_player.pas index f4c54db..f4e3b0f 100644 --- a/src/game/g_player.pas +++ b/src/game/g_player.pas @@ -311,6 +311,9 @@ type procedure JetpackOff; procedure CatchFire(Attacker: Word); + //WARNING! this does nothing for now, but still call it! + procedure positionChanged (); //WARNING! call this after monster position was changed, or coldet will not work right! + property Name: String read FName write FName; property Model: TPlayerModel read FModel; property Health: Integer read FHealth write FHealth; @@ -406,8 +409,11 @@ type RAngle: Integer; Color: TRGB; Obj: TObj; + + procedure positionChanged (); //WARNING! call this after monster position was changed, or coldet will not work right! end; + TShell = record SpriteID: DWORD; Live: Boolean; @@ -416,6 +422,8 @@ type Timeout: Cardinal; CX, CY: Integer; Obj: TObj; + + procedure positionChanged (); //WARNING! call this after monster position was changed, or coldet will not work right! end; TCorpse = class (TObject) @@ -438,6 +446,8 @@ type procedure SaveState(var Mem: TBinMemoryWriter); procedure LoadState(var Mem: TBinMemoryReader); + procedure positionChanged (); //WARNING! call this after monster position was changed, or coldet will not work right! + property Obj: TObj read FObj; property State: Byte read FState; property Mess: Boolean read FMess; @@ -593,6 +603,11 @@ var BotNames: Array of String; BotList: Array of TBotProfile; + +procedure TGib.positionChanged (); begin end; +procedure TShell.positionChanged (); begin end; + + function Lerp(X, Y, Factor: Integer): Integer; begin Result := X + ((Y - X) div Factor); @@ -1521,6 +1536,7 @@ begin Obj.X := fX; Obj.Y := fY; g_Obj_Push(@Obj, dX + Random(4)-Random(4), dY-Random(4)); + positionChanged(); // this updates spatial accelerators RAngle := Random(360); Timeout := gTime + SHELL_TIMEOUT; @@ -1553,6 +1569,7 @@ begin Obj.X := fX-GibsArray[a].Rect.X-(GibsArray[a].Rect.Width div 2); Obj.Y := fY-GibsArray[a].Rect.Y-(GibsArray[a].Rect.Height div 2); g_Obj_PushA(@Obj, 25 + Random(10), Random(361)); + positionChanged(); // this updates spatial accelerators RAngle := Random(360); if gBloodCount > 0 then @@ -1592,6 +1609,7 @@ begin begin vel := Obj.Vel; mr := g_Obj_Move(@Obj, True, False, True); + positionChanged(); // this updates spatial accelerators if WordBool(mr and MOVE_FALLOUT) then begin @@ -1641,6 +1659,7 @@ begin begin vel := Obj.Vel; mr := g_Obj_Move(@Obj, True, False, True); + positionChanged(); // this updates spatial accelerators if WordBool(mr and MOVE_FALLOUT) or (gShells[i].Timeout < gTime) then begin @@ -2008,6 +2027,10 @@ begin resetWeaponQueue(); end; +procedure TPlayer.positionChanged (); +begin +end; + procedure TPlayer.Damage(value: Word; SpawnerUID: Word; vx, vy: Integer; t: Byte); var c: Word; @@ -2957,15 +2980,25 @@ var begin id := g_Items_Create(FObj.X, FObj.Y, t, True, False); if KillType = K_EXTRAHARDKILL then // -7..+7; -8..0 + begin g_Obj_Push(@gItems[id].Obj, (FObj.Vel.X div 2)-7+Random(15), - (FObj.Vel.Y div 2)-Random(9)) + (FObj.Vel.Y div 2)-Random(9)); + gItems[id].positionChanged(); // this updates spatial accelerators + end else + begin if KillType = K_HARDKILL then // -5..+5; -5..0 + begin g_Obj_Push(@gItems[id].Obj, (FObj.Vel.X div 2)-5+Random(11), - (FObj.Vel.Y div 2)-Random(6)) + (FObj.Vel.Y div 2)-Random(6)); + end else // -3..+3; -3..0 + begin g_Obj_Push(@gItems[id].Obj, (FObj.Vel.X div 2)-3+Random(7), (FObj.Vel.Y div 2)-Random(4)); + end; + gItems[id].positionChanged(); // this updates spatial accelerators + end; if g_Game_IsNet and g_Game_IsServer then MH_SEND_ItemSpawn(True, id); @@ -4377,14 +4410,23 @@ begin b := Abs(FObj.Vel.X); if b > 1 then b := b * (Random(8 div b) + 1); for a := 0 to High(gGibs) do + begin if gGibs[a].Live and g_Obj_Collide(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y+FObj.Rect.Height-4, FObj.Rect.Width, 8, @gGibs[a].Obj) and (Random(3) = 0) then + begin // Ïèíàåì êóñêè if FObj.Vel.X < 0 then + begin g_Obj_PushA(@gGibs[a].Obj, b, Random(61)+120) // íàëåâî + end else + begin g_Obj_PushA(@gGibs[a].Obj, b, Random(61)); // íàïðàâî + end; + gGibs[a].positionChanged(); // this updates spatial accelerators + end; + end; end; SetAction(A_WALK); @@ -4611,7 +4653,10 @@ begin end; if FPhysics then + begin g_Obj_Move(@FObj, True, True, True); + positionChanged(); // this updates spatial accelerators + end; Exit; end; @@ -4734,7 +4779,10 @@ begin end; if FPhysics then - g_Obj_Move(@FObj, True, True, True) + begin + g_Obj_Move(@FObj, True, True, True); + positionChanged(); // this updates spatial accelerators + end else begin FObj.Vel.X := 0; @@ -5342,6 +5390,7 @@ begin Count := FLAG_TIME; g_Obj_Push(@Obj, (FObj.Vel.X div 2)-2+Random(5), (FObj.Vel.Y div 2)-2+Random(5)); + positionChanged(); // this updates spatial accelerators if FFlag = FLAG_RED then s := _lc[I_PLAYER_FLAG_RED] @@ -5992,6 +6041,8 @@ begin inherited; end; +procedure TCorpse.positionChanged (); begin end; + procedure TCorpse.Damage(Value: Word; vx, vy: Integer); var pm: TPlayerModel; @@ -6058,7 +6109,7 @@ begin if gTime mod (GAME_TICK*2) <> 0 then begin g_Obj_Move(@FObj, True, True, True); - + positionChanged(); // this updates spatial accelerators Exit; end; @@ -6066,6 +6117,7 @@ begin FObj.Vel.X := z_dec(FObj.Vel.X, 1); st := g_Obj_Move(@FObj, True, True, True); + positionChanged(); // this updates spatial accelerators if WordBool(st and MOVE_FALLOUT) then begin diff --git a/src/game/g_weapons.pas b/src/game/g_weapons.pas index 81db803..3585ef2 100644 --- a/src/game/g_weapons.pas +++ b/src/game/g_weapons.pas @@ -45,8 +45,11 @@ type TextureID: DWORD; Timeout: DWORD; Stopped: Byte; + + procedure positionChanged (); //WARNING! call this after monster position was changed, or coldet will not work right! end; + var Shots: array of TShot = nil; LastShotID: Integer = 0; @@ -145,7 +148,7 @@ const SHOT_FLAME_WIDTH = 4; SHOT_FLAME_HEIGHT = 4; - SHOT_FLAME_LIFETIME = 180; + SHOT_FLAME_LIFETIME = 180; SHOT_SIGNATURE = $544F4853; // 'SHOT' @@ -961,6 +964,7 @@ begin Obj.Y+Obj.Rect.Y+(Obj.Rect.Height div 2), X, Y); g_Obj_PushA(@Obj, Round(15*(rad-m)/rad), _angle); + positionChanged(); // this updates spatial accelerators end; end; end; @@ -1768,9 +1772,14 @@ begin (ShotType <> WEAPON_FLAMETHROWER); if Stopped = 0 then - st := g_Obj_Move(@Obj, False, spl) + begin + st := g_Obj_Move(@Obj, False, spl); + end else + begin st := 0; + end; + positionChanged(); // this updates spatial accelerators if WordBool(st and MOVE_FALLOUT) or (Obj.X < -1000) or (Obj.X > gMapInfo.Width+1000) or (Obj.Y < -1000) then @@ -2467,4 +2476,8 @@ begin end; end; + +procedure TShot.positionChanged (); begin end; + + end.