merge
authorunc0rr
Wed, 29 Jun 2011 22:24:38 +0400
changeset 5360 d47b8833284c
parent 5358 e2201f71beac (diff)
parent 5345 3c5480e91951 (current diff)
child 5362 5f0c46e78e50
merge
hedgewars/GSHandlers.inc
--- a/QTfrontend/gamecfgwidget.cpp	Wed Jun 29 17:32:05 2011 +0400
+++ b/QTfrontend/gamecfgwidget.cpp	Wed Jun 29 22:24:38 2011 +0400
@@ -229,6 +229,20 @@
     QList<QByteArray> bcfg;
     int mapgen = pMapContainer->get_mapgen();
 
+    QString currentMap = pMapContainer->getCurrentMap();
+    if (currentMap.size() > 0)
+    {
+        bcfg << QString("emap " + currentMap).toUtf8();
+        if(pMapContainer->getCurrentIsMission())
+            bcfg << QString("escript Maps/%1/map.lua").arg(currentMap).toUtf8();
+    }
+    bcfg << QString("etheme " + pMapContainer->getCurrentTheme()).toUtf8();
+
+    if (Scripts->currentIndex() > 0)
+    {
+        bcfg << QString("escript Scripts/Multiplayer/%1.lua").arg(Scripts->itemData(Scripts->currentIndex()).toList()[0].toString()).toUtf8();
+    }
+
     bcfg << QString("eseed " + pMapContainer->getCurrentSeed()).toUtf8();
     bcfg << QString("e$gmflags %1").arg(getGameFlags()).toUtf8();
     bcfg << QString("e$damagepct %1").arg(schemeData(25).toInt()).toUtf8();
@@ -270,20 +284,6 @@
         default: ;
     }
 
-    QString currentMap = pMapContainer->getCurrentMap();
-    if (currentMap.size() > 0)
-    {
-        bcfg << QString("emap " + currentMap).toUtf8();
-        if(pMapContainer->getCurrentIsMission())
-            bcfg << QString("escript Maps/%1/map.lua").arg(currentMap).toUtf8();
-    }
-    bcfg << QString("etheme " + pMapContainer->getCurrentTheme()).toUtf8();
-
-    if (Scripts->currentIndex() > 0)
-    {
-        bcfg << QString("escript Scripts/Multiplayer/%1.lua").arg(Scripts->itemData(Scripts->currentIndex()).toList()[0].toString()).toUtf8();
-    }
-
     QByteArray result;
 
     foreach(QByteArray ba, bcfg)
--- a/hedgewars/GSHandlers.inc	Wed Jun 29 17:32:05 2011 +0400
+++ b/hedgewars/GSHandlers.inc	Wed Jun 29 22:24:38 2011 +0400
@@ -605,7 +605,7 @@
     begin
     with Gear^ do
         begin
-        X:= X + cWindSpeed * 1600 + dX;
+        X:= X + cWindSpeed * 3200 + dX;
         Y:= Y + dY + cGravity * vobFallSpeed * 8;  // using same value as flakes to try and get similar results
         xx:= hwRound(X);
         yy:= hwRound(Y);
@@ -2565,7 +2565,6 @@
         HHGear := Gear^.Hedgehog^.Gear;
         Msg := Gear^.Message and not gmSwitch;
         DeleteGear(Gear);
-        OnUsedAmmo(HHGear^.Hedgehog^);
         ApplyAmmoChanges(HHGear^.Hedgehog^);
 
         HHGear := CurrentHedgehog^.Gear;
@@ -2614,6 +2613,7 @@
     Gear^.doStep := @doStepSwitcherWork;
 
     HHGear := Gear^.Hedgehog^.Gear;
+    OnUsedAmmo(HHGear^.Hedgehog^);
     with HHGear^ do
     begin
         State := State and not gstAttacking;
--- a/hedgewars/HHHandlers.inc	Wed Jun 29 17:32:05 2011 +0400
+++ b/hedgewars/HHHandlers.inc	Wed Jun 29 22:24:38 2011 +0400
@@ -533,7 +533,13 @@
 begin
 Gear^.Message:= gmDestroy;
 PlaySound(sndShotgunReload);
