Page 1 of 1

With Lua, is it feasible for...

Posted: 24 May 2008, 22:03
by Noruas
Well i looked at some old ta stuff, and found the hydration plant, that creates water, and i thought to myself, if you pay a krogoth sum for this, and it creates water as description, it can change a land map into a sea map by 1 terrain lowered or water level by one, and destroys disables all land units as a unique end gamer.
So in otherwords, without causing too much strain on pc, is it feasible for every 30 seconds, the water level raises by 1, till completely submerged (detect max height of map) as a unique end gamer unit style as to *drown them all out* because id love to test that out.

Re: With Lua, is it feasible for...

Posted: 25 May 2008, 01:05
by Guessmyname
Hmm. Anyone else forseeing issues with pre-existing floating structures?

Re: With Lua, is it feasible for...

Posted: 25 May 2008, 01:30
by Argh
It is perfectly possible to manipulate the heightmap to create the effect desired. However:

1. I may be wrong, but the only method I know of to do this is very computationally expensive. You can't just raise the water level- you'd have to drop the land-level. Not the same thing at all. Now, if the water-level variable was accessible via Lua, it'd be pretty cheap to do it that way. Doing it with the heightmap-adjustment method would be incredibly expensive, and would have to be spaced out over a number of frames to prevent severe problems.

It can be done, but it'd have to be quite slowly done- probably several seconds for a single adjustment over a whole map. Maybe I should write some code to do this, I have just about everything needed to do this kind of work in World Builder already.

2. I don't think that floating stuff would adjust to the method of changing the water level- I think their height is set when created, and doesn't change after that.

Re: With Lua, is it feasible for...

Posted: 25 May 2008, 03:53
by lurker
Changing the water level would break a lot of things all over. It's not that bad to change the land height if it's a slow effect.

Re: With Lua, is it feasible for...

Posted: 25 May 2008, 04:11
by trepan
The original post contained some performance numbers,
and even a suggested method for your request (segmented changes).

viewtopic.php?p=172300#p172300

Re: With Lua, is it feasible for...

Posted: 25 May 2008, 06:20
by Argh
Yeah, a half-second on that chip means probably around 3/4th second on this rig- far too slow to run in one frame. That said, meh, doing it in stages, a few thousand heightmap pixels at a time, is no biggie.
Ships get stuck when they try to go over an area that was formerly land. You can still drive them around in FPS mode, and it looks like they should be able to go through the area using F2 view, but they still get stuck once they stop moving and don't respond to orders.
This testing result indicates that the pathfinder for ships is not seeing changes made to the heightmap (big surprise there, since this was probably never envisioned). Meh, I'll test this, but I strongly suspect this problem still exists, so this may trap land-units, but it may not result in proper functionality overall.

Re: With Lua, is it feasible for...

Posted: 25 May 2008, 08:11
by SwiftSpear
I don't see why you think raising the water level would be less expensive than lowering the ground level. The computer doesn't know the difference between the two anyways, and you still need all the code to ratify whatever change is being made physically to the units and structures that will be effected by that change.

Re: With Lua, is it feasible for...

Posted: 25 May 2008, 09:01
by lurker
Well, you wouldn't have to update the entire LOS map. The rest of the load would stay the same.

Re: With Lua, is it feasible for...

Posted: 25 May 2008, 09:22
by KDR_11k
SwiftSpear wrote:I don't see why you think raising the water level would be less expensive than lowering the ground level. The computer doesn't know the difference between the two anyways, and you still need all the code to ratify whatever change is being made physically to the units and structures that will be effected by that change.
Um, changing the water level (if it wasn't hardcoded) would just be changing one value while changing the whole terrain requires changing a value for each terrain spot (128*mapSizeX*128*mapSizeZ spots IIRC, about 4 million on a 16x16 map). The units affected are capped at 10000.

Re: With Lua, is it feasible for...

Posted: 25 May 2008, 09:27
by lurker
But changing the water level means recoding every bit of code that checks if something is underwater. And you still have to repath.

Re: With Lua, is it feasible for...

Posted: 25 May 2008, 11:43
by quantum
Slowly adjusting the height map in order to avoid pauses makes the terrain entirely unpassable for some reason.

Here is the unfinished gadget:

Code: Select all

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

function gadget:GetInfo()
  return {
    name      = "Random Terrain",
    desc      = "Randomizes the heightmap",
    author    = "quantum",
    date      = "April 28, 2008",
    license   = "GNU GPL, v2 or later",
    layer     = 0,
    enabled   = false  --  loaded by default?
  }
end

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

if (not gadgetHandler:IsSyncedCode()) then
  return false  --  no unsynced code
end

-- Spring.AdjustHeightMap
-- Game.mapSizeX
-- Game.mapSizeZ

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------


local Spring = Spring
local Game = Game
local math = math
local table = table
local coroutine = coroutine

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

local function MakeTerrain()
  local separation = 8*4*4
  local minY = 0
  local maxY = 1000
  local adjustment = 0
  local offset = 0
  for i=0, 0 do
    for x=0, Game.mapSizeX/separation do
      local xs = x*separation+offset
      for z=0, Game.mapSizeZ/separation do 
        local zs = z*separation+offset
        local y = 100
        Spring.AdjustHeightMap(xs, zs, xs+separation+adjustment, zs+separation+adjustment, y)
      end
      coroutine.yield()
    end
  end
end

local co = coroutine.create(MakeTerrain)

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

function gadget:GameFrame(n)
  coroutine.resume(co)
end

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

Re: With Lua, is it feasible for...

Posted: 31 May 2008, 17:51
by CarRepairer
Reminds me of Worms: World Party when the game goes into sudden death mode and the water starts rising, worms near the bottom drown.

Re: With Lua, is it feasible for...

Posted: 31 May 2008, 18:15
by LordMatt
lol I remember worms.

Re: With Lua, is it feasible for...

Posted: 05 Jun 2008, 00:57
by Zoy64
the Sega dreamcast version was fun...