share/hedgewars/Data/Scripts/Multiplayer/Continental_supplies.lua
changeset 14811 d65e25e211d4
parent 14324 5da99c43b96f
child 15136 309aa93df110
equal deleted inserted replaced
14810:583d8b96fb30 14811:d65e25e211d4
    12 -- fix selection increase delay (weapons to compesate)
    12 -- fix selection increase delay (weapons to compesate)
    13 
    13 
    14 HedgewarsScriptLoad("/Scripts/Locale.lua")
    14 HedgewarsScriptLoad("/Scripts/Locale.lua")
    15 HedgewarsScriptLoad("/Scripts/Utils.lua")
    15 HedgewarsScriptLoad("/Scripts/Utils.lua")
    16 HedgewarsScriptLoad("/Scripts/Tracker.lua")
    16 HedgewarsScriptLoad("/Scripts/Tracker.lua")
    17 
       
    18 --approximative version of square root. This function follows the babylonian method.
       
    19 function IntegerSqrt(num)
       
    20 	local temp=num
       
    21 	while(temp*temp-div(temp,2)>num)
       
    22 	do
       
    23 		temp=div((temp+div(num,temp)),2)
       
    24 	end
       
    25 
       
    26 	return math.abs(temp)
       
    27 end
       
    28 
       
    29 -- sqrt(x^2,y^2), work without desyncs. is approximative
       
    30 function Norm(xx,yy)
       
    31 	--to fix overflows
       
    32 	if(((math.abs(xx)^2)+(math.abs(yy)^2))>2^26)
       
    33 	then
       
    34 		local bitr=2^13
       
    35 		return IntegerSqrt((div(math.abs(xx),bitr)^2)+(div(math.abs(yy),bitr)^2))*bitr
       
    36 	else
       
    37 		return IntegerSqrt((math.abs(xx)^2)+(math.abs(yy)^2))
       
    38 	end
       
    39 end
       
    40 
    17 
    41 -- returns 1 or -1 depending on where it is
    18 -- returns 1 or -1 depending on where it is
    42 function GetIfNegative(num)
    19 function GetIfNegative(num)
    43 	if(num<0)
    20 	if(num<0)
    44 	then
    21 	then
    65 function ShowDamageTag(hog,damage)
    42 function ShowDamageTag(hog,damage)
    66 	local healthtag=AddVisualGear(GetX(hog), GetY(hog), vgtHealthTag, damage, false)
    43 	local healthtag=AddVisualGear(GetX(hog), GetY(hog), vgtHealthTag, damage, false)
    67 	SetVisualGearValues(healthtag, nil, nil, nil, nil, nil, nil, nil, nil, nil, GetClanColor(GetHogClan(hog)))
    44 	SetVisualGearValues(healthtag, nil, nil, nil, nil, nil, nil, nil, nil, nil, GetClanColor(GetHogClan(hog)))
    68 end
    45 end
    69 
    46 
    70 --will use IntegerSqrt
       
    71 function FireGear(hedgehog,geartype,vx,vy,timer)
    47 function FireGear(hedgehog,geartype,vx,vy,timer)
    72 	local hypo=Norm(vx,vy)
    48 	local hypo=integerHypotenuse(vx,vy)
    73 	return AddGear(div((GetGearRadius(hedgehog)*2*vx),hypo)+GetX(hedgehog), div((GetGearRadius(hedgehog)*2*vy),hypo)+GetY(hedgehog), geartype, 0, vx, vy, timer)
    49 	return AddGear(div((GetGearRadius(hedgehog)*2*vx),hypo)+GetX(hedgehog), div((GetGearRadius(hedgehog)*2*vy),hypo)+GetY(hedgehog), geartype, 0, vx, vy, timer)
    74 end
    50 end
    75 
    51 
    76 function CollectMultiAmmo(hog, ammoList, noAddAmmo)
    52 function CollectMultiAmmo(hog, ammoList, noAddAmmo)
    77 	local x, y = GetGearPosition(hog)
    53 	local x, y = GetGearPosition(hog)
   859 			if(hog == CurrentHedgehog)
   835 			if(hog == CurrentHedgehog)
   860 			then
   836 			then
   861 				SetState(CurrentHedgehog, gstMoving)
   837 				SetState(CurrentHedgehog, gstMoving)
   862 			end
   838 			end
   863 			SetGearPosition(hog, GetX(hog),GetY(hog)-3)
   839 			SetGearPosition(hog, GetX(hog),GetY(hog)-3)
   864 			hypo=Norm(math.abs(GetX(hog)-GetX(CS.TEMP_VALUE)),math.abs(GetY(hog)-GetY(CS.TEMP_VALUE)))
   840 			hypo=integerHypotenuse(math.abs(GetX(hog)-GetX(CS.TEMP_VALUE)),math.abs(GetY(hog)-GetY(CS.TEMP_VALUE)))
   865 			SetGearVelocity(hog, div((power_radius_outer-hypo)*power_sa*GetIfNegative(GetX(hog)-GetX(CS.TEMP_VALUE)),power_radius_outer), div((power_radius_outer-hypo)*power_sa*GetIfNegative(GetY(hog)-GetY(CS.TEMP_VALUE)),power_radius_outer))
   841 			SetGearVelocity(hog, div((power_radius_outer-hypo)*power_sa*GetIfNegative(GetX(hog)-GetX(CS.TEMP_VALUE)),power_radius_outer), div((power_radius_outer-hypo)*power_sa*GetIfNegative(GetY(hog)-GetY(CS.TEMP_VALUE)),power_radius_outer))
   866 		end
   842 		end
   867 	end
   843 	end
   868 end
   844 end
   869 
   845