~ubuntu-branches/ubuntu/wily/hedgewars/wily

« back to all changes in this revision

Viewing changes to hedgewars/uAIMisc.pas

  • Committer: Package Import Robot
  • Author(s): Dmitry E. Oboukhov
  • Date: 2011-09-23 10:16:55 UTC
  • mfrom: (1.2.11 upstream)
  • Revision ID: package-import@ubuntu.com-20110923101655-3977th2gc5n0a3pv
Tags: 0.9.16-1
* New upstream version.
 + Downloadable content! Simply click to install any content.
   New voices, hats, maps, themes, translations, music, scripts...
   Hedgewars is now more customisable than ever before! As time goes
   by we will be soliciting community content to feature on this page,
   so remember to check it from time to time. If you decide you want
   to go back to standard Hedgewars, just remove the Data directory
   from your Hedgewars config directory.
 + 3-D rendering! Diorama-like rendering of the game in a variety
   of 3D modes. Let us know which ones work best for you, we didn't
   really have the equipment to test them all.
 + Resizable game window.
 + New utilities! The Time Box will remove one of your hedgehogs
   from the game for a while, protecting from attack until it returns,
   somewhere else on the map. Land spray will allow you to build bridges,
   seal up holes, or just make life unpleasant for your enemies.
 + New single player: Bamboo Thicket, That Sinking Feeling, Newton and
   the Tree and multi-player: The Specialists, Space Invaders,
   Racer - scripts! And a ton more script hooks for scripters
 + New twists on old weapons. Drill strike, seduction and fire have
   been adjusted. Defective mines have been added, rope can attach to
   hogs/crates/barrels again, grenades now have variable bounce (use
   precise key + 1-5). Portal gun is now more usable in flight and
   all game actions are a lot faster.
 + New theme - Golf, dozens of new community hats and a new
   localised Default voice, Ukranian.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
(*
2
2
 * Hedgewars, a free turn based strategy game
3
 
 * Copyright (c) 2005-2010 Andrey Korotaev <unC0Rr@gmail.com>
 
3
 * Copyright (c) 2005-2011 Andrey Korotaev <unC0Rr@gmail.com>
4
4
 *
5
5
 * This program is free software; you can redistribute it and/or modify
6
6
 * it under the terms of the GNU General Public License as published by
56
56
function RateExplosion(Me: PGear; x, y, r: LongInt): LongInt;
57
57
function RateShove(Me: PGear; x, y, r, power: LongInt): LongInt;
58
58
function RateShotgun(Me: PGear; x, y: LongInt): LongInt;
 
59
function RateHammer(Me: PGear): LongInt;
59
60
function HHGo(Gear, AltGear: PGear; var GoInfo: TGoInfo): boolean;
60
61
function AIrndSign(num: LongInt): LongInt;
61
62
 
111
112
            end;
112
113
 
113
114
if e > f then friendlyfactor:= 300 + (e - f) * 30
114
 
else friendlyfactor:= max(30, 300 - f * 80 div e)
 
115
else friendlyfactor:= max(30, 300 - f * 80 div max(1,e))
115
116
end;
116
117
 
117
118
procedure FillBonuses(isAfterAttack: boolean; filter: TGearsType);
134
135
Gear:= GearsList;
135
136
while Gear <> nil do
136
137
    begin
137
 
        if (filter = []) or (Gear^.Kind in filter) then
 
138
    if (filter = []) or (Gear^.Kind in filter) then
138
139
      case Gear^.Kind of
139
140
          gtCase: AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 33, 25);
140
141
          gtFlame: if (Gear^.State and gsttmpFlag) <> 0 then
141
142
                  AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 20, -50);
142
 
          gtMine: if (Gear^.State and gstAttacking) = 0 then
143
 
                  AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 50, -50)
144
 
              else
145
 
                  AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 100, -50); // mine is on
 
143
// avoid mines unless they are very likely to be duds, or are duds. also avoid if they are about to blow 
 
144
          gtMine:  if ((Gear^.State and gstAttacking) = 0) and 
 
145
                      (((cMineDudPercent < 90) and (Gear^.Health <> 0)) or
 
146
                       ((Gear^.Health = 0) and (Gear^.Damage > 30))) then
 
147
                          AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 50, -50)
 
148
                      else if (Gear^.State and gstAttacking) <> 0 then
 
149
                          AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 100, -50); // mine is on
 
150
          gtSMine:    AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 50, -30);
146
151
          gtDynamite: AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 150, -75);
147
152
          gtHedgehog: begin
148
153
                      if Gear^.Damage >= Gear^.Health then
149
154
                          AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 60, -25)
150
155
                      else
151
156
                          if isAfterAttack and (ThinkingHH^.Hedgehog <> Gear^.Hedgehog) then
152
 
                              if (MyClan = Gear^.Hedgehog^.Team^.Clan) then
 
157
                              if (ClansCount > 2) or (MyClan = Gear^.Hedgehog^.Team^.Clan) then
153
158
                                  AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 150, -3) // hedgehog-friend
154
159
                              else
155
160
                                  AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 100, 3)
227
232
for i:= 0 to Targets.Count do
228
233
    with Targets.ar[i] do
229
234
         begin
230
 
         dmg:= r + cHHRadius div 2 - hwRound(DistanceI(Point.x - x, Point.y - y));
 
235
         dmg:= hwRound(_0_01 * cDamageModifier
 
236
            * min((r + cHHRadius div 2 - DistanceI(Point.x - x, Point.y - y).Round) div 2, r) * cDamagePercent);
 
237
 
