Random Tome -- sourceforge download

All new ideas for the upcoming releases of ToME 4.x.x should be discussed here

Moderator: Moderator

Message
Author
asthmatic_thematic
Higher
Posts: 79
Joined: Tue Aug 19, 2008 7:15 pm

Re: Random Tome -- sourceforge download

#16 Post by asthmatic_thematic »

Ah, jolly good. I've put some things in pre-init, and run T-Engine from a terminal, and seen the output. I'll eventually need to be printing to files; I can worry about that later.

So I want to get the structure right before I start hammering away at code.

Here are some functions I think I will need to put into a new file, which pre-init will load for now:

Code: Select all

-- initialize world variables, including elevation, terrain, tectonic bias, and wetness
function _M:init(w, h, elev, terr, tect, wet)
   self.w = w
   self.h = h
   self.elev = {}
   self.terr = {}
   self.tect = {}
   self.wet  = {}

   for i = 1, self.w do
      self.elev[i] = {}
      self.terr[i] = {}
      self.tect[i] = {}
      self.wet[i]  = {}
      for j = 1, self.h do
         self.elev[i][j] = 0
         self.terr[i][j] = 0
         self.tect[i][j] = 0
         self.wet[i][j]  = 0
      end
   end
end

-- generate initial elevation matrix
function _M:setelev()
-- use diamond square to fill elev with fractal
end

-- generate tectonic bias matrix
function _M:settect()
-- use diamond square to fill tect with fractal
end

-- generate initial humidity matrix
function _M:setwet()
-- use diamond square to fill wet with fractal
end

-- convert a single elevation value to initial terrain description
-- @param x the elevation value
-- @return the initial terrain description
function _M:elev2terr(x)
-- should have two lua tables or something sexy here for genericness
--   eg: {PLAINS, H_LOWHILLS, H_HILLS, H_MOUNTAINS}  &  {DEEP, PLAINS, LOWHILLS, HILLS, MOUNTAINS, PEAK}
--   where DEEP is anything below the first item in the first list, and PEAK is anything above the last item, etc.
   if self.elev[i][j]<0                                           then self.terr[i][j] = DEEP      end
   if self.elev[i][j]>0           and self.elev[i][j]<H_LOWHILLS  then self.terr[i][j] = PLAINS    end
   if self.elev[i][j]>H_LOWHILLS  and self.elev[i][j]<H_HILLS     then self.terr[i][j] = LOWHILLS  end
   if self.elev[i][j]>H_HILLS     and self.elev[i][j]<H_MOUNTAINS then self.terr[i][j] = HILLS     end
   if self.elev[i][j]>H_MOUNTAINS and self.elev[i][j]<H_PEAK      then self.terr[i][j] = MOUNTAINS end
   if self.elev[i][j]>H_PEAK                                      then self.terr[i][j] = PEAK      end
end

-- convert elevation matrix to initial terrain matrix
function _M:setterr()
   for i = 1, self.w do
      for j = 1, self.h do
         self.terr[i][j] = elev2terr(self.elev[i][j])
      end
   end
end

-- determine the continental geographic center 
-- (will eventually be used multiple times for multiple continents/islands, 
--  with different constraints each time)
function _M:getgeocenter() -- constraints as args?
-- impose any structure constraints here: eg, island in NW, etc.
   local x_geo = rng.range(1, self.w)
   local y_geo = rng.range(1, self.h)
   return x_geo, y_geo
end

-- scale radially down from a continental geographic center
function _M:scaleradial()
   x_geo, y_geo = self.getgeocenter()
   -- get a 1d fractal for distance-trigger from geo center
   -- get a 1d fractal for slope to use after trigger
   -- loop through elevation matrix: get angle, interpolate, scale down by angle & distance
end

-- raise and lower random topographic cones

-- raise or lower map using eg quicksort so there is eg 70% land; adjust gini coefficient for correct plains amount

-- add mountain ranges

-- then turn to terrain features: rivers, woods, etc
------------------------------
Then I will have pre-init call all these functions, and I will output the elevation and terrain results to a file, finishing up with os.exit(), and then I will probably continue to use gnuplot for a while to pore over the resulting file.

I obviously haven't run the above code; I'm just trying to get a sense of the overall structure of what things will look like eventually. The first steps will just be doing a fractal fill of the elevation map and looking at it in gnuplot.

(1) Am I on the right track for the style of coding? If I'm right that I should move all the function declarations into a methods file, and then call them all from pre-init, what sort of header do I need to put at the top of the file with all the functions above--the class name information and any "require" statements? ... Then, in pre-init, I assume I need to say, eg, "require worldgen" or something to that effect. If you could be pretty explicit about what the header of the class file and the header I need in pre-init, that'd be great, since this is a bit new to me.

