# HG changeset patch # User Henek # Date 1309049256 -7200 # Node ID 5e18eaef65d0a578d3adbde9281b1cffd1016d5a # Parent 4622f83623ac41ef453f0febf400034d2b8021ad now scripts can create unique crates: dummy (empty) crates and booby traps. scripts can also set health crate values diff -r 4622f83623ac -r 5e18eaef65d0 hedgewars/GSHandlers.inc --- a/hedgewars/GSHandlers.inc Sat Jun 25 17:22:35 2011 +0400 +++ b/hedgewars/GSHandlers.inc Sun Jun 26 02:47:36 2011 +0200 @@ -102,6 +102,7 @@ gi := gi^.NextGear end; end; + //////////////////////////////////////////////////////////////////////////////// procedure doStepDrowningGear(Gear: PGear); forward; @@ -236,7 +237,6 @@ end; //////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////// procedure CalcRotationDirAngle(Gear: PGear); var dAngle: real; @@ -477,6 +477,7 @@ AddVisualGear(hwRound(Gear^.X), hwRound(Gear^.Y), vgtEvilTrace); end; end; + //////////////////////////////////////////////////////////////////////////////// procedure doStepMolotov(Gear: PGear); var @@ -513,11 +514,7 @@ end; end; -procedure doStepWatermelon(Gear: PGear); -begin - AllInactive := false; - Gear^.doStep := @doStepBomb -end; +//////////////////////////////////////////////////////////////////////////////// procedure doStepCluster(Gear: PGear); begin @@ -582,6 +579,7 @@ end end; +//////////////////////////////////////////////////////////////////////////////// procedure doStepSnowflake(Gear: PGear); var xx, yy, px, py: LongInt; move, draw, allpx, gun: Boolean; @@ -2074,6 +2072,7 @@ end end; +//////////////////////////////////////////////////////////////////////////////// procedure doStepShover(Gear: PGear); var HHGear: PGear; @@ -3308,6 +3307,7 @@ Gear^.doStep := @doStepRCPlaneWork end; +//////////////////////////////////////////////////////////////////////////////// procedure doStepJetpackWork(Gear: PGear); var HHGear: PGear; @@ -3435,7 +3435,6 @@ end end; -//////////////////////////////////////////////////////////////////////////////// procedure doStepJetpack(Gear: PGear); var HHGear: PGear; @@ -3471,7 +3470,6 @@ end; end; -//////////////////////////////////////////////////////////////////////////////// procedure doStepBirdyFly(Gear: PGear); var HHGear: PGear; @@ -3565,7 +3563,6 @@ end end; -//////////////////////////////////////////////////////////////////////////////// procedure doStepBirdyDescend(Gear: PGear); var HHGear: PGear; @@ -3607,7 +3604,6 @@ end end; -//////////////////////////////////////////////////////////////////////////////// procedure doStepBirdy(Gear: PGear); var HHGear: PGear; @@ -4145,6 +4141,7 @@ newPortal^.doStep := @doStepMovingPortal; end; +//////////////////////////////////////////////////////////////////////////////// procedure doStepPiano(Gear: PGear); var r0, r1: LongInt; @@ -4444,6 +4441,7 @@ Gear^.doStep := @doStepFlamethrowerWork end; +//////////////////////////////////////////////////////////////////////////////// procedure doStepLandGunWork(Gear: PGear); var HHGear: PGear; @@ -4519,6 +4517,7 @@ Gear^.doStep := @doStepLandGunWork end; +//////////////////////////////////////////////////////////////////////////////// procedure doStepPoisonCloud(Gear: PGear); begin if Gear^.Timer = 0 then @@ -4576,7 +4575,6 @@ Gear^.doStep:= @doStepIdle end; -//////////////////////////////////////////////////////////////////////////////// procedure doStepHammerHitWork(Gear: PGear); var i, ei: LongInt; @@ -4812,6 +4810,14 @@ var x, y: LongInt; begin + if (Gear^.State and gstMoving) <> 0 then + begin + AddGearCI(Gear); + Gear^.dX:= _0; + Gear^.dY:= _0; + Gear^.State:= Gear^.State and not gstMoving; + end; + if CurAmmoGear = Gear then begin if (CurrentHedgehog = nil) or (CurrentHedgehog^.Gear = nil) then @@ -4860,6 +4866,7 @@ end; end; +//////////////////////////////////////////////////////////////////////////////// procedure doStepTardis(Gear: PGear); (*var i, x, y: LongInt; @@ -4902,3 +4909,6 @@ DeleteGear(Gear) end end; + +//////////////////////////////////////////////////////////////////////////////// + diff -r 4622f83623ac -r 5e18eaef65d0 hedgewars/HHHandlers.inc --- a/hedgewars/HHHandlers.inc Sat Jun 25 17:22:35 2011 +0400 +++ b/hedgewars/HHHandlers.inc Sun Jun 26 02:47:36 2011 +0200 @@ -467,6 +467,8 @@ begin Gear^.Message:= gmDestroy; PlaySound(sndShotgunReload); +if (Gear^.Pos and posCaseTrap) <> 0 then doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 30, HH^.Hedgehog, EXPLAutoSound) +else case Gear^.Pos of posCaseUtility, posCaseAmmo: begin diff -r 4622f83623ac -r 5e18eaef65d0 hedgewars/uConsts.pas --- a/hedgewars/uConsts.pas Sat Jun 25 17:22:35 2011 +0400 +++ b/hedgewars/uConsts.pas Sun Jun 26 02:47:36 2011 +0200 @@ -258,6 +258,8 @@ posCaseAmmo = $00000001; posCaseHealth = $00000002; posCaseUtility = $00000004; + posCaseDummy = $00000008; + posCaseTrap = $00000010; NoPointX = Low(LongInt); cTargetPointRef : TPoint = (X: NoPointX; Y: 0); diff -r 4622f83623ac -r 5e18eaef65d0 hedgewars/uGears.pas --- a/hedgewars/uGears.pas Sat Jun 25 17:22:35 2011 +0400 +++ b/hedgewars/uGears.pas Sun Jun 26 02:47:36 2011 +0200 @@ -39,6 +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; procedure ResurrectHedgehog(gear: PGear); procedure ProcessGears; procedure EndTurnCleanup; @@ -120,7 +121,7 @@ @doStepKamikaze, @doStepCake, @doStepSeduction, - @doStepWatermelon, + @doStepBomb, @doStepCluster, @doStepBomb, @doStepWaterUp, @@ -540,11 +541,11 @@ gear^.Density:= _1_5; end; gtStructure: begin - gear^.ImpactSound:= sndGrenadeImpact; - gear^.nImpactSounds:= 1; + gear^.Elasticity:= _0_55; + gear^.Friction:= _0_995; + gear^.Density:= _0_9; gear^.Radius:= 13; - gear^.Elasticity:= _0_3; - gear^.Health:= 50; + gear^.Health:= 200; gear^.Tag:= 3; end; end; @@ -1607,12 +1608,12 @@ FollowGear := AddGear(x, y, gtCase, 0, _0, _0, 0); cCaseFactor := 0; - if (content > ord(High(TAmmoType))) then content := ord(High(TAmmoType)); + if (crate <> HealthCrate) and (content > ord(High(TAmmoType))) then content := ord(High(TAmmoType)); case crate of HealthCrate: begin - FollowGear^.Health := cHealthCaseAmount; FollowGear^.Pos := posCaseHealth; + FollowGear^.Health := content; AddCaption(GetEventString(eidNewHealthPack), cWhiteColor, capgrpAmmoInfo); end; AmmoCrate: begin @@ -1632,6 +1633,34 @@ SpawnCustomCrateAt := FollowGear; end; +function SpawnFakeCrateAt(x, y: LongInt; crate: TCrateType; trap: boolean): PGear; +begin + FollowGear := AddGear(x, y, gtCase, 0, _0, _0, 0); + cCaseFactor := 0; + + if trap then FollowGear^.Pos := posCaseTrap + else FollowGear^.Pos := posCaseDummy; + + case crate of + HealthCrate: begin + FollowGear^.Pos := FollowGear^.Pos + posCaseHealth; + AddCaption(GetEventString(eidNewHealthPack), cWhiteColor, capgrpAmmoInfo); + end; + AmmoCrate: begin + FollowGear^.Pos := FollowGear^.Pos + posCaseAmmo; + AddCaption(GetEventString(eidNewAmmoPack), cWhiteColor, capgrpAmmoInfo); + end; + UtilityCrate: begin + FollowGear^.Pos := FollowGear^.Pos + posCaseUtility; + AddCaption(GetEventString(eidNewUtilityPack), cWhiteColor, capgrpAmmoInfo); + end; + end; + + if ( (x = 0) and (y = 0) ) then FindPlace(FollowGear, true, 0, LAND_WIDTH); + + SpawnFakeCrateAt := FollowGear; +end; + procedure SpawnBoxOfSmth; var t, aTot, uTot, a, h: LongInt; i: TAmmoType; diff -r 4622f83623ac -r 5e18eaef65d0 hedgewars/uGearsRender.pas --- a/hedgewars/uGearsRender.pas Sat Jun 25 17:22:35 2011 +0400 +++ b/hedgewars/uGearsRender.pas Sun Jun 26 02:47:36 2011 +0200 @@ -928,24 +928,25 @@ DrawRotated(sprSMineOff, x, y, 0, Gear^.DirAngle) else if Gear^.Health <> 0 then DrawRotated(sprSMineOn, x, y, 0, Gear^.DirAngle) else DrawRotated(sprMineDead, x, y, 0, Gear^.DirAngle); - gtCase: case Gear^.Pos of - posCaseAmmo : begin - i:= (GameTicks shr 6) mod 64; - if i > 18 then i:= 0; - DrawSprite(sprCase, x - 24, y - 24, i); - end; - posCaseHealth: begin - i:= ((GameTicks shr 6) + 38) mod 64; - if i > 13 then i:= 0; - DrawSprite(sprFAid, x - 24, y - 24, i); - end; - posCaseUtility: begin - i:= (GameTicks shr 6) mod 70; - if i > 23 then i:= 0; - i:= i mod 12; - DrawSprite(sprUtility, x - 24, y - 24, i); - end; - end; + gtCase: if ((Gear^.Pos and posCaseAmmo) <> 0) then + begin + i:= (GameTicks shr 6) mod 64; + if i > 18 then i:= 0; + DrawSprite(sprCase, x - 24, y - 24, i); + end + else if ((Gear^.Pos and posCaseHealth) <> 0) then + begin + i:= ((GameTicks shr 6) + 38) mod 64; + if i > 13 then i:= 0; + DrawSprite(sprFAid, x - 24, y - 24, i); + end + else if ((Gear^.Pos and posCaseUtility) <> 0) then + begin + i:= (GameTicks shr 6) mod 70; + if i > 23 then i:= 0; + i:= i mod 12; + DrawSprite(sprUtility, x - 24, y - 24, i); + end; gtExplosives: begin if ((Gear^.State and gstDrowning) <> 0) then DrawSprite(sprExplosivesRoll, x - 24, y - 24, 0) diff -r 4622f83623ac -r 5e18eaef65d0 hedgewars/uScript.pas --- a/hedgewars/uScript.pas Sat Jun 25 17:22:35 2011 +0400 +++ b/hedgewars/uScript.pas Sun Jun 26 02:47:36 2011 +0200 @@ -223,16 +223,64 @@ lc_campaignunlock:= 0; end; +function lc_spawnfakehealthcrate(L: Plua_State) : LongInt; Cdecl; +var gear: PGear; +begin + if lua_gettop(L) <> 3 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)); + lua_pushinteger(L, gear^.uid); + end; + lc_spawnfakehealthcrate := 1; +end; + +function lc_spawnfakeammocrate(L: PLua_State): LongInt; Cdecl; +var gear: PGear; +begin + if lua_gettop(L) <> 3 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)); + lua_pushinteger(L, gear^.uid); + end; + lc_spawnfakeammocrate := 1; +end; + +function lc_spawnfakeutilitycrate(L: PLua_State): LongInt; Cdecl; +var gear: PGear; +begin + if lua_gettop(L) <> 3 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)); + lua_pushinteger(L, gear^.uid); + end; + lc_spawnfakeutilitycrate := 1; +end; + function lc_spawnhealthcrate(L: Plua_State) : LongInt; Cdecl; var gear: PGear; +var health: LongInt; begin - if lua_gettop(L) <> 2 then begin + if (lua_gettop(L) < 2) or (lua_gettop(L) > 3) then begin LuaError('Lua: Wrong number of parameters passed to SpawnHealthCrate!'); lua_pushnil(L); end else begin + if lua_gettop(L) = 3 then health:= lua_tointeger(L, 3) + else health:= cHealthCaseAmount; gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), - HealthCrate, 0); + HealthCrate, health); lua_pushinteger(L, gear^.uid); end; lc_spawnhealthcrate := 1; @@ -1740,6 +1788,9 @@ lua_register(luaState, 'SpawnHealthCrate', @lc_spawnhealthcrate); lua_register(luaState, 'SpawnAmmoCrate', @lc_spawnammocrate); lua_register(luaState, 'SpawnUtilityCrate', @lc_spawnutilitycrate); +lua_register(luaState, 'SpawnFakeHealthCrate', @lc_spawnfakehealthcrate); +lua_register(luaState, 'SpawnFakeAmmoCrate', @lc_spawnfakeammocrate); +lua_register(luaState, 'SpawnFakeUtilityCrate', @lc_spawnfakeutilitycrate); lua_register(luaState, 'WriteLnToConsole', @lc_writelntoconsole); lua_register(luaState, 'GetGearType', @lc_getgeartype); lua_register(luaState, 'EndGame', @lc_endgame);