Merge 0.9.17 with trunk 0.9.17
authornemo
Sat, 19 Nov 2011 14:30:58 -0500
branch0.9.17
changeset 6400 a057306acea6
parent 6375 fcea0c053bc1 (current diff)
parent 6398 33c92c4ac749 (diff)
child 6402 4670f003f91b
Merge 0.9.17 with trunk
--- a/ChangeLog.txt	Mon Nov 14 13:31:38 2011 -0500
+++ b/ChangeLog.txt	Sat Nov 19 14:30:58 2011 -0500
@@ -6,6 +6,7 @@
  + New voicepack, Hillbilly
  + More attractive mission screen with previews
  + Chat timestamping, links, input history, tab completion
+ + AI smarter, now uses switch. Also tweaks to mine/crate/barrel rules
  + Customisable chat by dragging a .css file, see file generated by the /saveStyleSheet command
  + Errors/warnings in chat instead of popup boxes
  + Mousewheel to change hog/weapon counts in game creation
@@ -19,6 +20,7 @@
  + Grenades/bazooka/melon pieces/ballgun now kicked by explosions
  + Minor theme optimisation, Optional SkyR
  + Camera follows melon, clusterbomb, gas cloud
+ * More fixes to fullscreen/window resize on non-Linux systems
  * Vertical movement should be restricted for small displays, camera will try less hard to keep hog in centre
  * Keep mouse from jumping around when ammo menu is active
  * Hogs can now move after trapping another hog in a portal loop
@@ -30,7 +32,7 @@
  * Girders no longer make windows in tunnels
  * Prevent some more escaping through border, firepunch, pickhammer
  * Many frontend bugfixes, code cleanup. Crash in game abort, flake clipping, invalid state on room close
- * Many other engine bugfixes.  SDL event crasher, timebox crasher, birdy hang, desync on quits, crash in birdy eggshell, clouds on Deep Space theme, etc
+ * Many other engine bugfixes.  SDL event crasher, timebox crasher, birdy hang, desync on quits, crash in birdy eggshell, hammer + vamp + invuln, clouds on Deep Space theme, etc
 
 0.9.15 -> 0.9.16:
  + In-game chat now supports backspace-repeat and Escape to close the text input area
--- a/QTfrontend/main.cpp	Mon Nov 14 13:31:38 2011 -0500
+++ b/QTfrontend/main.cpp	Sat Nov 19 14:30:58 2011 -0500
@@ -132,20 +132,7 @@
     if (checkForDir(cfgdir->absolutePath()))
     {
         // alternative loading/lookup paths
-        // TODO: Uncomment paths as they're implemented
         checkForDir(cfgdir->absolutePath() + "/Data");
-        //checkForDir(cfgdir->absolutePath() + "/Data/Forts");
-        //checkForDir(cfgdir->absolutePath() + "/Data/Graphics");
-        //checkForDir(cfgdir->absolutePath() + "/Data/Graphics/Flags");
-        //checkForDir(cfgdir->absolutePath() + "/Data/Graphics/Graves");
-        //checkForDir(cfgdir->absolutePath() + "/Data/Graphics/Hats");
-        //checkForDir(cfgdir->absolutePath() + "/Data/Maps");
-        //checkForDir(cfgdir->absolutePath() + "/Data/Missions");
-        //checkForDir(cfgdir->absolutePath() + "/Data/Missions/Campaign");
-        //checkForDir(cfgdir->absolutePath() + "/Data/Missions/Training");
-        //checkForDir(cfgdir->absolutePath() + "/Data/Sounds");
-        //checkForDir(cfgdir->absolutePath() + "/Data/Sounds/voices");
-        //checkForDir(cfgdir->absolutePath() + "/Data/Themes");
 
         // config/save paths
         checkForDir(cfgdir->absolutePath() + "/Demos");
--- a/QTfrontend/ui/page/pagedata.cpp	Mon Nov 14 13:31:38 2011 -0500
+++ b/QTfrontend/ui/page/pagedata.cpp	Sat Nov 19 14:30:58 2011 -0500
@@ -59,7 +59,7 @@
     initPage();
 
     web->setOpenLinks(false);
-    fetchList();
+//    fetchList();
 }
 
 void PageDataDownload::request(const QUrl &url)
--- a/hedgewars/GSHandlers.inc	Mon Nov 14 13:31:38 2011 -0500
+++ b/hedgewars/GSHandlers.inc	Sat Nov 19 14:30:58 2011 -0500
@@ -1300,7 +1300,7 @@
         end
     else
         begin
-        if CheckLandValue(hwRound(Gear^.X), hwRound(Gear^.Y + Gear^.dY + cGravity), lfIndestructible) then
+        if CheckLandValue(hwRound(Gear^.X), hwRound(Gear^.Y + Gear^.dY + cGravity), $FF00) then
             begin
             Gear^.dY := Gear^.dY + cGravity;
             Gear^.Y := Gear^.Y + Gear^.dY
@@ -1309,7 +1309,7 @@
         end;
 
     Gear^.X := Gear^.X + HHGear^.dX;
-    if CheckLandValue(hwRound(Gear^.X), hwRound(Gear^.Y)-cHHRadius, lfIndestructible) then
+    if CheckLandValue(hwRound(Gear^.X), hwRound(Gear^.Y)-cHHRadius, $FF00) then
         begin
         HHGear^.X := Gear^.X;
         HHGear^.Y := Gear^.Y - int2hwFloat(cHHRadius)
@@ -3641,7 +3641,7 @@
         begin
         Gear^.Damage:= i;
         //AddCaption('Fuel: '+inttostr(round(Gear^.Health/20))+'%', cWhiteColor, capgrpAmmostate);
-        if Gear^.Tex <> nil then FreeTexture(Gear^.Tex);
+        FreeTexture(Gear^.Tex);
         Gear^.Tex := RenderStringTex(trmsg[sidFuel] + ': ' + inttostr(i) +
                      '%', cWhiteColor, fntSmall)
         end;
@@ -4685,7 +4685,7 @@
         if (i <> Gear^.Damage) and ((GameTicks and $3F) = 0) then
             begin
             Gear^.Damage:= i;
-            if Gear^.Tex <> nil then FreeTexture(Gear^.Tex);
+            FreeTexture(Gear^.Tex);
             Gear^.Tex := RenderStringTex(trmsg[sidFuel] + ': ' + inttostr(i) +
                          '%', cWhiteColor, fntSmall)
             end
@@ -4757,7 +4757,7 @@
         if (i <> Gear^.Damage) and ((GameTicks and $3F) = 0) then
             begin
             Gear^.Damage:= i;
-            if Gear^.Tex <> nil then FreeTexture(Gear^.Tex);
+            FreeTexture(Gear^.Tex);
             Gear^.Tex := RenderStringTex(trmsg[sidFuel] + ': ' + inttostr(i) +
                          '%', cWhiteColor, fntSmall)
             end
@@ -4816,7 +4816,7 @@
         if (tmp^.Kind = gtHedgehog) or (tmp^.Kind = gtMine) or (tmp^.Kind = gtExplosives) then
             begin
             //tmp^.State:= tmp^.State or gstFlatened;
-            ApplyDamage(tmp, CurrentHedgehog, tmp^.Health div 3, dsUnknown);
+            if not tmp^.Invulnerable then ApplyDamage(tmp, CurrentHedgehog, tmp^.Health div 3, dsUnknown);
             //DrawTunnel(tmp^.X, tmp^.Y - _1, _0, _0_5, cHHRadius * 6, cHHRadius * 3);
             tmp2:= AddGear(hwRound(tmp^.X), hwRound(tmp^.Y), gtHammerHit, 0, _0, _0, 0);
             tmp2^.IntersectGear:= tmp;
