- Fix AI not to damage self hedgehogs
authorunc0rr
Fri, 15 Sep 2006 13:47:01 +0000
changeset 146 458f4f58c1b6
parent 145 e593d5266e01
child 147 52a3c431db8a
- Fix AI not to damage self hedgehogs - Fix checking for winner - main.cpp shouldn't be changed without changing main.cpp.in
QTfrontend/main.cpp.in
hedgewars/GSHandlers.inc
hedgewars/uAI.pas
hedgewars/uTeams.pas
hedgewars/uWorld.pas
--- a/QTfrontend/main.cpp.in	Thu Sep 14 17:20:50 2006 +0000
+++ b/QTfrontend/main.cpp.in	Fri Sep 15 13:47:01 2006 +0000
@@ -1,6 +1,6 @@
 /*
  * Hedgewars, a worms-like game
- * Copyright (c) 2005 Andrey Korotaev <unC0Rr@gmail.com>
+ * Copyright (c) 2005, 2006 Andrey Korotaev <unC0Rr@gmail.com>
  *
  * Distributed under the terms of the BSD-modified licence:
  *
@@ -36,6 +36,7 @@
 #include <QLocale>
 #include <QMessageBox>
 #include <QFileInfo>
+#include <QDateTime>
 #include "hwform.h"
 #include "hwconsts.h"
 
@@ -47,6 +48,10 @@
 {
 	QApplication app(argc, argv);
 
+	QDateTime now = QDateTime::currentDateTime();
+	QDateTime zero;
+	srand(now.secsTo(zero));
+
 	Q_INIT_RESOURCE(hedgewars);
 
 	QTranslator Translator;
--- a/hedgewars/GSHandlers.inc	Thu Sep 14 17:20:50 2006 +0000
+++ b/hedgewars/GSHandlers.inc	Fri Sep 15 13:47:01 2006 +0000
@@ -779,7 +779,7 @@
 thexchcnt:= i;
 for i:= 1 to thexchcnt do
     for t:= 0 to thexchcnt - 2 do
-        if thexchar[t].team.TeamHealth > thexchar[Succ(t)].team.TeamHealth then
+        if thexchar[t].team.TeamHealthBarWidth > thexchar[Succ(t)].team.TeamHealthBarWidth then
            begin
            thexchar[5]:= thexchar[t];
            thexchar[t]:= thexchar[Succ(t)];
--- a/hedgewars/uAI.pas	Thu Sep 14 17:20:50 2006 +0000
+++ b/hedgewars/uAI.pas	Fri Sep 15 13:47:01 2006 +0000
@@ -79,6 +79,7 @@
               begin
               BestActions:= Actions;
               inc(BestActions.Score, Score);
+              
               AddAction(BestActions, aia_Weapon, Longword(a), 500);
               if Time <> 0 then AddAction(BestActions, aia_Timer, Time div 1000, 400);
               if (Angle > 0) then AddAction(BestActions, aia_LookRight, 0, 200)
@@ -250,7 +251,11 @@
       begin
       Walk(@WalkMe);
       if (StartTicks > GameTicks - 1500) and not StopThinking then SDL_Delay(2000);
-      if BestActions.Score = BadTurn then AddAction(BestActions, aia_Skip, 0, 250);
+      if BestActions.Score < -1023 then
+         begin
+         BestActions.Count:= 0;
+         AddAction(BestActions, aia_Skip, 0, 250);
+         end;
       end else
 else begin
       Walk(@WalkMe);
@@ -262,7 +267,6 @@
             Walk(@WalkMe)
             end
       end;
-
 Me.State:= Me.State and not gstHHThinking
 end;
 
--- a/hedgewars/uTeams.pas	Thu Sep 14 17:20:50 2006 +0000
+++ b/hedgewars/uTeams.pas	Fri Sep 15 13:47:01 2006 +0000
@@ -66,6 +66,7 @@
              GraveName: string;
              FortName: string;
              TeamHealth: integer;
+             TeamHealthBarWidth: integer;
              DrawHealthY: integer;
              AttackBar: LongWord;
              end;
@@ -330,15 +331,16 @@
 begin
 with team^ do
      begin
-     TeamHealth:= 0;
+     TeamHealthBarWidth:= 0;
      for i:= 0 to cMaxHHIndex do
          if Hedgehogs[i].Gear <> nil then
-            inc(TeamHealth, Hedgehogs[i].Gear.Health);
-     if TeamHealth > MaxTeamHealth then
+            inc(TeamHealthBarWidth, Hedgehogs[i].Gear.Health);
+     TeamHealth:= TeamHealthBarWidth;
+     if TeamHealthBarWidth > MaxTeamHealth then
         begin
-        MaxTeamHealth:= TeamHealth;
+        MaxTeamHealth:= TeamHealthBarWidth;
         RecountAllTeamsHealth;
-        end else TeamHealth:= (TeamHealth * cTeamHealthWidth) div MaxTeamHealth
+        end else TeamHealthBarWidth:= (TeamHealthBarWidth * cTeamHealthWidth) div MaxTeamHealth
      end;
 // FIXME: at the game init, gtTeamHealthSorters are created for each team, and they work simultaneously
 AddGear(0, 0, gtTeamHealthSorter, 0)
--- a/hedgewars/uWorld.pas	Thu Sep 14 17:20:50 2006 +0000
+++ b/hedgewars/uWorld.pas	Fri Sep 15 13:47:01 2006 +0000
@@ -241,13 +241,13 @@
       r.h:= team.NameTag.h;
       SDL_UpperBlit(team.NameTag, nil, Surface, @r);
       r:= team.HealthRect;
-      r.w:= 2 + team.TeamHealth;
+      r.w:= 2 + team.TeamHealthBarWidth;
       DrawFromStoreRect(cScreenWidth div 2,
                         Team.DrawHealthY,
                         @r, Surface);
       inc(r.x, cTeamHealthWidth + 2);
       r.w:= 3;
-      DrawFromStoreRect(cScreenWidth div 2 + team.TeamHealth + 2,
+      DrawFromStoreRect(cScreenWidth div 2 + team.TeamHealthBarWidth + 2,
                         Team.DrawHealthY,
                         @r, Surface);
       team:= team.Next