231
238
         if dmg > 0 then
232
239
            begin
233
 
            dmg:= min(dmg div 2, r);
234
240
            if dmg >= abs(Score) then
235
241
               if Score > 0 then inc(rate, KillScore)
236
242
                            else dec(rate, KillScore * friendlyfactor div 100)
251
257
    with Targets.ar[i] do
252
258
         begin
253
259
         dmg:= r - hwRound(DistanceI(Point.x - x, Point.y - y));
 
260
         dmg:= hwRound(_0_01 * cDamageModifier * dmg * cDamagePercent);
254
261
         if dmg > 0 then
255
262
            begin
256
263
            if power >= abs(Score) then
265
272
end;
266
273
 
267
274
function RateShotgun(Me: PGear; x, y: LongInt): LongInt;
268
 
const
269
 
  REUSE_BONUS = 1.35;
270
275
var i, dmg, rate: LongInt;
271
276
begin
272
277
rate:= 0;
281
286
for i:= 0 to Targets.Count do
282
287
    with Targets.ar[i] do
283
288
         begin
284
 
         dmg:= min(cHHRadius + cShotgunRadius - hwRound(DistanceI(Point.x - x, Point.y - y)), 25);
285
 
         dmg := round(dmg * REUSE_BONUS);
 
289
         dmg:= min(cHHRadius + cShotgunRadius + 4 - hwRound(DistanceI(Point.x - x, Point.y - y)), 25);
 
290
         dmg:= hwRound(_0_01 * cDamageModifier * dmg * cDamagePercent);
286
291
         if dmg > 0 then
287
292
            begin
288
293
                if dmg >= abs(Score) then dmg := KillScore;
289
294
                if Score > 0 then inc(rate, dmg)
290
295
                else dec(rate, dmg * friendlyfactor div 100);
291
296
            end;
292
 
         end;
 
297
         end;        
293
298
RateShotgun:= rate * 1024;
294
299
end;
295
300
 
 
301
function RateHammer(Me: PGear): LongInt;
 
302
var x, y, i, r, rate: LongInt;
 
303
begin
 
304
// hammer hit shift against attecker hog is 10
 
305
x:= hwRound(Me^.X) + hwSign(Me^.dX) * 10;
 
306
y:= hwRound(Me^.Y);
 
307
rate:= 0;
 
308
 
 
309
for i:= 0 to Pred(Targets.Count) do
 
310
    with Targets.ar[i] do
 
311
         begin
 
312
         // hammer hit radius is 8, shift is 10
 
313
         r:= hwRound(DistanceI(Point.x - x, Point.y - y));
 
314
 
 
315
         if r <= 18 then
 
316
            if Score > 0 then 
 
317
                inc(rate, Score div 3)
 
318
                else 
 
319
                inc(rate, Score div 3 * friendlyfactor div 100)
 
320
         end;
 
321
RateHammer:= rate * 1024;
 
322
end;
 
323
 
296
324
function HHJump(Gear: PGear; JumpType: TJumpType; var GoInfo: TGoInfo): boolean;
297
325
var bX, bY: LongInt;
298
326
    bRes: boolean;
299
327
begin
300
328
bRes:= false;
301
329
GoInfo.Ticks:= 0;
302
 
GoInfo.FallPix:= 0;
303
330
GoInfo.JumpType:= jmpNone;
304
331
bX:= hwRound(Gear^.X);
305
332
bY:= hwRound(Gear^.Y);
368
395
 
369
396
function HHGo(Gear, AltGear: PGear; var GoInfo: TGoInfo): boolean;
370
397
var pX, pY: LongInt;
371
 
    bRes: boolean;
372
398
begin
373
 
bRes:= false;
374
399
AltGear^:= Gear^;
375
400
 
376
401
GoInfo.Ticks:= 0;
388
413
      begin
389
414
      Goinfo.FallPix:= 0;
390
415
      HHJump(AltGear, jmpLJump, GoInfo); // try ljump instead of fall with damage
391
 
      exit(bRes)
 
416
      exit(false)
392
417
      end;
393
418
   Gear^.Y:= Gear^.Y + Gear^.dY;
394
419
   if hwRound(Gear^.Y) > pY then inc(GoInfo.FallPix);
397
422
      inc(GoInfo.Ticks, 410);
398
423
      Gear^.State:= Gear^.State and not (gstMoving or gstHHJumping);
399
424
      Gear^.dY:= _0;
400
 
      bRes:= true;
401
425
      HHJump(AltGear, jmpLJump, GoInfo); // try ljump instead of fall
402
 
      exit(bRes)
 
426
      exit(true)
403
427
      end;
404
428
   continue
405
429
   end;
406
430
   if (Gear^.Message and gmLeft  )<>0 then Gear^.dX:= -cLittle else
407
 
   if (Gear^.Message and gmRight )<>0 then Gear^.dX:=  cLittle else exit(bRes);
 
431
   if (Gear^.Message and gmRight )<>0 then Gear^.dX:=  cLittle else exit(false);
408
432
   if TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then
409
433
      begin
410
434
      if not (TestCollisionXwithXYShift(Gear, _0, -6, hwSign(Gear^.dX))
460
484
   exit(true);
461
485
until (pX = hwRound(Gear^.X)) and (pY = hwRound(Gear^.Y)) and ((Gear^.State and gstMoving) = 0);
462
486
HHJump(AltGear, jmpHJump, GoInfo);
463
 
HHGo:= bRes;
 
487
HHGo:= false;
464
488
end;
465
489
 
466
490
function AIrndSign(num: LongInt): LongInt;