Page 1 of 1

How does one add LUPS effects

Posted: 13 Feb 2015, 10:00
by PicassoCT
without adding a new unit. Just standalone. Similar to Spring.SpawnCEG ?

This is for a savannah fire Gadget currently wip..

CEGs can look good, but are too expensive, cause CPU bound..

Code: Select all

function gadget:GetInfo()

function isPlanetFlammeable()
	if Game.mapHardness > 0 and Game.windMin > 0 and Game.gravity > 80 and Game.waterDamage == 0 then
	badwordsTable={"cold","ice","frost","dessert","sand","dune"} 
		for i=1,#badwordsTable do ; 
			if string.find(Game.mapName, badwordsTable[i]) then 
			return false; 
			end  
		end 
	return true  
	end

  return {
    name      = "Weltenbrand",
    desc      = "Dieses Gadget simuliert ein SteppenFeuer. Wer das liest und dafür Deusch lernt ist doof.",
    author    = "You",
    date      = "Sep. 2015",
    license   = "GNU GPL, v2 or later",
    layer     = 0,
    enabled   = isPlanetFlammeable()
  }

end



if (gadgetHandler:IsSyncedCode()) then
	VFS.Include("scripts/toolKit.lua")

	--Food
	--AccumulatedHeat

	windVector={x=5,z=10}
	InHeat=25
	costPerFrame=10
	     --x --z
	local fireTable={}
	fireTable[1]={x=32,z=32}
	local mapX=Game.mapSizeX/16
	local mapY=Game.mapSizeY/16
	local PointOfIgnition=1200
	
	local LandScapeTable={}
	for i=1,Game.mapSizeX/16, 1 do
	for j=1,Game.mapSizeY/16,1 do
		LandScapeTable[i][j]={boolBurning=false,Food=getFood(i*16,j*16),AccumulatedHeat=0}
	end
	end
	
	local fireCounter=0
	
	
	function gadget:Explosion(weaponID, px, py, pz, AttackerID)
	end

	function gadget:UnitDamaged(unitID, unitDefID, unitTeam, damage, paralyzer, weaponDefID, attackerID, attackerDefID, attackerTeam) 
	end
	
	function getFood(x,y)
	--TODO GetGrass
	return math.random(0,100)
	end
	
	function addFiresFromGG()
	if not GG.AddFire then GG.AddFire={} end
	for i=1,#GG.AddFire,1 do
		fireTable[#fireTable+1]={x=GG.AddFire.x,y=GG.AddFire.y}
	end
	GG.AddFire={} 
	end
	
	local spSpawnCEG=Spring.SpawnCEG
	function drawFlames_AddDamage() 
		for i=1,#fireTable do
		spSpawnCEG("foorestfire",fireTable[i].x,Spring.GetGroundHeight(fireTable[i].x,fireTable[i].z)+20,fireTable[i].z,0,0,0)
		T=grabEveryone("placeholder",fireTable[i].x,fireTable[i].z,22)
		foreach(T,function(id) Spring.AddUnitDamage(10) end )
		end
	end
	
	function updateWind() 
	windVector.x,windVector.z=Spring.GetWind()
	end
	
	function addHeatToSurroundingArea(nr,heat)
	wX=windVector.x/math.max(math.abs(windVector.x),math.abs(windVector.z))
	wZ=windVector.z/math.max(math.abs(windVector.x),math.abs(windVector.z))
	X,Y=fireTable[nr].x,fireTable[nr].z
	X,Y=X+wX,Y+wZ
	
	
	startX,endX=math.max(1,X-1),math.min(X+1,mapX)
	startY,endY=math.max(1,Y-1),math.min(Y+1,mapY)
	for x=startX,endX,1 do
	for y=startY,endY,1 do
		LandScapeTable[x][y].AccumulatedHeat=LandScapeTable[x][y].AccumulatedHeat+heat/2
		if LandScapeTable[x][y].AccumulatedHeat > PointOfIgnition and LandScapeTable[x][y].boolBurning==false and LandScapeTable[x][y].Food >0 then
		fireTable[#fireTable+1]={x=x,y=y}
		LandScapeTable[x][y].boolBurning=true
		fireCounter=fireCounter+1
		end
	end
	end
	
	end
	
	function updateFire() 
	if fireCounter > 0 then
	for i=#fireTable,i>0,-1 do
		LandScapeTable[fireTable[i].x][fireTable[i].z].Food=		LandScapeTable[fireTable[i].x][fireTable[i].z].Food-costPerFrame
		LandScapeTable[fireTable[i].x][fireTable[i].z].AccumulatedHeat=		LandScapeTable[fireTable[i].x][fireTable[i].z].AccumulatedHeat+InHeat
		addHeatToSurroundingArea(i,LandScapeTable[fireTable[i].x][fireTable[i].z].AccumulatedHeat)
		if LandScapeTable[fireTable[i].x][fireTable[i].z].Food <0 then table.remove(fireTable,i); fireCounter=fireCounter-1 end
	end
	end
	end
	
	function gadget:GameFrame(frame)
	
		if frame % 50 == 0 then
			updateWind()
		end
		
		if frame % 10 == 0 then
			drawFlames_AddDamage()
		end
		
		if frame % 100 == 0 then
			addFiresFromGG()
			updateFire()	
		end
	
	end
	
	
end
	
TODO: Its never LUPUS
Add Food per tyle by grass and features
Destroy Features and add a Burned Ground Decal
Slow Regrowth of FireFood
Get the stupid Gaia Wildlife of JW to realize, this is not fun, even though not a nearby enemy
FeatureRequest: Spring emulating the smell of delicious roastbeef
This is ridicolous stuff.. the sort of that makes you check where the wind is coming and then set fire to the lawn in front of your base

Re: How does one add LUPS effects

Posted: 13 Feb 2015, 22:29
by jK
https://github.com/jk3064/lups/blob/mas ... s.lua#L341

-> either set unit<0 or use the worldspace tag

Re: How does one add LUPS effects

Posted: 13 Feb 2015, 23:40
by Jools
If you have a working forest fire, could I please use it in Johns pond map? It is WIP and I think I even deleted the forest fires gadget.