-if (Gear^.Pos and posCaseTrap) <> 0 then doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 30, HH^.Hedgehog, EXPLAutoSound)
+if (Gear^.Pos and posCaseExplode) <> 0 then
+    if (Gear^.Pos and posCasePoison) <> 0 then
+        doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 25, HH^.Hedgehog, EXPLAutoSound + EXPLPoisoned)
+    else
+        doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 25, HH^.Hedgehog, EXPLAutoSound)
+else if (Gear^.Pos and posCasePoison) <> 0 then
+    doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 25, HH^.Hedgehog, EXPLAutoSound + EXPLPoisoned + EXPLNoDamage)
 else
 case Gear^.Pos of
        posCaseUtility,
--- a/hedgewars/VGSHandlers.inc	Wed Jun 29 17:32:05 2011 +0400
+++ b/hedgewars/VGSHandlers.inc	Wed Jun 29 22:24:38 2011 +0400
@@ -46,7 +46,7 @@
         inc(Frame);
         if Frame = vobSDFramesCount then Frame:= 0
         end;
-    X:= X + (cWindSpeedf * 600 + dX + tdX) * Steps;
+    X:= X + (cWindSpeedf * 400 + dX + tdX) * Steps;
     if SuddenDeathDmg then
         Y:= Y + (dY + tdY + cGravityf * vobSDFallSpeed) * Steps
     else
--- a/hedgewars/uCommandHandlers.pas	Wed Jun 29 17:32:05 2011 +0400
+++ b/hedgewars/uCommandHandlers.pas	Wed Jun 29 22:24:38 2011 +0400
@@ -445,7 +445,7 @@
 
 procedure chSetMap(var s: shortstring);
 begin
-if isDeveloperMode then
+if isDeveloperMode and (s <> '') then
 begin
 UserPathz[ptMapCurrent]:= UserPathz[ptMaps] + '/' + s;
 Pathz[ptMapCurrent]:= Pathz[ptMaps] + '/' + s;
--- a/hedgewars/uCommands.pas	Wed Jun 29 17:32:05 2011 +0400
+++ b/hedgewars/uCommands.pas	Wed Jun 29 22:24:38 2011 +0400
@@ -33,7 +33,7 @@
 procedure StopMessages(Message: Longword);
 
 implementation
-uses Types, uConsts, uVariables, uConsole, uUtils, uDebug;
+uses Types, uConsts, uVariables, uConsole, uUtils, uDebug, uScript;
 
 type  PVariable = ^TVariable;
       TVariable = record
@@ -68,7 +68,7 @@
 
 procedure ParseCommand(CmdStr: shortstring; TrustedSource: boolean);
 var ii: LongInt;
-    s: shortstring;
+    s, i, o: shortstring;
     t: PVariable;
     c: char;
 begin
@@ -85,6 +85,8 @@
       if t^.Name = CmdStr then
          begin
          if TrustedSource or t^.Trusted then