--- a/hedgewars/uAI.pas	Mon Nov 14 13:31:38 2011 -0500
+++ b/hedgewars/uAI.pas	Sat Nov 19 14:30:58 2011 -0500
@@ -60,6 +60,49 @@
 BestActions.Pos:= 0
 end;
 
+
+
+const cBranchStackSize = 12;
+type TStackEntry = record
+                   WastedTicks: Longword;
+                   MadeActions: TActions;
+                   Hedgehog: TGear;
+                   end;
+
+var Stack: record
+           Count: Longword;
+           States: array[0..Pred(cBranchStackSize)] of TStackEntry;
+           end;
+
+function Push(Ticks: Longword; const Actions: TActions; const Me: TGear; Dir: integer): boolean;
+var bRes: boolean;
+begin
+    bRes:= (Stack.Count < cBranchStackSize) and (Actions.Count < MAXACTIONS - 5);
+    if bRes then
+        with Stack.States[Stack.Count] do
+            begin
+            WastedTicks:= Ticks;
+            MadeActions:= Actions;
+            Hedgehog:= Me;
+            Hedgehog.Message:= Dir;
+            inc(Stack.Count)
+            end;
+    Push:= bRes
+end;
+
+procedure Pop(var Ticks: Longword; var Actions: TActions; var Me: TGear);
+begin
+    dec(Stack.Count);
+    with Stack.States[Stack.Count] do
+        begin
+        Ticks:= WastedTicks;
+        Actions:= MadeActions;
+        Me:= Hedgehog
+        end
+end;
+
+
+
 procedure TestAmmos(var Actions: TActions; Me: PGear; isMoved: boolean);
 var BotLevel: Byte;
     ap: TAttackParams;
@@ -89,6 +132,7 @@
               begin
               BestActions:= Actions;
               inc(BestActions.Score, Score);
+              BestActions.isWalkingToABetterPlace:= false;
 
               if (ap.Angle > 0) then AddAction(BestActions, aia_LookRight, 0, 200, 0, 0)
               else if (ap.Angle < 0) then AddAction(BestActions, aia_LookLeft, 0, 200, 0, 0);
@@ -129,61 +173,23 @@
        end
 end;
 
-procedure Walk(Me: PGear);
+procedure Walk(Me: PGear; var Actions: TActions);
 const FallPixForBranching = cHHRadius * 2 + 8;
-      cBranchStackSize = 12;
-
-type TStackEntry = record
-                   WastedTicks: Longword;
-                   MadeActions: TActions;
-                   Hedgehog: TGear;
-                   end;
-
-var Stack: record
-           Count: Longword;
-           States: array[0..Pred(cBranchStackSize)] of TStackEntry;
-           end;
-
-    function Push(Ticks: Longword; const Actions: TActions; const Me: TGear; Dir: integer): boolean;
-    var bRes: boolean;
-    begin
-    bRes:= (Stack.Count < cBranchStackSize) and (Actions.Count < MAXACTIONS - 5);
-    if bRes then
-       with Stack.States[Stack.Count] do
-            begin
-            WastedTicks:= Ticks;
-            MadeActions:= Actions;
-            Hedgehog:= Me;
-            Hedgehog.Message:= Dir;
-            inc(Stack.Count)
-            end;
-    Push:= bRes
-    end;
-
-    procedure Pop(var Ticks: Longword; var Actions: TActions; var Me: TGear);
-    begin
-    dec(Stack.Count);
-    with Stack.States[Stack.Count] do
-         begin
-         Ticks:= WastedTicks;
-         Actions:= MadeActions;
-         Me:= Hedgehog
-         end
-    end;
-
-var Actions: TActions;
+var
     ticks, maxticks, steps, tmp: Longword;
     BaseRate, BestRate, Rate: integer;
     GoInfo: TGoInfo;
     CanGo: boolean;
     AltMe: TGear;
     BotLevel: Byte;
+    a: TAmmoType;
 begin
 ticks:= 0; // avoid compiler hint
-Actions.Count:= 0;
-Actions.Pos:= 0;
-Actions.Score:= 0;
 Stack.Count:= 0;
+
+for a:= Low(TAmmoType) to High(TAmmoType) do
+    CanUseAmmo[a]:= Assigned(AmmoTests[a].proc) and HHHasAmmo(Me^.Hedgehog^, a);
+
 BotLevel:= Me^.Hedgehog^.BotLevel;
 
 tmp:= random(2) + 1;
@@ -240,6 +246,7 @@
        if Rate > BestRate then
           begin
           BestActions:= Actions;
+          BestActions.isWalkingToABetterPlace:= true;
           BestRate:= Rate;
           Me^.State:= Me^.State or gstAttacked // we have better place, go there and do not use ammo
           end
@@ -256,40 +263,84 @@
 
 function Think(Me: Pointer): ptrint;
 var BackMe, WalkMe: TGear;
-    StartTicks: Longword;
+    StartTicks, currHedgehogIndex, itHedgehog, switchesNum, i: Longword;
+    switchImmediatelyAvailable, switchAvailable: boolean;
+    Actions: TActions;
 begin
 InterlockedIncrement(hasThread);
 StartTicks:= GameTicks;
-BackMe:= PGear(Me)^;
+currHedgehogIndex:= CurrentTeam^.CurrHedgehog;
+itHedgehog:= currHedgehogIndex;
+switchesNum:= 0;
+
+switchImmediatelyAvailable:= (CurAmmoGear <> nil) and (CurAmmoGear^.Kind = gtSwitcher);
+switchAvailable:= HHHasAmmo(PGear(Me)^.Hedgehog^, amSwitch);
 
 if (PGear(Me)^.State and gstAttacked) = 0 then
    if Targets.Count > 0 then
       begin
-      WalkMe:= BackMe;
-      Walk(@WalkMe);
-      if (StartTicks > GameTicks - 1500) and (not StopThinking) then SDL_Delay(1000);
-      if BestActions.Score < -1023 then
-         begin
-         BestActions.Count:= 0;
-         AddAction(BestActions, aia_Skip, 0, 250, 0, 0);
-         end;
+        // iterate over current team hedgehogs
+        repeat
+            WalkMe:= CurrentTeam^.Hedgehogs[itHedgehog].Gear^;
+
+            Actions.Count:= 0;
+            Actions.Pos:= 0;
+            Actions.Score:= 0;
+            if switchesNum > 0 then
+                begin
+                if not switchImmediatelyAvailable then
+                    begin
+                    // when AI has to use switcher, make it cost smth
+                    Actions.Score:= -20000;
+                    AddAction(Actions, aia_Weapon, Longword(amSwitch), 300 + random(200), 0, 0);                    
+                    AddAction(Actions, aia_attack, aim_push, 300 + random(300), 0, 0);
+                    AddAction(Actions, aia_attack, aim_release, 1, 0, 0);
+                    end;
+                for i:= 1 to switchesNum do
+                    AddAction(Actions, aia_Switch, 0, 300 + random(200), 0, 0);
+                end;
+            Walk(@WalkMe, Actions);
+
+            // find another hog in team
+            repeat
+                itHedgehog:= Succ(itHedgehog) mod CurrentTeam^.HedgehogsNumber;
+            until (itHedgehog = currHedgehogIndex) or (CurrentTeam^.Hedgehogs[itHedgehog].Gear <> nil);
+
+            inc(switchesNum);
+        until (not (switchImmediatelyAvailable or switchAvailable))
+            or StopThinking 
+            or (itHedgehog = currHedgehogIndex)
+            or BestActions.isWalkingToABetterPlace;
+
+        if (StartTicks > GameTicks - 1500) and (not StopThinking) then SDL_Delay(1000);
+
+        if (BestActions.Score < -1023) and (not BestActions.isWalkingToABetterPlace) then
+            begin
+            BestActions.Count:= 0;
+            AddAction(BestActions, aia_Skip, 0, 250, 0, 0);
+            end;
+
       end else
 else begin