(2) What will the lua code to call the C diamond-square routine look like when plugged in above, filling up elevation with a fractal? By the way, DG, I'll need both FractalFills in 2d and 1d from my original file; the 1d one gets used for example to make mountain ranges look a little jiggly, and to make radial features look a little wiggly.

Once these initial structural things get going, I don't think this is going to take *too* long to convert to lua, although adding generality and genericness will take a bit more time, as we figure out what people want beyond just what I've been using this code for (especially long term will be civilizations and their claims and destroying towns into ruins etc).
Last edited by asthmatic_thematic on Wed Mar 23, 2011 3:35 pm, edited 2 times in total.

asthmatic_thematic
Higher
Posts: 79
Joined: Tue Aug 19, 2008 7:15 pm

Re: Random Tome -- sourceforge download

#17 Post by asthmatic_thematic »

By the way: we'll probably eventually need to generalize the aStar a bit: my aStar take a civilization-type parameter and a walkmax parameter, so it can do thinks like treat certain terrain as somewhat-walkable--elves can go through forests with ease, and deepwater civilizations can sail the seas, etc. That's why my elf civs usually claimed forests in valleys, but dwarfy and trolly type people would own the mountains above them. (Their claim of a point was affected by the terrain along their easiest path to that point, and which terrain a fight took place in had a huge effect on who won it.)

asthmatic_thematic
Higher
Posts: 79
Joined: Tue Aug 19, 2008 7:15 pm

Re: Random Tome -- sourceforge download

#18 Post by asthmatic_thematic »

LUA progress. about 80% done implementing worldgen c code, except for site placement. (looking at astar and map stuff for that now.) fractals not in yet; just placeholders. looks surprisingly good even without. below are some plots that are basically masks which will be imposed on fractal data.

generally, next step is site-placement, and then working on a way to interface this with the game code.

sandbox text to put at end of default engine init.lua file. (note this won't run the game, just output some data files for examination.) this just invokes the functions.
http://pastebin.com/zvbJ7C7K

file genworld.lua -- must be called that. right now in game/engine/default/engine.
http://pastebin.com/FC0wUTjV

a couple of pretty pictures:

elevation file. note, no fractals yet; but when this is masked over a fractal, it'll look goooood.
Screen shot 2011-03-29 at 11.24.17 PM.png
Screen shot 2011-03-29 at 11.24.17 PM.png (51.91 KiB) Viewed 3109 times
terrain file. same as previous posts: you can see, eg, yellow deserts, orange forests, blue river-lines and red lakes, purple hills and mountains, etc.
Screen shot 2011-03-29 at 11.23.44 PM.png
Screen shot 2011-03-29 at 11.23.44 PM.png (28.35 KiB) Viewed 3109 times

Canderel
Sher'Tul
Posts: 1252
Joined: Mon Nov 24, 2003 2:31 pm
Location: South Africa

Re: Random Tome -- sourceforge download

#19 Post by Canderel »

One should add this to the "empty" modules by default for them to have a world. So the empty modules are less empty and easier to have a bit of stuff to fluff out.

asthmatic_thematic
Higher
Posts: 79
Joined: Tue Aug 19, 2008 7:15 pm

Re: Random Tome -- sourceforge download

#20 Post by asthmatic_thematic »

hmmm, that's an interesting idea.

once all the default initialization variables get settled, they'll need to be put into a form which te4's maps and objects like, and which is fairly compatible with te4's other ways of managing data lists. (right now, during development, these initialization values show up in a big list of c preprocessor style capital letter loose variables, and are unfriendly to change by hand.)

even once they work and play well with te4, putting this in empty might make empty a bit more cutting edge/complicated than it needs to be. but having access to this would also reduce the amount of work it takes for someone to turn empty from a dummy module into something real, which is i guess part of the purpose of empty.

i think empty's probably a good idea, especially if the other option is to make another sample dummy module with just random worldgen in it. or, i guess this could go as a class in the default engine...

yufra
Perspiring Physicist
Posts: 1332
Joined: Tue Jul 13, 2010 2:53 pm

Re: Random Tome -- sourceforge download

#21 Post by yufra »

Has anyone touched this in a while? The community module will probably try to use this at some point...
<DarkGod> lets say it's intended

asthmatic_thematic
Higher
Posts: 79
Joined: Tue Aug 19, 2008 7:15 pm

Re: Random Tome -- sourceforge download

#22 Post by asthmatic_thematic »

Hi hi!

A while back, I tried restarting this--I plugged my changes to the code into version 24, I think, and got some new errors due to changes in the way things are handled.

My time is a bit more limited now: the reason I stopped working on this six months ago was that I had a baby daughter, and six weeks later moved from England to New York and started a new law job.

But things have settled down a fair bit now, and so I have *some* time. If someone would be willing to work with me to get this into a very basic mod (e.g., just creating a worldmap to move around, or whatever the best way to integrate this is), I could work in parallel on getting the rest of the C code stuff into lua. (Basic topology is there, but I still need to translate the C routines for gradients for rivers, humidity maps, forests, etc.). A small part of the previous difficulty was that my lua wasn't very good, but a bigger part was that T4 is very very complex.

Let me know!
Thanks,
A-T

yufra
Perspiring Physicist
Posts: 1332
Joined: Tue Jul 13, 2010 2:53 pm

Re: Random Tome -- sourceforge download

#23 Post by yufra »

Congratulations on your daughter and job, that is really cool. :D

I think you are right, a collaboration to get it into an example module is a good idea. I am fairly competent at Lua + TE4, but am putting a lot of effort into getting the sci-fi community module off the ground right now. A random world generator would be so useful for that module, though, that I will try to prioritize this as soon as possible. Alternatively we can try to recruit one of the other people that are good with Lua + TE4. The ones that hang out on IRC (and thus are easy to find and chat with) that fit that bill are:
  • tiger_eye, has experience with the C core and did a lot of refactoring of the FOV code
  • Goblinz, been really active in creating add-ons for ToME4
  • edge2054, a lot of class development
I chatted briefly with tiger_eye about it and he seems interested. If you have time maybe stop by the IRC channel to chat?
<DarkGod> lets say it's intended

asthmatic_thematic
Higher
Posts: 79
Joined: Tue Aug 19, 2008 7:15 pm

Re: Random Tome -- sourceforge download

#24 Post by asthmatic_thematic »

Sounds great! I should have some time this wknd. In the meantime I will get the code into b27 and get to the latest error I was stopped on.

Thanks!

asthmatic_thematic
Higher
Posts: 79
Joined: Tue Aug 19, 2008 7:15 pm

Re: Random Tome -- sourceforge download

#25 Post by asthmatic_thematic »

Current status: with just a bit of work, I updated the old situation for b37, so I can recreate the same bug in the most recent release. This bug arose because of a change maybe around b30 or so; before that I could make map arrays and output them to a file to look at, at least.

Here is all I've done so far. I manually insert this text:
http://tinypaste.com/fbefba49
at the bottom of Contents/Resources/game/engines/default/engine/init.lua

Then I include this file:
http://tinypaste.com/023a0c5c
in the same directory as the modified file above in a file called "genworld.lua". In the old days I would run tome, it would spit out a map array, and then tome would quit. Now, I get this error:
Screen Shot 2012-01-12 at 9.38.57 PM.png
Screen Shot 2012-01-12 at 9.38.57 PM.png (20.93 KiB) Viewed 2927 times
The first step is to get past this error. Anybody know what has changed?

I keep feeling if I could just get this project past a certain stage, it would be easy, but I can never get it started.:)