+            begin
+            if (c <> '$') or (s[0] <> #0) then s:= ParseCommandOverride(CmdStr, s);
             case t^.VType of
               vtCommand: if c='/' then
                          begin
@@ -94,8 +96,12 @@
                          if s[0]=#0 then
                             begin
                             str(PLongInt(t^.Handler)^, s);
-                            WriteLnToConsole('$' + CmdStr + ' is "' + s + '"');
-                            end else val(s, PLongInt(t^.Handler)^);
+                            i:= inttostr(PLongInt(t^.Handler)^);
+                            o:= ParseCommandOverride(CmdStr, i);
+                            if i <> o then val(o, PLongInt(t^.Handler)^) 
+                            else WriteLnToConsole('$' + CmdStr + ' is "' + s + '"');
+                            end 
+                         else val(s, PLongInt(t^.Handler)^);
               vthwFloat: if c='$' then
                          if s[0]=#0 then
                             begin
@@ -106,13 +112,23 @@
                          if s[0]=#0 then
                             begin
                             str(ord(boolean(t^.Handler^)), s);
-                            WriteLnToConsole('$' + CmdStr + ' is "' + s + '"');
-                            end else
+                            if boolean(t^.Handler^) then i:= '1'
+                            else i:= '0';
+                            o:= ParseCommandOverride(CmdStr, i);
+                            if i <> o then 
+                                begin
+                                val(o, ii);
+                                boolean(t^.Handler^):= not (ii = 0)
+                                end
+                            else WriteLnToConsole('$' + CmdStr + ' is "' + s + '"');
+                            end 
+                         else
                             begin
                             val(s, ii);
                             boolean(t^.Handler^):= not (ii = 0)
                             end;
               end;
+              end;
          exit
          end else t:= t^.Next
       end;
--- a/hedgewars/uConsts.pas	Wed Jun 29 17:32:05 2011 +0400
+++ b/hedgewars/uConsts.pas	Wed Jun 29 22:24:38 2011 +0400
@@ -260,7 +260,8 @@
     posCaseHealth  = $00000002;
     posCaseUtility = $00000004;
     posCaseDummy   = $00000008;
-    posCaseTrap    = $00000010;
+    posCaseExplode = $00000010;
+    posCasePoison  = $00000020;
 
     NoPointX = Low(LongInt);
     cTargetPointRef : TPoint = (X: NoPointX; Y: 0);
--- a/hedgewars/uGears.pas	Wed Jun 29 17:32:05 2011 +0400
+++ b/hedgewars/uGears.pas	Wed Jun 29 22:24:38 2011 +0400
@@ -39,7 +39,7 @@
 procedure freeModule;
 function  AddGear(X, Y: LongInt; Kind: TGearType; State: Longword; dX, dY: hwFloat; Timer: LongWord): PGear;
 function  SpawnCustomCrateAt(x, y: LongInt; crate: TCrateType; content: Longword ): PGear;
-function  SpawnFakeCrateAt(x, y: LongInt; crate: TCrateType; trap: boolean ): PGear;
+function  SpawnFakeCrateAt(x, y: LongInt; crate: TCrateType; explode: boolean; poison: boolean ): PGear;
 procedure ResurrectHedgehog(gear: PGear);
 procedure ProcessGears;
 procedure EndTurnCleanup;
@@ -1685,13 +1685,14 @@
     SpawnCustomCrateAt := FollowGear;
 end;
 
-function SpawnFakeCrateAt(x, y: LongInt; crate: TCrateType; trap: boolean): PGear;
+function SpawnFakeCrateAt(x, y: LongInt; crate: TCrateType; explode: boolean; poison: boolean): PGear;
 begin
     FollowGear := AddGear(x, y, gtCase, 0, _0, _0, 0);
     cCaseFactor := 0;
+    FollowGear^.Pos := posCaseDummy;
     
-    if trap then FollowGear^.Pos := posCaseTrap
-    else FollowGear^.Pos := posCaseDummy;
+    if explode then FollowGear^.Pos := FollowGear^.Pos + posCaseExplode;
+    if poison then FollowGear^.Pos := FollowGear^.Pos + posCasePoison;
 
     case crate of
         HealthCrate: begin
--- a/hedgewars/uLandGraphics.pas	Wed Jun 29 17:32:05 2011 +0400
+++ b/hedgewars/uLandGraphics.pas	Wed Jun 29 22:24:38 2011 +0400
@@ -715,7 +715,9 @@
    yy:= Y div 2;
    end;
 pixelsweep:= ((Land[Y, X] and $FF00) = 0) and (LandPixels[yy, xx] <> 0);
-if (((Land[Y, X] and lfDamaged) <> 0) and ((Land[Y, X] and lfIndestructible) = 0)) or pixelsweep then
+if ((((Land[Y, X] and lfDamaged) <> 0) or 
+    (((Land[Y, X] and lfBasic) <> 0) and (LandPixels[yy,xx] <> 0) and ((LandPixels[yy,xx] and AMask) shl AShift < 255)))
+    and ((Land[Y, X] and lfIndestructible) = 0)) or pixelsweep then
     begin
     c:= 0;
     for i:= -1 to 1 do
--- a/hedgewars/uScript.pas	Wed Jun 29 17:32:05 2011 +0400
+++ b/hedgewars/uScript.pas	Wed Jun 29 22:24:38 2011 +0400
@@ -43,6 +43,7 @@
 function ScriptCall(fname : shortstring; par1, par2, par3: LongInt) : LongInt;
 function ScriptCall(fname : shortstring; par1, par2, par3, par4 : LongInt) : LongInt;
 function ScriptExists(fname : shortstring) : boolean;
+function ParseCommandOverride(key, value : shortstring) : shortstring;
 
 procedure initModule;
 procedure freeModule;
@@ -226,13 +227,13 @@
 function lc_spawnfakehealthcrate(L: Plua_State) : LongInt; Cdecl;
 var gear: PGear;
 begin
-    if lua_gettop(L) <> 3 then begin
+    if lua_gettop(L) <> 4 then begin
         LuaError('Lua: Wrong number of parameters passed to SpawnFakeHealthCrate!');
         lua_pushnil(L);
     end
     else begin
         gear := SpawnFakeCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2),