-      while (not StopThinking) and (BestActions.Count = 0) do
-            begin
-            FillBonuses(true);
-            WalkMe:= BackMe;
-            Walk(@WalkMe);
-            if not StopThinking then SDL_Delay(100)
-            end
-      end;
+    BackMe:= PGear(Me)^;
+    while (not StopThinking) and (BestActions.Count = 0) do
+        begin
+        FillBonuses(true);
+        WalkMe:= BackMe;
+        Actions.Count:= 0;
+        Actions.Pos:= 0;
+        Actions.Score:= 0;
+        Walk(@WalkMe, Actions);
+        if not StopThinking then SDL_Delay(100)
+        end
+    end;
+
 PGear(Me)^.State:= PGear(Me)^.State and not gstHHThinking;
 Think:= 0;
 InterlockedDecrement(hasThread)
 end;
 
 procedure StartThink(Me: PGear);
-var a: TAmmoType;
 begin
 if ((Me^.State and (gstAttacking or gstHHJumping or gstMoving)) <> 0)
    or isInMultiShoot then exit;
@@ -301,6 +352,7 @@
 BestActions.Count:= 0;
 BestActions.Pos:= 0;
 BestActions.Score:= Low(LongInt);
+BestActions.isWalkingToABetterPlace:= false;
 
 StopThinking:= false;
 ThinkingHH:= Me;
@@ -313,8 +365,6 @@
    end;
 
 FillBonuses((Me^.State and gstAttacked) <> 0);
-for a:= Low(TAmmoType) to High(TAmmoType) do
-    CanUseAmmo[a]:= Assigned(AmmoTests[a].proc) and HHHasAmmo(Me^.Hedgehog^, a);
 AddFileLog('Enter Think Thread');
 BeginThread(@Think, Me, ThinkThread)
 end;
--- a/hedgewars/uAIActions.pas	Mon Nov 14 13:31:38 2011 -0500
+++ b/hedgewars/uAIActions.pas	Sat Nov 19 14:30:58 2011 -0500
@@ -30,6 +30,7 @@
       aia_attack     = 4;
       aia_Up         = 5;
       aia_Down       = 6;
+      aia_Switch     = 7;
 
       aia_Weapon     = $8000;
       aia_WaitXL     = $8001;
@@ -56,6 +57,7 @@
                 Count, Pos: Longword;
                 actions: array[0..Pred(MAXACTIONS)] of TAction;
                 Score: LongInt;
+                isWalkingToABetterPlace: boolean;
                 end;
 
 procedure AddAction(var Actions: TActions; Action: Longword; Param: LongInt; TimeDelta: Longword; X, Y: LongInt);
@@ -64,14 +66,15 @@
 implementation
 uses uAIMisc, uAI, uAmmos, uVariables, uCommands, uUtils, uDebug, uIO;
 
-const ActionIdToStr: array[0..6] of string[16] = (
+const ActionIdToStr: array[0..7] of string[16] = (
 {aia_none}           '',
 {aia_Left}           'left',
 {aia_Right}          'right',
 {aia_Timer}          'timer',
 {aia_attack}         'attack',
 {aia_Up}             'up',
-{aia_Down}           'down'
+{aia_Down}           'down',
+{aia_Switch}         'switch'
                      );
 
 {$IFDEF TRACEAIACTIONS}
--- a/hedgewars/uAIMisc.pas	Mon Nov 14 13:31:38 2011 -0500
+++ b/hedgewars/uAIMisc.pas	Sat Nov 19 14:30:58 2011 -0500
@@ -143,11 +143,11 @@
 // avoid mines unless they are very likely to be duds, or are duds. also avoid if they are about to blow 
           gtMine:  if ((Gear^.State and gstAttacking) = 0) and 
                       (((cMineDudPercent < 90) and (Gear^.Health <> 0)) or
-                       ((Gear^.Health = 0) and (Gear^.Damage > 30))) then
+                       (isAfterAttack and (Gear^.Health = 0) and (Gear^.Damage > 30))) then
                           AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 50, -50)
                       else if (Gear^.State and gstAttacking) <> 0 then
                           AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 100, -50); // mine is on
-          gtExplosives: AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 75, -60+Gear^.Health);
+          gtExplosives: if isAfterAttack then AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 75, -60+Gear^.Health);
           gtSMine:    AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 50, -30);
           gtDynamite: AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 150, -75);
           gtHedgehog: begin
--- a/hedgewars/uCaptions.pas	Mon Nov 14 13:31:38 2011 -0500
+++ b/hedgewars/uCaptions.pas	Sat Nov 19 14:30:58 2011 -0500
@@ -25,6 +25,7 @@
 
 procedure AddCaption(s: shortstring; Color: Longword; Group: TCapGroup);
 procedure DrawCaptions;
+procedure ReloadCaptions(unload: boolean);
 
 procedure initModule;
 procedure freeModule;
@@ -36,13 +37,14 @@
                    Tex: PTexture;
                    EndTime: LongWord;
                    Text: shortstring;
+                   Color: Longword
                    end;
 var
     Captions: array[TCapGroup] of TCaptionStr;
 
 procedure AddCaption(s: shortstring; Color: Longword; Group: TCapGroup);
 begin
-    if (Captions[Group].Tex <> nil) and (Captions[Group].Text <> s) then
+    if Captions[Group].Text <> s then
         begin
         FreeTexture(Captions[Group].Tex);
         Captions[Group].Tex:= nil
@@ -50,6 +52,7 @@
     
     if Captions[Group].Tex = nil then
         begin
+        Captions[Group].Color:= Color;
         Captions[Group].Text:= s;
         Captions[Group].Tex:= RenderStringTex(s, Color, fntBig)
         end;
@@ -61,6 +64,16 @@
     end;
 end;
 
+// For uStore texture recreation
+procedure ReloadCaptions(unload: boolean);
+var Group: TCapGroup;
+begin
+for Group:= Low(TCapGroup) to High(TCapGroup) do
+    if unload then FreeTexture(Captions[Group].Tex)
+    else if Captions[Group].Text <> '' then
+        Captions[Group].Tex:= RenderStringTex(Captions[Group].Text, Captions[Group].Color, fntBig)
+end;
+
 procedure DrawCaptions;
 var
     grp: TCapGroup;
@@ -75,16 +88,17 @@
     for grp:= Low(TCapGroup) to High(TCapGroup) do
         with Captions[grp] do
             if Tex <> nil then
-            begin
+                begin
                 DrawCentered(0, offset, Tex);
                 inc(offset, Tex^.h + 2);
                 if EndTime <= RealTicks then
-                begin
+                    begin
                     FreeTexture(Tex);
                     Tex:= nil;
+                    Text:= '';
                     EndTime:= 0
+                    end;
                 end;
-            end;
 end;
 
 procedure initModule;
@@ -93,13 +107,13 @@
 end;
 
 procedure freeModule;
-var
-    group: TCapGroup;
+var group: TCapGroup;
 begin
     for group:= Low(TCapGroup) to High(TCapGroup) do
-    begin
+        begin
         FreeTexture(Captions[group].Tex);
-    end;
+        Captions[group].Tex:= nil
+        end
 end;
 
 end.
--- a/hedgewars/uChat.pas	Mon Nov 14 13:31:38 2011 -0500
+++ b/hedgewars/uChat.pas	Sat Nov 19 14:30:58 2011 -0500
@@ -24,6 +24,7 @@
 
 procedure initModule;
 procedure freeModule;
+procedure ReloadLines;
 
 procedure AddChatString(s: shortstring);
 procedure DrawChat;
@@ -72,15 +73,15 @@
 cl.s:= str;
 
 if isInput then