tiger_eye
Perspiring Physicist
Posts: 889
Joined: Thu Feb 17, 2011 5:20 am

Re: Random Tome -- sourceforge download

#26 Post by tiger_eye »

Hey asthmatic_thematic, it'd be cool to see this thing working again.

How are you constructing the map? Specifically, how are you adding terrain to each grid? From the lua error, it appears that you can create terrain at x, y, but that the terrain you add aren't derived from "Entity". Pretty much everything (actors, terrain, objects, projectiles, etc) is an Entity of some kind, which is where the method "getMapObjects" is defined.

As to what changed in the code around b30: I have no idea.

Oh, and one more teeny tiny thing: why do you use both: 'require "engine.Map"' and 'local Map = require "engine.Map"'? Typically only the latter is used.

yufra
Perspiring Physicist
Posts: 1332
Joined: Tue Jul 13, 2010 2:53 pm

Re: Random Tome -- sourceforge download

#27 Post by yufra »

tiger_eye wrote: How are you constructing the map? Specifically, how are you adding terrain to each grid? From the lua error, it appears that you can create terrain at x, y, but that the terrain you add aren't derived from "Entity". Pretty much everything (actors, terrain, objects, projectiles, etc) is an Entity of some kind, which is where the method "getMapObjects" is defined.
Yup, that does indeed look like the problem. The "self.terr" table is filled with the ASCII characters that are placed in the init.lua file. These entity objects are not actually available where you are currently placing the code, so that is another issue. I think that we actually want to take your code and make it into a fully-fledged Generator subclass. If you look at the engine/Generator.lua and the engine/generator/map/Cavern.lua you should be able to get an idea of what is going on there. We can help you transition the code over there if you want, or if you would prefer to just look on your own and get back to us that is fine too. Cheers!
<DarkGod> lets say it's intended

tiger_eye
Perspiring Physicist
Posts: 889
Joined: Thu Feb 17, 2011 5:20 am

Re: Random Tome -- sourceforge download

#28 Post by tiger_eye »

*bump*

asthmatic_thematic, how are things going? Many of us are now collaborating on code using gitorious.org, so if you want to set things up there (we can help) and continue making an interesting random world generator, we could help collaborate and integrate it into ToME.
darkgod wrote:OMFG tiger eye you are my hero!

Post Reply