-            HealthCrate, lua_toboolean(L, 3));
+            HealthCrate, lua_toboolean(L, 3), lua_toboolean(L, 4));
         lua_pushinteger(L, gear^.uid);
     end;
     lc_spawnfakehealthcrate := 1;        
@@ -241,13 +242,13 @@
 function lc_spawnfakeammocrate(L: PLua_State): LongInt; Cdecl;
 var gear: PGear;
 begin
-    if lua_gettop(L) <> 3 then begin
+    if lua_gettop(L) <> 4 then begin
         LuaError('Lua: Wrong number of parameters passed to SpawnFakeAmmoCrate!');
         lua_pushnil(L);
     end
     else begin
         gear := SpawnFakeCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2),
-            AmmoCrate, lua_toboolean(L, 3));
+            AmmoCrate, lua_toboolean(L, 3), lua_toboolean(L, 4));
         lua_pushinteger(L, gear^.uid);
     end;
     lc_spawnfakeammocrate := 1;
@@ -256,13 +257,13 @@
 function lc_spawnfakeutilitycrate(L: PLua_State): LongInt; Cdecl;
 var gear: PGear;
 begin
-    if lua_gettop(L) <> 3 then begin
+    if lua_gettop(L) <> 4 then begin
         LuaError('Lua: Wrong number of parameters passed to SpawnFakeUtilityCrate!');
         lua_pushnil(L);
     end
     else begin  
         gear := SpawnFakeCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2),
-            UtilityCrate, lua_toboolean(L, 3));
+            UtilityCrate, lua_toboolean(L, 3), lua_toboolean(L, 4));
         lua_pushinteger(L, gear^.uid);
     end;
     lc_spawnfakeutilitycrate := 1;
@@ -1588,6 +1589,25 @@
 GetGlobals;
 end;
 
+function ParseCommandOverride(key, value : shortstring) : shortstring;
+begin
+ParseCommandOverride:= value;
+if not ScriptExists('ParseCommandOverride') then exit;
+lua_getglobal(luaState, Str2PChar('ParseCommandOverride'));
+lua_pushstring(luaState, Str2PChar(key));
+lua_pushstring(luaState, Str2PChar(value));
+if lua_pcall(luaState, 2, 1, 0) <> 0 then
+    begin
+    LuaError('Lua: Error while calling ParseCommandOverride: ' + lua_tostring(luaState, -1));
+    lua_pop(luaState, 1)
+    end
+else
+    begin
+    ParseCommandOverride:= lua_tostring(luaState, -1);
+    lua_pop(luaState, 1)
+    end;
+end;
+
 function ScriptCall(fname : shortstring; par1: LongInt) : LongInt;
 begin
 ScriptCall:= ScriptCall(fname, par1, 0, 0, 0)
@@ -1669,14 +1689,23 @@
 end;
 
 procedure ScriptApplyAmmoStore;
-var i : LongInt;
+var i, j : LongInt;
 begin
 SetAmmoLoadout(ScriptAmmoLoadout);
 SetAmmoProbability(ScriptAmmoProbability);
 SetAmmoDelay(ScriptAmmoDelay);
 SetAmmoReinforcement(ScriptAmmoReinforcement);