-begin
+    begin
     color:= colors[#6];
     str:= UserNick + '> ' + str + '_'
-end
+    end
 else
-begin
+    begin
     color:= colors[str[1]];
     delete(str, 1, 1)
-end;
+    end;
 
 font:= CheckCJKFont(str, fnt16);
 w:= 0; h:= 0; // avoid compiler hints
@@ -99,6 +100,20 @@
 SDL_FreeSurface(resSurface)
 end;
 
+// For uStore texture recreation
+procedure ReloadLines;
+var i, t: LongWord;
+begin
+    if InputStr.s <> '' then SetLine(InputStr, InputStr.s, true);
+    for i:= 0 to MaxStrIndex do
+        if Strs[i].s <> '' then
+            begin
+            t:= Strs[i].Time;
+            SetLine(Strs[i], Strs[i].s, false);
+            Strs[i].Time:= t
+            end;
+end;
+
 procedure AddChatString(s: shortstring);
 begin
 if not ChatReady then
@@ -370,20 +385,14 @@
     missedCount:= 0;
 
     inputStr.Tex := nil;
-    for i:= 0 to MaxStrIndex do
-    begin
-        Strs[i].Tex := nil;
-    end;
+    for i:= 0 to MaxStrIndex do Strs[i].Tex := nil;
 end;
 
 procedure freeModule;
 var i: ShortInt;
 begin
     FreeTexture(InputStr.Tex);
-    for i:= 0 to MaxStrIndex do
-    begin
-        FreeTexture(Strs[i].Tex);
-    end;
+    for i:= 0 to MaxStrIndex do FreeTexture(Strs[i].Tex);
 end;
 
 end.
--- a/hedgewars/uGears.pas	Mon Nov 14 13:31:38 2011 -0500
+++ b/hedgewars/uGears.pas	Sat Nov 19 14:30:58 2011 -0500
@@ -591,11 +591,8 @@
 
 DeleteCI(Gear);
 
-if Gear^.Tex <> nil then
-    begin
-    FreeTexture(Gear^.Tex);
-    Gear^.Tex:= nil
-    end;
+FreeTexture(Gear^.Tex);
+Gear^.Tex:= nil;
 
 // make sure that portals have their link removed before deletion
 if (Gear^.Kind = gtPortal) then
@@ -660,7 +657,7 @@
             with CurrentHedgehog^ do 
                 begin
                 inc(Team^.stats.AIKills);
-                if Team^.AIKillsTex <> nil then FreeTexture(Team^.AIKillsTex);
+                FreeTexture(Team^.AIKillsTex);
                 Team^.AIKillsTex := RenderStringTex(inttostr(Team^.stats.AIKills), Team^.Clan^.Color, fnt16);
                 end
         end;
@@ -803,7 +800,7 @@
         begin
         if Gear^.RenderTimer and (Gear^.Timer > 500) and ((Gear^.Timer mod 1000) = 0) then
             begin
-            if Gear^.Tex <> nil then FreeTexture(Gear^.Tex);
+            FreeTexture(Gear^.Tex);
             Gear^.Tex:= RenderStringTex(inttostr(Gear^.Timer div 1000), cWhiteColor, fntSmall);
             end;
         Gear^.doStep(Gear);
@@ -1684,7 +1681,7 @@
         with CurrentHedgehog^ do 
             begin
             inc(Team^.stats.AIKills);
-            if Team^.AIKillsTex <> nil then FreeTexture(Team^.AIKillsTex);
+            FreeTexture(Team^.AIKillsTex);
             Team^.AIKillsTex := RenderStringTex(inttostr(Team^.stats.AIKills), Team^.Clan^.Color, fnt16);
             end;
     tempTeam := gear^.Hedgehog^.Team;
--- a/hedgewars/uLandTexture.pas	Mon Nov 14 13:31:38 2011 -0500
+++ b/hedgewars/uLandTexture.pas	Sat Nov 19 14:30:58 2011 -0500
@@ -31,7 +31,7 @@
 implementation
 uses uConsts, GLunit, uTypes, uVariables, uTextures, uDebug, uRender;
 
-const TEXSIZE = 256;
+const TEXSIZE = 512;
 
 type TLandRecord = record
             shouldUpdate: boolean;
@@ -139,11 +139,11 @@
 procedure ResetLand;
 var x, y: LongInt;
 begin
-    for x:= 0 to LANDTEXARW -1 do
+    for x:= 0 to LANDTEXARW - 1 do
         for y:= 0 to LANDTEXARH - 1 do
             with LandTextures[x, y] do
                 begin
-                if tex <> nil then FreeTexture(tex);
+                FreeTexture(tex);
                 tex:= nil;
                 end;
 end;
--- a/hedgewars/uRender.pas	Mon Nov 14 13:31:38 2011 -0500
+++ b/hedgewars/uRender.pas	Sat Nov 19 14:30:58 2011 -0500
@@ -45,8 +45,6 @@
 procedure Tint(r, g, b, a: Byte); inline;
 procedure Tint(c: Longword); inline;
 
-var
-    HHTexture: PTexture;
 
 implementation
 uses uVariables;
--- a/hedgewars/uScript.pas	Mon Nov 14 13:31:38 2011 -0500
+++ b/hedgewars/uScript.pas	Sat Nov 19 14:30:58 2011 -0500
@@ -725,7 +725,7 @@
             gear^.Hedgehog^.Name:= hogName;
 
 	    FreeTexture(gear^.Hedgehog^.NameTagTex);
-            gear^.Hedgehog^.NameTagTex:= RenderStringTex(gear^.Hedgehog^.Name, gear^.Hedgehog^.Team^.Clan^.Color, fnt16);
+        gear^.Hedgehog^.NameTagTex:= RenderStringTex(gear^.Hedgehog^.Name, gear^.Hedgehog^.Team^.Clan^.Color, fnt16);
 
         end;
     lc_sethogname:= 0;
--- a/hedgewars/uStore.pas	Mon Nov 14 13:31:38 2011 -0500
+++ b/hedgewars/uStore.pas	Sat Nov 19 14:30:58 2011 -0500
@@ -21,7 +21,7 @@
 
 unit uStore;
 interface
-uses sysutils, uConsts, SDLh, GLunit, uTypes, uLandTexture;
+uses sysutils, uConsts, SDLh, GLunit, uTypes, uLandTexture, uCaptions, uChat;
 
 procedure initModule;
 procedure freeModule;
@@ -42,7 +42,7 @@
 procedure MakeCrossHairs;
 
 implementation
-uses uMisc, uConsole, uMobile, uVariables, uUtils, uTextures, uRender, uRenderUtils, uCommands, uDebug;
+uses uMisc, uConsole, uMobile, uVariables, uUtils, uTextures, uRender, uRenderUtils, uCommands, uDebug, uWorld;
 
 //type TGPUVendor = (gvUnknown, gvNVIDIA, gvATI, gvIntel, gvApple);
 
@@ -110,7 +110,7 @@
     if SDL_MustLock(texsurf) then
         SDL_UnlockSurface(texsurf);
 
-    if CrosshairTex <> nil then FreeTexture(CrosshairTex);
+    FreeTexture(CrosshairTex);
     CrosshairTex:= Surface2Tex(texsurf, false);
     SDL_FreeSurface(texsurf)
     end;
@@ -277,8 +277,9 @@
 WriteNames(fnt16);
 MakeCrossHairs;
 LoadGraves;
+if not reload then
+    AddProgress;
 
-AddProgress;
 for ii:= Low(TSprite) to High(TSprite) do
     with SpritesData[ii] do
         // FIXME - add a sprite attribute to match on rq flags?
@@ -358,7 +359,8 @@
                 Surface:= nil
         end;
 
-AddProgress;
+if not reload then
+    AddProgress;
 
 tmpsurf:= LoadImage(UserPathz[ptGraphics] + '/' + cHHFileName, ifAlpha or ifTransparent);
 if tmpsurf = nil then tmpsurf:= LoadImage(Pathz[ptGraphics] + '/' + cHHFileName, ifAlpha or ifCritical or ifTransparent);
@@ -371,34 +373,34 @@
 ConfirmTexture:= RenderStringTex(trmsg[sidConfirm], cYellowColor, fntBig);
 SyncTexture:= RenderStringTex(trmsg[sidSync], cYellowColor, fntBig);
 
-AddProgress;
+if not reload then
+    AddProgress;
 
 // name of weapons in ammo menu
 for ai:= Low(TAmmoType) to High(TAmmoType) do
     with Ammoz[ai] do
-    begin
+        begin
         TryDo(trAmmo[NameId] <> '','No default text/translation found for ammo type #' + intToStr(ord(ai)) + '!',true);
         tmpsurf:= TTF_RenderUTF8_Blended(Fontz[CheckCJKFont(trAmmo[NameId],fnt16)].Handle, Str2PChar(trAmmo[NameId]), cWhiteColorChannels);
         TryDo(tmpsurf <> nil,'Name-texture creation for ammo type #' + intToStr(ord(ai)) + ' failed!',true);
         tmpsurf:= doSurfaceConversion(tmpsurf);
-        if (NameTex <> nil) then
-            FreeTexture(NameTex);
+        FreeTexture(NameTex);
         NameTex:= Surface2Tex(tmpsurf, false);
         SDL_FreeSurface(tmpsurf)
-    end;
+        end;
 
 // number of weapons in ammo menu
 for i:= Low(CountTexz) to High(CountTexz) do
 begin
     tmpsurf:= TTF_RenderUTF8_Blended(Fontz[fnt16].Handle, Str2PChar(IntToStr(i) + 'x'), cWhiteColorChannels);
     tmpsurf:= doSurfaceConversion(tmpsurf);
-    if (CountTexz[i] <> nil) then
-        FreeTexture(CountTexz[i]);
+    FreeTexture(CountTexz[i]);
     CountTexz[i]:= Surface2Tex(tmpsurf, false);
     SDL_FreeSurface(tmpsurf)
 end;
 
-AddProgress;
+if not reload then
+    AddProgress;
 IMG_Quit();
 end;
 
@@ -418,16 +420,21 @@
             end
         end;
     SDL_FreeSurface(MissionIcons);
+
+    // free the textures declared in uVariables
+    FreeTexture(WeaponTooltipTex);
+    WeaponTooltipTex:= nil;
+    FreeTexture(PauseTexture);
+    PauseTexture:= nil;
+    FreeTexture(SyncTexture);
+    SyncTexture:= nil;
+    FreeTexture(ConfirmTexture);
+    ConfirmTexture:= nil;
     FreeTexture(ropeIconTex);
     ropeIconTex:= nil;
     FreeTexture(HHTexture);
     HHTexture:= nil;
-    FreeTexture(PauseTexture);
-    PauseTexture:= nil;
-    FreeTexture(ConfirmTexture);
-    ConfirmTexture:= nil;
-    FreeTexture(SyncTexture);
-    SyncTexture:= nil;
+
     // free all ammo name textures
     for ai:= Low(TAmmoType) to High(TAmmoType) do
         begin
@@ -444,9 +451,9 @@
 
     // free all team and hedgehog textures
     for t:= 0 to Pred(TeamsCount) do
-    begin
+        begin
         if TeamsArray[t] <> nil then
-        begin
+            begin
             FreeTexture(TeamsArray[t]^.NameTagTex);
             TeamsArray[t]^.NameTagTex:= nil;
             FreeTexture(TeamsArray[t]^.CrosshairTex);
@@ -460,26 +467,26 @@
             FreeTexture(TeamsArray[t]^.FlagTex);
             TeamsArray[t]^.FlagTex:= nil;
             for i:= 0 to cMaxHHIndex do
-            begin
+                begin
                 FreeTexture(TeamsArray[t]^.Hedgehogs[i].NameTagTex);
                 TeamsArray[t]^.Hedgehogs[i].NameTagTex:= nil;
                 FreeTexture(TeamsArray[t]^.Hedgehogs[i].HealthTagTex);
                 TeamsArray[t]^.Hedgehogs[i].HealthTagTex:= nil;
                 FreeTexture(TeamsArray[t]^.Hedgehogs[i].HatTex);
                 TeamsArray[t]^.Hedgehogs[i].HatTex:= nil;
+                end;
             end;
         end;
-    end;
 {$IFNDEF S3D_DISABLED}
     if (cStereoMode = smHorizontal) or (cStereoMode = smVertical) or (cStereoMode = smAFR) then
-    begin
+        begin
         glDeleteTextures(1, @texl);
         glDeleteRenderbuffersEXT(1, @depthl);
         glDeleteFramebuffersEXT(1, @framel);
         glDeleteTextures(1, @texr);
         glDeleteRenderbuffersEXT(1, @depthr);
         glDeleteFramebuffersEXT(1, @framer)
-    end
+        end
 {$ENDIF}
 end;
 
@@ -488,8 +495,7 @@
 var s: shortstring;
 begin
     str(Hedgehog.Gear^.Health, s);
-    if Hedgehog.HealthTagTex <> nil then
-        FreeTexture(Hedgehog.HealthTagTex);
+    FreeTexture(Hedgehog.HealthTagTex);
     Hedgehog.HealthTagTex:= RenderStringTex(s, Hedgehog.Team^.Clan^.Color, fnt16)
 end;
 
@@ -763,9 +769,10 @@
 
 procedure FinishProgress;
 begin
+    uMobile.GameLoaded();
     WriteLnToConsole('Freeing progress surface... ');
     FreeTexture(ProgrTex);
-    uMobile.GameLoaded();
+    ProgrTex:= nil;
     Step:= 0
 end;
 
@@ -938,8 +945,6 @@
 procedure FreeWeaponTooltip;
 begin
 // free the existing texture (if there is any)
-if WeaponTooltipTex = nil then
-    exit;
 FreeTexture(WeaponTooltipTex);
 WeaponTooltipTex:= nil
 end;
@@ -978,6 +983,10 @@
         SetScale(cDefaultZoomLevel);
 {$IF DEFINED(DARWIN) OR DEFINED(WIN32)}
         reinit:= true;
+        StoreRelease(true);
+        ResetLand;
+        ResetWorldTex;
+        //uTextures.freeModule; //DEBUG ONLY
 {$ENDIF}
         AddFileLog('Freeing old primary surface...');
         SDL_FreeSurface(SDLPrimSurface);
@@ -1032,18 +1041,20 @@
     SetupOpenGL();
     if reinit then
         begin
+        // clean the window from any previous content
+        glClear(GL_COLOR_BUFFER_BIT);
         if SuddenDeathDmg then
              glClearColor(SDSkyColor.r * (SDTint/255) / 255, SDSkyColor.g * (SDTint/255) / 255, SDSkyColor.b * (SDTint/255) / 255, 0.99)
         else if ((cReducedQuality and rqNoBackground) = 0) then 
              glClearColor(SkyColor.r / 255, SkyColor.g / 255, SkyColor.b / 255, 0.99)
         else glClearColor(RQSkyColor.r / 255, RQSkyColor.g / 255, RQSkyColor.b / 255, 0.99);
 
-        StoreRelease(true);
+        // reload everything we had before
+        ReloadCaptions(false);
+        ReloadLines;
         StoreLoad(true);
-
-        ResetLand;
-
-        UpdateLandTexture(0, LAND_WIDTH, 0, LAND_HEIGHT)
+        // redraw all land
+        UpdateLandTexture(0, LAND_WIDTH, 0, LAND_HEIGHT);
         end;
 end;
 
--- a/hedgewars/uTextures.pas	Mon Nov 14 13:31:38 2011 -0500
+++ b/hedgewars/uTextures.pas	Sat Nov 19 14:30:58 2011 -0500
@@ -31,7 +31,7 @@
 procedure freeModule;
 
 implementation
-uses GLunit, uUtils, uVariables, uConsts, uDebug;
+uses GLunit, uUtils, uVariables, uConsts, uDebug, uConsole;
 
 var TextureList: PTexture;
 
@@ -207,7 +207,7 @@
 procedure FreeTexture(tex: PTexture);
 begin
     if tex <> nil then
-    begin
+        begin
         if tex^.NextTexture <> nil then
             tex^.NextTexture^.PrevTexture:= tex^.PrevTexture;
         if tex^.PrevTexture <> nil then
@@ -216,7 +216,7 @@
             TextureList:= tex^.NextTexture;
         glDeleteTextures(1, @tex^.id);
         Dispose(tex);
-    end
+        end
 end;
 
 procedure initModule;
@@ -226,7 +226,12 @@
 
 procedure freeModule;
 begin
-    while TextureList <> nil do FreeTexture(TextureList);
+    if TextureList <> nil then WriteToConsole('FIXME FIXME FIXME. App shutdown without full cleanup of texture list; read game0.log and please report this problem');
+    while TextureList <> nil do 
+        begin
+        AddFileLog('Texture not freed: width='+inttostr(LongInt(TextureList^.w))+' height='+inttostr(LongInt(TextureList^.h))+' priority='+inttostr(round(TextureList^.priority*1000)));
+        FreeTexture(TextureList);
+        end
 end;
 
 end.
--- a/hedgewars/uVariables.pas	Mon Nov 14 13:31:38 2011 -0500
+++ b/hedgewars/uVariables.pas	Sat Nov 19 14:30:58 2011 -0500
@@ -150,7 +150,8 @@
     cLaserSighting  : boolean;
     cVampiric       : boolean;
     cArtillery      : boolean;
-    WeaponTooltipTex : PTexture;
+    WeaponTooltipTex: PTexture;
+    HHTexture       : PTexture;
 
     flagMakeCapture : boolean;
 
--- a/hedgewars/uVisualGears.pas	Mon Nov 14 13:31:38 2011 -0500
+++ b/hedgewars/uVisualGears.pas	Sat Nov 19 14:30:58 2011 -0500
@@ -401,8 +401,7 @@
 
 procedure DeleteVisualGear(Gear: PVisualGear);
 begin
-    if Gear^.Tex <> nil then
-        FreeTexture(Gear^.Tex);
+    FreeTexture(Gear^.Tex);
     Gear^.Tex:= nil;
 
     if Gear^.NextGear <> nil then Gear^.NextGear^.PrevGear:= Gear^.PrevGear;
--- a/hedgewars/uWorld.pas	Mon Nov 14 13:31:38 2011 -0500
+++ b/hedgewars/uWorld.pas	Sat Nov 19 14:30:58 2011 -0500
@@ -27,6 +27,8 @@
 procedure freeModule;
 
 procedure InitWorld;
+procedure ResetWorldTex;
+
 procedure DrawWorld(Lag: LongInt);
 procedure DrawWorldStereo(Lag: LongInt; RM: TRenderMode);
 procedure ShowMission(caption, subcaption, text: ansistring; icon, time : LongInt);
@@ -212,6 +214,17 @@
 cGearScrEdgesDist:= min(2 * cScreenHeight div 5, 2 * cScreenWidth div 5);
 end;
 
+// for uStore texture resetting
+procedure ResetWorldTex;
+begin
+    FreeTexture(fpsTexture);
+    fpsTexture:= nil;
+    FreeTexture(timeTexture);
+    timeTexture:= nil;
+    FreeTexture(missionTex);
+    missionTex:= nil;
+end;
+
 procedure ShowAmmoMenu;
 const MENUSPEED = 15;
 const BORDERSIZE = 2;
@@ -1087,12 +1100,10 @@
         if t < 10 then s:= '0' + s;
         s:= inttostr(i div 60) + ':' + s;
    
-        if timeTexture <> nil then
-            FreeTexture(timeTexture);
-        timeTexture:= nil;
     
         tmpSurface:= TTF_RenderUTF8_Blended(Fontz[fnt16].Handle, Str2PChar(s), cWhiteColorChannels);
         tmpSurface:= doSurfaceConversion(tmpSurface);
+        FreeTexture(timeTexture);
         timeTexture:= Surface2Tex(tmpSurface, false);
         SDL_FreeSurface(tmpSurface)
     end;
@@ -1108,11 +1119,9 @@
             Frames:= 0;
             CountTicks:= 0;
             s:= inttostr(FPS) + ' fps';
-            if fpsTexture <> nil then
-                FreeTexture(fpsTexture);
-            fpsTexture:= nil;
             tmpSurface:= TTF_RenderUTF8_Blended(Fontz[fnt16].Handle, Str2PChar(s), cWhiteColorChannels);
             tmpSurface:= doSurfaceConversion(tmpSurface);
+            FreeTexture(fpsTexture);
             fpsTexture:= Surface2Tex(tmpSurface, false);
             SDL_FreeSurface(tmpSurface)
         end;
@@ -1316,9 +1325,7 @@
 
 if time = 0 then time:= 5000;
 missionTimer:= time;
-if missionTex <> nil then
-    FreeTexture(missionTex);
-missionTex:= nil;
+FreeTexture(missionTex);
 
 if icon > -1 then
     begin
@@ -1384,8 +1391,11 @@
 begin
     stereoDepth:= stereoDepth; // avoid hint
     FreeTexture(fpsTexture);
+    fpsTexture:= nil;
     FreeTexture(timeTexture);
+    timeTexture:= nil;
     FreeTexture(missionTex);
+    missionTex:= nil
 end;
 
 end.
--- a/share/hedgewars/Data/Scripts/Multiplayer/Highlander.lua	Mon Nov 14 13:31:38 2011 -0500
+++ b/share/hedgewars/Data/Scripts/Multiplayer/Highlander.lua	Sat Nov 19 14:30:58 2011 -0500
@@ -1,6 +1,6 @@
 --------------------------------
 -- HIGHLANDER / HOGS OF WAR
--- version 0.3
+-- version 0.3b
 -- by mikade
 --------------------------------
 
@@ -32,27 +32,23 @@
 
 -- mudball is now counted as a utility
 
-----------------
--- other ideas
-----------------
+-----------
+--0.3b
+-----------
 
--- circles to mark hogs with more than 4 weapons
--- health crate and switch drops
--- hogs start with 1 weap and 1 utility each (some are rarer than others?)
--- could always create a "donor card" mini circle instead of automatic disposal
-
+-- cleaned up code and got rid of unneccessary vars
+-- mudball is a weapon again
+-- landgun is now a utility
+-- extra time, vampirism utility removed
+-- hammer wep removed
+-- all hogs have kamikaze
 
 loadfile(GetDataPath() .. "Scripts/Locale.lua")()
 loadfile(GetDataPath() .. "Scripts/Tracker.lua")()
 
 local wepArray = {}
-local wepArrayCount = 0
-
 local atkArray = {}
-local atkCount = 0
-
 local utilArray = {}
-local utilArrayCount = 0
 
 local currName
 local lastName
@@ -61,14 +57,16 @@
 
 function StartingSetUp(gear)
 
-	for i = 0, (wepArrayCount-1) do
+	for i = 1, #wepArray do	
 		setGearValue(gear,wepArray[i],0)
 	end
 
-	i = GetRandom(atkArrayCount)
+	setGearValue(gear,amKamikaze,1)
+
+	i = 1 + GetRandom(#atkArray)
 	setGearValue(gear,atkArray[i],1)
 
-	i = GetRandom(utilArrayCount)
+	i = 1 + GetRandom(#utilArray)
 	setGearValue(gear,utilArray[i],1)
 
 	SetHealth(gear, 100)
@@ -78,7 +76,7 @@
 --[[function SaveWeapons(gear)
 
 	-
-	for i = 0, (wepArrayCount-1) do
+	for i = 1, (#wepArray) do
 		setGearValue(gear, wepArray[i], GetAmmoCount(gear, wepArray[i]) )
 		 --AddAmmo(gear, wepArray[i], getGearValue(gear,wepArray[i]) )
 	end
@@ -87,7 +85,7 @@
 
 function ConvertValues(gear)
 
-	for i = 0, (wepArrayCount-1) do
+	for i = 1, #wepArray do	
 		AddAmmo(gear, wepArray[i], getGearValue(gear,wepArray[i]) )
 	end
 
@@ -99,7 +97,7 @@
 
 	if CurrentHedgehog ~= nil then
 
-		for i = 0, (wepArrayCount-1) do
+		for i = 1, #wepArray do		
 			val = getGearValue(gear,wepArray[i])
 			if val ~= 0 then
 				setGearValue(CurrentHedgehog, wepArray[i], val)
@@ -132,150 +130,41 @@
 				"", 4, 4000
 				)
 
-	atkArray[0] = amBazooka
-	atkArray[1] = amBee
-	atkArray[2] = amMortar
-	atkArray[3] = amDrill
-	--atkArray[4] = amSnowball
-
-	atkArray[4] = amGrenade
-	atkArray[5] = amClusterBomb
-	atkArray[6] = amMolotov
-	atkArray[7] = amWatermelon
-	atkArray[8] = amHellishBomb
-	atkArray[9] = amGasBomb
-
-	atkArray[10] = amShotgun
-	atkArray[11] = amDEagle
-	atkArray[12] = amFlamethrower
-	atkArray[13] = amSniperRifle
-	atkArray[14] = amSineGun
-
-	atkArray[15] = amFirePunch
-	atkArray[16] = amWhip
-	atkArray[17] = amBaseballBat
-	--atkArray[19] = amKamikaze
-	atkArray[18] = amBirdy
-	atkArray[19] = amSeduction
-	atkArray[20] = amHammer
-
-	atkArray[21] = amMine
-	atkArray[22] = amDynamite
-	atkArray[23] = amCake
-	atkArray[24] = amBallgun
-	atkArray[25] = amRCPlane
-	atkArray[26] = amSMine
+	atkArray = 	{amBazooka, amBee, amMortar, amDrill, --[[amSnowball,]]
+			amGrenade, amClusterBomb, amMolotov, amWatermelon, amHellishBomb, amGasBomb,
+			amShotgun, amDEagle, amFlamethrower, amSniperRifle, amSineGun,
+			amFirePunch, amWhip, amBaseballBat, --[[amKamikaze,]] amSeduction, --[[amHammer,]]
+			amMine, amDynamite, amCake, amBallgun, amRCPlane, amSMine,
+			amAirAttack, amMineStrike, amDrillStrike, --[[amPiano,]] amRCPlane, amSMine,
+			amBirdy
 
-	atkArray[27] = amAirAttack
-	atkArray[28] = amMineStrike
-	atkArray[29] = amDrillStrike
-	atkArray[30] = amNapalm
-	--atkArray[32] = amPiano
-	atkArray[31] = amLandGun
-
-	--atkArray[33] = amBirdy
-	--atkArray[34] = amLandGun
-
-	atkArrayCount = 32
-
-	-------------------------------
-
+			} 
 
-	wepArray[0] = amBazooka
-	wepArray[1] = amBee
-	wepArray[2] = amMortar
-	wepArray[3] = amDrill
-	wepArray[4] = amSnowball
-
-	wepArray[5] = amGrenade
-	wepArray[6] = amClusterBomb
-	wepArray[7] = amMolotov
-	wepArray[8] = amWatermelon
-	wepArray[9] = amHellishBomb
-	wepArray[10] = amGasBomb
-
-	wepArray[11] = amShotgun
-	wepArray[12] = amDEagle
-	wepArray[13] = amFlamethrower
-	wepArray[14] = amSniperRifle
-	wepArray[15] = amSineGun
+	utilArray = 	{amBlowTorch, amPickHammer, amGirder, amPortalGun,
+			amRope, amParachute, amTeleport, amJetpack,
+			amInvulnerable, amLaserSight, --[[amVampiric,]]
+			amLowGravity, amExtraDamage, --[[amExtraTime,]]
+			amLandGun
+			}
 
-	wepArray[16] = amFirePunch
-	wepArray[17] = amWhip
-	wepArray[18] = amBaseballBat
-	--wepArray[19] = amKamikaze
-	wepArray[19] = amExtraTime
-	wepArray[20] = amSeduction
-	wepArray[21] = amHammer
-
-	wepArray[22] = amMine
-	wepArray[23] = amDynamite
-	wepArray[24] = amCake
-	wepArray[25] = amBallgun
-	wepArray[26] = amRCPlane
-	wepArray[27] = amSMine
-
-	wepArray[28] = amAirAttack
-	wepArray[29] = amMineStrike
-	wepArray[30] = amDrillStrike
-	wepArray[31] = amNapalm
-	--wepArray[32] = amPiano
-	wepArray[32] = amExtraDamage
-
-	wepArray[33] = amBirdy
-	wepArray[34] = amLandGun
-
-	wepArray[35] = amBlowTorch
-	wepArray[36] = amPickHammer
-	wepArray[37] = amGirder
-	wepArray[38] = amPortalGun
-
-	wepArray[39] = amRope
-	wepArray[40] = amParachute
-	wepArray[41] = amTeleport
-	wepArray[42] = amJetpack
+	wepArray = 	{amBazooka, amBee, amMortar, amDrill, --[[amSnowball,]]
+			amGrenade, amClusterBomb, amMolotov, amWatermelon, amHellishBomb, amGasBomb,
+			amShotgun, amDEagle, amFlamethrower, amSniperRifle, amSineGun,
+			amFirePunch, amWhip, amBaseballBat, --[[amKamikaze,]] amSeduction, --[[amHammer,]]
+			amMine, amDynamite, amCake, amBallgun, amRCPlane, amSMine,
+			amAirAttack, amMineStrike, amDrillStrike, --[[amPiano,]] amRCPlane, amSMine,
+			amBirdy,
+			
+			amBlowTorch, amPickHammer, amGirder, amPortalGun,
+			amRope, amParachute, amTeleport, amJetpack,
+			amInvulnerable, amLaserSight, --[[amVampiric,]]
+			amLowGravity, amExtraDamage, --[[amExtraTime,]]
+			amLandGun
 
-	wepArray[43] = amInvulnerable
-	wepArray[44] = amLaserSight
-	wepArray[45] = amVampiric
-	----resurrector used to be here
-
-	wepArray[46] = amLowGravity
-
-	--wepArray[47] = amExtraDamage -- see 19
-	--wepArray[48] = amExtraTime	-- see 32
-
-	--wepArray[49] = amResurrector
-	--wepArray[50] = amTardis
-
-	wepArrayCount = 47
-
-	----------------------------
+			}
 
-	utilArray[0] = amBlowTorch
-	utilArray[1] = amPickHammer
-	utilArray[2] = amGirder
-	utilArray[3] = amPortalGun
-
-	utilArray[4] = amRope
-	utilArray[5] = amParachute
-	utilArray[6] = amTeleport
-	utilArray[7] = amJetpack
-
-	utilArray[8] = amInvulnerable
-	utilArray[9] = amLaserSight
-	utilArray[10] = amVampiric
-
-	utilArray[11] = amLowGravity
-	utilArray[12] = amExtraDamage
-	utilArray[13] = amExtraTime
-
-	utilArray[14] = amSnowball
-
-	--utilArray[14] = amResurrector
-	--utilArray[15] = amTardis
-
-	utilArrayCount = 15
+	-- REMOVED
+	-- amTardis, amResurrector, amSwitch 
 
 	runOnGears(StartingSetUp)
 	runOnGears(ConvertValues)
@@ -335,6 +224,7 @@
 
 function onAmmoStoreInit()
 	SetAmmo(amSkip, 9, 0, 0, 0)
+	SetAmmo(amKamikaze, 9, 0, 0, 0)
 	--SetAmmo(amSwitch, 9, 0, 0, 0) -------1
 end
 
--- a/tools/PascalParser.hs	Mon Nov 14 13:31:38 2011 -0500
+++ b/tools/PascalParser.hs	Sat Nov 19 14:30:58 2011 -0500
@@ -36,7 +36,7 @@
     | UnknownType
     deriving Show
 data Range = Range Identifier
-           | RangeFromTo Expression Expression
+           | RangeFromTo InitExpression InitExpression
     deriving Show
 data Initialize = Initialize String
     deriving Show
@@ -55,6 +55,7 @@
         | Assignment Reference Expression
     deriving Show
 data Expression = Expression String
+    | BuiltInFunCall [Expression] Reference
     | PrefixOp String Expression
     | PostfixOp String Expression
     | BinOp String Expression Expression
@@ -68,7 +69,6 @@
     deriving Show
 data Reference = ArrayElement [Expression] Reference
     | FunCall [Expression] Reference
-    | BuiltInFunCall [Expression] Reference
     | SimpleReference Identifier
     | Dereference Reference
     | RecordField Reference Reference
@@ -84,9 +84,12 @@
     | InitHexNumber String
     | InitString String
     | InitChar String
+    | BuiltInFunction String [InitExpression]
+    | InitSet [Identifier]
     | InitNull
     deriving Show
 
+builtin = ["succ", "pred", "low", "high"]
     
 pascalLanguageDef
     = emptyDef
@@ -103,13 +106,16 @@
             , "type", "var", "const", "out", "array", "packed"
             , "procedure", "function", "with", "for", "to"
             , "downto", "div", "mod", "record", "set", "nil"
-            , "string", "shortstring", "succ", "pred", "low"
-            , "high"
-            ]
+            , "string", "shortstring"
+            ] ++ builtin
     , reservedOpNames= [] 
     , caseSensitive  = False   
     }
     
+caseInsensitiveString s = do
+    mapM_ (\a -> satisfy (\b -> toUpper a == toUpper b)) s <?> s
+    return s
+    
 pas = patch $ makeTokenParser pascalLanguageDef
     where
     patch tp = tp {stringLiteral = sl}
@@ -162,17 +168,22 @@
 reference = buildExpressionParser table term <?> "reference"
     where
     term = comments >> choice [
-        parens pas reference 
-        , char '@' >> reference >>= return . Address
-        , iD >>= return . SimpleReference
+        parens pas (reference >>= postfixes) >>= postfixes
+        , char '@' >> reference >>= postfixes >>= return . Address
+        , liftM SimpleReference iD >>= postfixes 
         ] <?> "simple reference"
 
     table = [ 
-            [Postfix $ (parens pas) (option [] parameters) >>= return . FunCall]
-          , [Postfix (char '^' >> return Dereference)]
-          , [Postfix $ (brackets pas) (commaSep1 pas $ expression) >>= return . ArrayElement]
-          , [Infix (try (char '.' >> notFollowedBy (char '.')) >> return RecordField) AssocLeft]
+            [Infix (try (char '.' >> notFollowedBy (char '.')) >> return RecordField) AssocLeft]
         ]
+    
+    postfixes r = many postfix >>= return . foldl fp r
+    postfix = choice [
+            parens pas (option [] parameters) >>= return . FunCall
+          , char '^' >> return Dereference
+          , (brackets pas) (commaSep1 pas $ expression) >>= return . ArrayElement
+        ]
+    fp r f = f r
 
     
 varsDecl1 = varsParser sepEndBy1    
@@ -275,9 +286,9 @@
     ] <?> "range declaration"
     where
     rangeft = do
-    e1 <- expression
+    e1 <- initExpression
     string ".."
-    e2 <- expression
+    e2 <- initExpression
     return $ RangeFromTo e1 e2
     
 typeVarDeclaration isImpl = (liftM concat . many . choice) [
@@ -386,7 +397,8 @@
 expression = buildExpressionParser table term <?> "expression"
     where
     term = comments >> choice [
-        parens pas $ expression 
+        builtInFunction expression >>= \(n, e) -> return $ BuiltInFunCall e (SimpleReference (Identifier n))
+        , parens pas $ expression 
         , try $ integer pas >>= \i -> notFollowedBy (char '.') >> (return . NumberLiteral . show) i
         , try $ float pas >>= return . FloatLiteral . show
         , try $ integer pas >>= return . NumberLiteral . show
@@ -477,12 +489,12 @@
 withBlock = do
     try $ string "with"
     comments
-    r <- reference
+    rs <- (commaSep1 pas) reference
     comments
     string "do"
     comments
     o <- phrase
-    return $ WithBlock r o
+    return $ foldr WithBlock o rs
     
 repeatCycle = do
     try $ string "repeat"
@@ -565,10 +577,13 @@
 initExpression = buildExpressionParser table term <?> "initialization expression"
     where
     term = comments >> choice [
-        try $ parens pas (commaSep pas $ initExpression) >>= return . InitArray
+        liftM (uncurry BuiltInFunction) $ builtInFunction initExpression 
+        , try $ brackets pas (commaSep pas $ iD) >>= return . InitSet
+        , try $ parens pas (commaSep pas $ initExpression) >>= return . InitArray
         , parens pas (semiSep pas $ recField) >>= return . InitRecord
         , try $ integer pas >>= \i -> notFollowedBy (char '.') >> (return . InitNumber . show) i
         , try $ float pas >>= return . InitFloat . show
+        , try $ integer pas >>= return . InitNumber . show
         , stringLiteral pas >>= return . InitString
         , char '#' >> many digit >>= return . InitChar
         , char '$' >> many hexDigit >>= return . InitHexNumber
@@ -611,4 +626,10 @@
           ]
         , [Prefix (try (string "not") >> return (InitPrefixOp "not"))]
         ]
-    
\ No newline at end of file
+
+builtInFunction e = do
+    name <- choice $ map (\s -> try $ caseInsensitiveString s >>= \i -> notFollowedBy alphaNum >> return i) builtin
+    spaces
+    exprs <- parens pas $ commaSep1 pas $ e
+    spaces
+    return (name, exprs)
--- a/tools/pas2c.hs	Mon Nov 14 13:31:38 2011 -0500
+++ b/tools/pas2c.hs	Sat Nov 19 14:30:58 2011 -0500
@@ -15,8 +15,13 @@
          (Right a) -> (return . render . pascal2C) a
 
 pascal2C :: PascalUnit -> Doc
-pascal2C (Unit unitName interface implementation init fin) = implementation2C implementation
+pascal2C (Unit unitName interface implementation init fin) = 
+    interface2C interface
+    $+$ 
+    implementation2C implementation
 
+interface2C :: Interface -> Doc
+interface2C (Interface uses tvars) = typesAndVars2C tvars
 
 implementation2C :: Implementation -> Doc
 implementation2C (Implementation uses tvars) = typesAndVars2C tvars
@@ -48,7 +53,15 @@
     initExpr Nothing = empty
     initExpr (Just e) = text "=" <+> initExpr2C e
 
-initExpr2C :: InitExpression -> Doc    
+initExpr2C :: InitExpression -> Doc
+initExpr2C (InitBinOp op expr1 expr2) = parens $ (initExpr2C expr1) <+> op2C op <+> (initExpr2C expr2)
+initExpr2C (InitNumber s) = text s
+initExpr2C (InitFloat s) = text s
+initExpr2C (InitHexNumber s) = text "0x" <> (text . map toLower $ s)
+initExpr2C (InitString s) = doubleQuotes $ text s 
+initExpr2C (InitReference (Identifier i)) = text i
+
+
 initExpr2C _ = text "<<expression>>"
 
 type2C :: TypeDecl -> Doc