hedgewars/uGears.pas
branchwebgl
changeset 8330 aaefa587e277
parent 8099 a7f02b902b6f
parent 8204 9a6030d96273
child 8444 75db7bb8dce8
equal deleted inserted replaced
8116:d24257910f8d 8330:aaefa587e277
    54 function  GearByUID(uid : Longword) : PGear;
    54 function  GearByUID(uid : Longword) : PGear;
    55 procedure doStepDrowningGear(Gear: PGear);
    55 procedure doStepDrowningGear(Gear: PGear);
    56 
    56 
    57 implementation
    57 implementation
    58 uses uStore, uSound, uTeams, uRandom, uCollisions, uIO, uLandGraphics,
    58 uses uStore, uSound, uTeams, uRandom, uCollisions, uIO, uLandGraphics,
    59     uLocale, uAI, uAmmos, uStats, uVisualGears, uScript, GLunit, uMobile, uVariables,
    59     uLocale, uAI, uAmmos, uStats, uVisualGears, uScript, GLunit, uVariables,
    60     uCommands, uUtils, uTextures, uRenderUtils, uGearsRender, uCaptions, uDebug, uLandTexture,
    60     uCommands, uUtils, uTextures, uRenderUtils, uGearsRender, uCaptions, uDebug, uLandTexture,
    61     uGearsHedgehog, uGearsUtils, uGearsList, uGearsHandlers, uGearsHandlersRope;
    61     uGearsHedgehog, uGearsUtils, uGearsList, uGearsHandlers, uGearsHandlersRope;
    62 
    62 
    63 var skipFlag: boolean;
    63 var skipFlag: boolean;
    64 
    64 
   170                     inc(tmp, 5);
   170                     inc(tmp, 5);
   171                     if (GameFlags and gfResetHealth) <> 0 then
   171                     if (GameFlags and gfResetHealth) <> 0 then
   172                         dec(Gear^.Hedgehog^.InitialHealth, 5)
   172                         dec(Gear^.Hedgehog^.InitialHealth, 5)
   173                     end
   173                     end
   174                 end;
   174                 end;
   175             if tmp > 0 then 
   175             if tmp > 0 then
   176                 begin
   176                 begin
   177                 inc(Gear^.Damage, min(tmp, max(0,Gear^.Health - 1 - Gear^.Damage)));
   177                 inc(Gear^.Damage, min(tmp, max(0,Gear^.Health - 1 - Gear^.Damage)));
   178                 HHHurt(Gear^.Hedgehog, dsPoison);
   178                 HHHurt(Gear^.Hedgehog, dsPoison);
   179                 end
   179                 end
   180             end;
   180             end;
   210 
   210 
   211     if curHandledGear^.Message and gmDelete <> 0 then
   211     if curHandledGear^.Message and gmDelete <> 0 then
   212         DeleteGear(curHandledGear)
   212         DeleteGear(curHandledGear)
   213     else
   213     else
   214         begin
   214         begin
   215         if curHandledGear^.Message and gmRemoveFromList <> 0 then 
   215         if curHandledGear^.Message and gmRemoveFromList <> 0 then
   216             begin
   216             begin
   217             RemoveGearFromList(curHandledGear);
   217             RemoveGearFromList(curHandledGear);
   218             // since I can't think of any good reason this would ever be separate from a remove from list, going to keep it inside this block
   218             // since I can't think of any good reason this would ever be separate from a remove from list, going to keep it inside this block
   219             if curHandledGear^.Message and gmAddToList <> 0 then InsertGearToList(curHandledGear);
   219             if curHandledGear^.Message and gmAddToList <> 0 then InsertGearToList(curHandledGear);
   220             curHandledGear^.Message:= (curHandledGear^.Message and (not (gmRemoveFromList or gmAddToList)))
   220             curHandledGear^.Message:= (curHandledGear^.Message and (not (gmRemoveFromList or gmAddToList)))
   244             dec(delay);
   244             dec(delay);
   245 
   245 
   246         if delay = 0 then
   246         if delay = 0 then
   247             inc(step)
   247             inc(step)
   248         end;
   248         end;
   249         
   249 
   250     stChDmg:
   250     stChDmg:
   251     if CheckNoDamage then
   251     if CheckNoDamage then
   252         inc(step)
   252         inc(step)
   253     else
   253     else
   254         step:= stDelay;
   254         step:= stDelay;
   255         
   255 
   256     stSweep:
   256     stSweep:
   257     if SweepDirty then
   257     if SweepDirty then
   258         begin
   258         begin
   259         SetAllToActive;
   259         SetAllToActive;
   260         step:= stChDmg
   260         step:= stChDmg
   261         end
   261         end
   262     else
   262     else
   263         inc(step);
   263         inc(step);
   264         
   264 
   265     stTurnReact:
   265     stTurnReact:
   266         begin
   266         begin
   267         if (not bBetweenTurns) and (not isInMultiShoot) then
   267         if (not bBetweenTurns) and (not isInMultiShoot) then
   268             begin
   268             begin
   269             uStats.TurnReaction;
   269             uStats.TurnReaction;
   270             inc(step)
   270             inc(step)
   271             end
   271             end
   272         else
   272         else
   273             inc(step, 2);
   273             inc(step, 2);
   274         end;
   274         end;
   275         
   275 
   276     stAfterDelay:
   276     stAfterDelay:
   277         begin
   277         begin
   278         if delay = 0 then
   278         if delay = 0 then
   279             delay:= cInactDelay
   279             delay:= cInactDelay
   280         else
   280         else
   313                 begin
   313                 begin
   314                 SuddenDeath:= true;
   314                 SuddenDeath:= true;
   315                 if cHealthDecrease <> 0 then
   315                 if cHealthDecrease <> 0 then
   316                     begin
   316                     begin
   317                     SuddenDeathDmg:= true;
   317                     SuddenDeathDmg:= true;
   318                         
   318 
   319                     // flash
   319                     // flash
   320                     ScreenFade:= sfFromWhite;
   320                     ScreenFade:= sfFromWhite;
   321                     ScreenFadeValue:= sfMax;
   321                     ScreenFadeValue:= sfMax;
   322                     ScreenFadeSpeed:= 1;
   322                     ScreenFadeSpeed:= 1;
   323                     
   323 
   324                     ChangeToSDClouds;
   324                     ChangeToSDClouds;
   325                     ChangeToSDFlakes;
   325                     ChangeToSDFlakes;
   326                     glClearColor(SDSkyColor.r * (SDTint/255) / 255, SDSkyColor.g * (SDTint/255) / 255, SDSkyColor.b * (SDTint/255) / 255, 0.99);
   326                     glClearColor(SDSkyColor.r * (SDTint/255) / 255, SDSkyColor.g * (SDTint/255) / 255, SDSkyColor.b * (SDTint/255) / 255, 0.99);
   327                     Ammoz[amTardis].SkipTurns:= 9999;
   327                     Ammoz[amTardis].SkipTurns:= 9999;
   328                     Ammoz[amTardis].Probability:= 0;
   328                     Ammoz[amTardis].Probability:= 0;
   528             t^.Health:= t^.Hedgehog^.InitialHealth;
   528             t^.Health:= t^.Hedgehog^.InitialHealth;
   529             RenderHealth(t^.Hedgehog^);
   529             RenderHealth(t^.Hedgehog^);
   530             end;
   530             end;
   531         t:= t^.NextGear
   531         t:= t^.NextGear
   532         end;
   532         end;
   533    
   533 
   534     if ((GameFlags and gfResetWeps) <> 0) and (not PlacingHogs) then
   534     if ((GameFlags and gfResetWeps) <> 0) and (not PlacingHogs) then
   535         ResetWeapons;
   535         ResetWeapons;
   536 
   536 
   537     if (GameFlags and gfResetHealth) <> 0 then
   537     if (GameFlags and gfResetHealth) <> 0 then
   538         for i:= 0 to Pred(TeamsCount) do
   538         for i:= 0 to Pred(TeamsCount) do
   675             gtMine,
   675             gtMine,
   676             gtSMine,
   676             gtSMine,
   677             gtKnife,
   677             gtKnife,
   678             gtCase,
   678             gtCase,
   679             gtTarget,
   679             gtTarget,
   680             gtExplosives,
   680             gtExplosives: begin//,
   681             gtStructure: begin
   681 //            gtStructure: begin
   682 //addFileLog('ShotgunShot radius: ' + inttostr(Gear^.Radius) + ', t^.Radius = ' + inttostr(t^.Radius) + ', distance = ' + inttostr(dist) + ', dmg = ' + inttostr(dmg));
   682 //addFileLog('ShotgunShot radius: ' + inttostr(Gear^.Radius) + ', t^.Radius = ' + inttostr(t^.Radius) + ', distance = ' + inttostr(dist) + ', dmg = ' + inttostr(dmg));
   683                     dmg:= 0;
   683                     dmg:= 0;
   684                     r:= Gear^.Radius + t^.Radius;
   684                     r:= Gear^.Radius + t^.Radius;
   685                     dx:= Gear^.X-t^.X;
   685                     dx:= Gear^.X-t^.X;
   686                     dx.isNegative:= false;
   686                     dx.isNegative:= false;
   758     Gear:= t^.ar[i];
   758     Gear:= t^.ar[i];
   759     tmpDmg:= ModifyDamage(Damage, Gear);
   759     tmpDmg:= ModifyDamage(Damage, Gear);
   760     if (Gear^.State and gstNoDamage) = 0 then
   760     if (Gear^.State and gstNoDamage) = 0 then
   761         begin
   761         begin
   762 
   762 
   763         if (Ammo^.Kind = gtDEagleShot) or (Ammo^.Kind = gtSniperRifleShot) then 
   763         if (Ammo^.Kind = gtDEagleShot) or (Ammo^.Kind = gtSniperRifleShot) then
   764             begin
   764             begin
   765             VGear := AddVisualGear(hwround(Ammo^.X), hwround(Ammo^.Y), vgtBulletHit);
   765             VGear := AddVisualGear(hwround(Ammo^.X), hwround(Ammo^.Y), vgtBulletHit);
   766             if VGear <> nil then
   766             if VGear <> nil then
   767                 VGear^.Angle := DxDy2Angle(-Ammo^.dX, Ammo^.dY);
   767                 VGear^.Angle := DxDy2Angle(-Ammo^.dX, Ammo^.dY);
   768             end;
   768             end;
   775             gtMine,
   775             gtMine,
   776             gtSMine,
   776             gtSMine,
   777             gtKnife,
   777             gtKnife,
   778             gtTarget,
   778             gtTarget,
   779             gtCase,
   779             gtCase,
   780             gtExplosives,
   780             gtExplosives: //,
   781             gtStructure:
   781             //gtStructure:
   782             begin
   782             begin
   783             if (Ammo^.Kind = gtDrill) then
   783             if (Ammo^.Kind = gtDrill) then
   784                 begin
   784                 begin
   785                 Ammo^.Timer:= 0;
   785                 Ammo^.Timer:= 0;
   786                 exit;
   786                 exit;
   808                         end;
   808                         end;
   809                 ApplyDamage(Gear, Ammo^.Hedgehog, tmpDmg, dsShove)
   809                 ApplyDamage(Gear, Ammo^.Hedgehog, tmpDmg, dsShove)
   810                 end
   810                 end
   811             else
   811             else
   812                 Gear^.State:= Gear^.State or gstWinner;
   812                 Gear^.State:= Gear^.State or gstWinner;
   813             if (Gear^.Kind = gtExplosives) and (Ammo^.Kind = gtBlowtorch) then 
   813             if (Gear^.Kind = gtExplosives) and (Ammo^.Kind = gtBlowtorch) then
   814                 begin
   814                 begin
   815                 if (Ammo^.Hedgehog^.Gear <> nil) then
   815                 if (Ammo^.Hedgehog^.Gear <> nil) then
   816                     Ammo^.Hedgehog^.Gear^.State:= (Ammo^.Hedgehog^.Gear^.State and (not gstNotKickable));
   816                     Ammo^.Hedgehog^.Gear^.State:= (Ammo^.Hedgehog^.Gear^.State and (not gstNotKickable));
   817                 ApplyDamage(Gear, Ammo^.Hedgehog, tmpDmg * 100, dsUnknown); // crank up damage for explosives + blowtorch
   817                 ApplyDamage(Gear, Ammo^.Hedgehog, tmpDmg * 100, dsUnknown); // crank up damage for explosives + blowtorch
   818                 end;
   818                 end;
   904                     begin
   904                     begin
   905                     ar[Count]:= @Hedgehogs[i];
   905                     ar[Count]:= @Hedgehogs[i];
   906                     inc(Count)
   906                     inc(Count)
   907                     end;
   907                     end;
   908         end;
   908         end;
   909     // unC0Rr, while it is true user can watch value on map screen, IMO this (and check above) should be enforced in UI
       
   910     // - is there a good place to put values for the different widgets to check?  Right now they are kind of disconnected.
       
   911     //it would be nice if divide teams, forts mode and hh per map could all be checked by the team widget, or maybe disable start button
       
   912     TryDo(Count <= MaxHedgehogs, 'Too many hedgehogs for this map! (max # is ' + inttostr(MaxHedgehogs) + ')', true);
       
   913     while (Count > 0) do
   909     while (Count > 0) do
   914         begin
   910         begin
   915         i:= GetRandom(Count);
   911         i:= GetRandom(Count);
   916         if PlacingHogs then
   912         if PlacingHogs then
   917             ar[i]^.Unplaced:= true
   913             ar[i]^.Unplaced:= true
   936 begin
   932 begin
   937     r:= r*r;
   933     r:= r*r;
   938     s:= 0;
   934     s:= 0;
   939     SetLength(GearsNearArray, s);
   935     SetLength(GearsNearArray, s);
   940     t := GearsList;
   936     t := GearsList;
   941     while t <> nil do 
   937     while t <> nil do
   942         begin
   938         begin
   943         if (t^.Kind = Kind) 
   939         if (t^.Kind = Kind)
   944             and ((X - t^.X)*(X - t^.X) + (Y - t^.Y)*(Y-t^.Y) < int2hwFloat(r)) then
   940             and ((X - t^.X)*(X - t^.X) + (Y - t^.Y)*(Y-t^.Y) < int2hwFloat(r)) then
   945             begin
   941             begin
   946             inc(s);
   942             inc(s);
   947             SetLength(GearsNearArray, s);
   943             SetLength(GearsNearArray, s);
   948             GearsNearArray[s - 1] := t;
   944             GearsNearArray[s - 1] := t;
  1030 function SpawnFakeCrateAt(x, y: LongInt; crate: TCrateType; explode: boolean; poison: boolean): PGear;
  1026 function SpawnFakeCrateAt(x, y: LongInt; crate: TCrateType; explode: boolean; poison: boolean): PGear;
  1031 begin
  1027 begin
  1032     FollowGear := AddGear(x, y, gtCase, 0, _0, _0, 0);
  1028     FollowGear := AddGear(x, y, gtCase, 0, _0, _0, 0);
  1033     cCaseFactor := 0;
  1029     cCaseFactor := 0;
  1034     FollowGear^.Pos := posCaseDummy;
  1030     FollowGear^.Pos := posCaseDummy;
  1035     
  1031 
  1036     if explode then
  1032     if explode then
  1037         FollowGear^.Pos := FollowGear^.Pos + posCaseExplode;
  1033         FollowGear^.Pos := FollowGear^.Pos + posCaseExplode;
  1038     if poison then
  1034     if poison then
  1039         FollowGear^.Pos := FollowGear^.Pos + posCasePoison;
  1035         FollowGear^.Pos := FollowGear^.Pos + posCasePoison;
  1040 
  1036 
  1269     if (x < 4) and (TeamsArray[t] <> nil) then
  1265     if (x < 4) and (TeamsArray[t] <> nil) then
  1270         begin
  1266         begin
  1271             // if team matches current hedgehog team, default to current hedgehog
  1267             // if team matches current hedgehog team, default to current hedgehog
  1272             if (i = 0) and (CurrentHedgehog <> nil) and (CurrentHedgehog^.Team = TeamsArray[t]) then
  1268             if (i = 0) and (CurrentHedgehog <> nil) and (CurrentHedgehog^.Team = TeamsArray[t]) then
  1273                 hh:= CurrentHedgehog
  1269                 hh:= CurrentHedgehog
  1274             else 
  1270             else
  1275                 begin
  1271                 begin
  1276             // otherwise use the first living hog or the hog amongs the remaining ones indicated by i
  1272             // otherwise use the first living hog or the hog amongs the remaining ones indicated by i
  1277                 j:= 0;
  1273                 j:= 0;
  1278                 c:= 0;
  1274                 c:= 0;
  1279                 while (j <= cMaxHHIndex) and (hh = nil) do
  1275                 while (j <= cMaxHHIndex) and (hh = nil) do
  1285                             hh:= @TeamsArray[t]^.Hedgehogs[j]
  1281                             hh:= @TeamsArray[t]^.Hedgehogs[j]
  1286                         end;
  1282                         end;
  1287                     inc(j)
  1283                     inc(j)
  1288                     end
  1284                     end
  1289                 end;
  1285                 end;
  1290         if hh <> nil then 
  1286         if hh <> nil then
  1291             begin
  1287             begin
  1292             Gear:= AddVisualGear(0, 0, vgtSpeechBubble);
  1288             Gear:= AddVisualGear(0, 0, vgtSpeechBubble);
  1293             if Gear <> nil then
  1289             if Gear <> nil then
  1294                 begin
  1290                 begin
  1295                 Gear^.Hedgehog:= hh;
  1291                 Gear^.Hedgehog:= hh;
  1365             @doStepHammerHit,
  1361             @doStepHammerHit,
  1366             @doStepResurrector,
  1362             @doStepResurrector,
  1367             @doStepNapalmBomb,
  1363             @doStepNapalmBomb,
  1368             @doStepSnowball,
  1364             @doStepSnowball,
  1369             @doStepSnowflake,
  1365             @doStepSnowflake,
  1370             @doStepStructure,
  1366             //@doStepStructure,
  1371             @doStepLandGun,
  1367             @doStepLandGun,
  1372             @doStepTardis,
  1368             @doStepTardis,
  1373             @doStepIceGun,
  1369             @doStepIceGun,
  1374             @doStepAddAmmo,
  1370             @doStepAddAmmo,
  1375             @doStepGenericFaller,
  1371             @doStepGenericFaller,