-for i:= 0 to Pred(TeamsCount) do
-    AddAmmoStore;
+
+if (GameFlags and gfSharedAmmo) <> 0 then
+    for i:= 0 to Pred(ClansCount) do
+        AddAmmoStore
+else if (GameFlags and gfPerHogAmmo) <> 0 then
+    for i:= 0 to Pred(TeamsCount) do
+        for j:= 0 to Pred(TeamsArray[i]^.HedgehogsNumber) do
+            AddAmmoStore
+else 
+    for i:= 0 to Pred(TeamsCount) do
+        AddAmmoStore
 end;
 
 procedure initModule;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/misc/theme_editor.html	Wed Jun 29 22:24:38 2011 +0400
@@ -0,0 +1,159 @@
+<!doctype html>
+<html>
+    <head>
+        <title>Hedgewars Theme Editor</title>
+        <script type="text/javascript">
+            var sky, clouds, horizont, water, land, border;
+            var skyColor, waterTopColor, waterBottomColor;
+            var elements = 7;
+            var landArray;
+            
+            function landFunction(x){
+                return 384 - 192 * Math.sin(x * Math.PI/512);
+            }
+            
+            function tryToDraw(){
+                if (--elements <= 0) {
+                    draw();
+                }
+            }
+        
+            function load(){
+                    var canvas = document.getElementById('preview');
+                    if (canvas.getContext){
+                        var ctx = canvas.getContext('2d');
+                    
+                        ctx.fillStyle = '#0b294b';
+                        ctx.fillRect(0, 0, 512, 384);
+                        
+                        ctx.font = "40pt Arial";
+                        ctx.fillStyle = '#2b7bd5';
+                        ctx.fillText('Loading Images...', 32, 212);
+                    }
+                    
+                    sky = new Image();
+                    sky.onload = tryToDraw;
+                    sky.src = 'http://hedgewars.googlecode.com/hg/share/hedgewars/Data/Themes/Nature/Sky.png';
+          
+                    clouds = new Image();
+                    clouds.onload = tryToDraw;
+                    clouds.src = 'http://hedgewars.googlecode.com/hg/share/hedgewars/Data/Graphics/Clouds.png';
+          
+                    horizont = new Image();
+                    horizont.onload = tryToDraw;
+                    horizont.src = 'http://hedgewars.googlecode.com/hg/share/hedgewars/Data/Themes/Nature/horizont.png';
+          
+                    land = new Image();
+                    land.onload = tryToDraw;
+                    land.src = 'http://hedgewars.googlecode.com/hg/share/hedgewars/Data/Themes/Nature/LandTex.png';
+          
+                    border = new Image();
+                    border.onload = tryToDraw;
+                    border.src = 'http://hedgewars.googlecode.com/hg/share/hedgewars/Data/Themes/Nature/Border.png';
+          
+                    water = new Image();
+                    water.onload = tryToDraw;
+                    water.src = 'http://hedgewars.googlecode.com/hg/share/hedgewars/Data/Graphics/BlueWater.png';
+                    
+                    landArray = new Array(512);
+                    for (var x = 0; x < landArray.length; x++)
+                        landArray[x] = landFunction(x);
+                    
+                    skyColor = '#131252';
+                    document.getElementById('skyColor').value = skyColor;
+                    
+                    waterTopColor = '#555C9D';
+                    document.getElementById('waterTopColor').value = waterTopColor;
+                    
+                    waterBottomColor = '#343C7D';
+                    document.getElementById('waterBottomColor').value = waterBottomColor;
+                    
+                    tryToDraw();
+            }
+            
+            function draw(){
+                var canvas = document.getElementById('preview');
+                if (canvas.getContext){
+                    var ctx = canvas.getContext('2d');
+                    
+                    ctx.fillStyle = skyColor;
+                    ctx.fillRect(0, 0, 512, 384);
+                    
+                    ctx.drawImage(sky, 0, 64, 512, 256);
+          
+                    for (var i = 0; i < 4; i++)
+                        ctx.drawImage(clouds, 0, i * 128, 256, 128, i * 128, 64, 128, 64);
+          
+                    ctx.drawImage(horizont, 0, 192, 512, 128);
+                    
+                    ctx.save();
+                    
+                    ctx.beginPath();
+                    ctx.moveTo(0, 384);
+                    for (var x = 0; x < landArray.length; x++)
+                        ctx.lineTo(x, landArray[x]);
+                    ctx.clip();
+                    
+                    for (var i = 0; i < 2; i++)
+                    	for (var k = 0; k < 2; k++)
+                    		ctx.drawImage(land, i * 320, k * 240, 320, 240);
+                    
+                    ctx.restore();
+                    
+                    var k = 0;
+                    for (var x = 0; x < landArray.length; x++) {
+                        if (++k == 64)
+                            k = 0;
+                        ctx.drawImage(border, k, 0, 2, 16, x, landArray[x] - 4, 1, 8);
+                    }
+                        
+                    
+                    var gradient = ctx.createLinearGradient(0, 320, 0, 384);
+                    gradient.addColorStop(0, waterTopColor);
+                    gradient.addColorStop(1, waterBottomColor);
+                    ctx.fillStyle = gradient;
+                    ctx.fillRect(0, 320, 512, 384);
+          
+                    for (var i = 0; i < 8; i++)
+                        ctx.drawImage(water, i * 64, 308, 64, 24);
+                }
+            }
+        </script>
+        <style type="text/css">
+            canvas { border: 1px solid black; }
+        </style>
+    </head>
+    <body onload="load();">
+        <h1>Hedgewars Theme editor</h1>
+        <canvas id="preview" width="512" height="384"></canvas><br>
+        <table>
+        <tr><td>Sky:</td><td>
+        <input id="sky" type="file" accept="image/png" onchange="sky.src = window.URL.createObjectURL(this.files[0])"></input>
+        </td></tr>
+        <tr><td>Sky Color:</td><td>
+        <input id="skyColor" type="color" onchange="skyColor = this.value; draw()"></input>
+        </td></tr>
+        <tr><td>Clouds:</td><td>
+        <input id="clouds" type="file" accept="image/png" onchange="clouds.src = window.URL.createObjectURL(this.files[0])"></input>
+        </td></tr>
+        <tr><td>Horizont:</td><td>
+        <input id="horizont" type="file" accept="image/png" onchange="horizont.src = window.URL.createObjectURL(this.files[0])"></input>
+        </td></tr>
+        <tr><td>Land:</td><td>
+        <input id="land" type="file" accept="image/png" onchange="land.src = window.URL.createObjectURL(this.files[0])"></input>
+        </td></tr>
+        <tr><td>Border:</td><td>
+        <input id="border" type="file" accept="image/png" onchange="border.src = window.URL.createObjectURL(this.files[0])"></input>
+        </td></tr>
+        <tr><td>Water:</td><td>
+        <input id="water" type="file" accept="image/png" onchange="water.src = window.URL.createObjectURL(this.files[0])"></input>
+        </td></tr>
+        <tr><td>Water Top Color:</td><td>
+        <input id="waterTopColor" type="color" onchange="waterTopColor = this.value; draw()"></input>
+        </td></tr>
+        <tr><td>Water Bottom Color:</td><td>
+        <input id="waterBottomColor" type="color" onchange="waterBottomColor = this.value; draw()"></input>
+        </td></tr>
+        </table>
+    </body>
+</html>
--- a/share/hedgewars/Data/Scripts/Multiplayer/Random_Weapon.lua	Wed Jun 29 17:32:05 2011 +0400
+++ b/share/hedgewars/Data/Scripts/Multiplayer/Random_Weapon.lua	Wed Jun 29 22:24:38 2011 +0400
@@ -46,7 +46,7 @@
 
 function onGameInit()
     -- Limit flags that can be set, but allow game schemes to be used
-    GameFlags = band(bor(GameFlags, gfResetWeps), bnot(gfInfAttack + gfPerHogAmmo))
+    GameFlags = band(bor(GameFlags, gfResetWeps), bnot(gfInfAttack))
     -- Set a custom game goal that will show together with the scheme ones
     Goals = loc("Each turn you get one random weapon")
 end