Remove YAMG
There are better uses of our time and energy.
This commit is contained in:
parent
17ad6353d9
commit
bed44694fd
13 changed files with 0 additions and 3276 deletions
|
@ -426,15 +426,6 @@
|
|||
<Unit filename="../../src/generators/map_create.hpp" />
|
||||
<Unit filename="../../src/generators/map_generator.cpp" />
|
||||
<Unit filename="../../src/generators/map_generator.hpp" />
|
||||
<Unit filename="../../src/generators/yamg/ya_mapgen.cpp" />
|
||||
<Unit filename="../../src/generators/yamg/ya_mapgen.hpp" />
|
||||
<Unit filename="../../src/generators/yamg/yamg_decls.hpp" />
|
||||
<Unit filename="../../src/generators/yamg/yamg_hex.cpp" />
|
||||
<Unit filename="../../src/generators/yamg/yamg_hex.hpp" />
|
||||
<Unit filename="../../src/generators/yamg/yamg_hexheap.cpp" />
|
||||
<Unit filename="../../src/generators/yamg/yamg_hexheap.hpp" />
|
||||
<Unit filename="../../src/generators/yamg/yamg_params.cpp" />
|
||||
<Unit filename="../../src/generators/yamg/yamg_params.hpp" />
|
||||
<Unit filename="../../src/generic_event.cpp" />
|
||||
<Unit filename="../../src/generic_event.hpp" />
|
||||
<Unit filename="../../src/gettext.hpp" />
|
||||
|
|
|
@ -1060,10 +1060,6 @@ set(libwesnoth-game_STAT_SRC
|
|||
generators/default_map_generator.cpp
|
||||
generators/default_map_generator_job.cpp
|
||||
generators/lua_map_generator.cpp
|
||||
generators/yamg/ya_mapgen.cpp
|
||||
generators/yamg/yamg_hex.cpp
|
||||
generators/yamg/yamg_hexheap.cpp
|
||||
generators/yamg/yamg_params.cpp
|
||||
hotkey/command_executor.cpp
|
||||
hotkey/hotkey_item.cpp
|
||||
hotkey/hotkey_command.cpp
|
||||
|
|
|
@ -105,10 +105,6 @@ libwesnoth_sources = Split("""
|
|||
generators/default_map_generator.cpp
|
||||
generators/default_map_generator_job.cpp
|
||||
generators/lua_map_generator.cpp
|
||||
generators/yamg/ya_mapgen.cpp
|
||||
generators/yamg/yamg_hex.cpp
|
||||
generators/yamg/yamg_hexheap.cpp
|
||||
generators/yamg/yamg_params.cpp
|
||||
key.cpp
|
||||
language.cpp
|
||||
loadscreen.cpp
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
#include "map_create.hpp"
|
||||
|
||||
#include "generators/cave_map_generator.hpp"
|
||||
#include "generators/yamg/ya_mapgen.hpp"
|
||||
#include "generators/default_map_generator.hpp"
|
||||
#include "generators/lua_map_generator.hpp"
|
||||
#include "log.hpp"
|
||||
|
@ -35,8 +34,6 @@ map_generator* create_map_generator(const std::string& name, const config &cfg)
|
|||
return new default_map_generator(cfg);
|
||||
} else if(name == "cave") {
|
||||
return new cave_map_generator(cfg);
|
||||
} else if(name == "yamg") {
|
||||
return new ya_mapgen(cfg);
|
||||
} else if(name == "lua") {
|
||||
return new lua_map_generator(cfg);
|
||||
} else {
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,151 +0,0 @@
|
|||
/*
|
||||
Copyright (C) 2013 - 2015 by L.Sebilleau <l.sebilleau@free.fr>
|
||||
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
/*
|
||||
Yet Another Map Generator.
|
||||
|
||||
This class is the main generator class. Once instanced and configured, it can create a random map and can produce a buffer which BfW can use.
|
||||
Each generator owns a single map, but multiple instances can be used. Generator can be reused too.
|
||||
|
||||
Public functions are used in this order in the standalone tool:
|
||||
- Constructor
|
||||
- Configuration creation and modification.
|
||||
- SetUp : install and check configuration.
|
||||
- CreateMap : create the map in memory.
|
||||
- GetMap : write the map data to a buffer.
|
||||
- ResetMap : free the old map and reset the generator to default values.
|
||||
|
||||
Provisions have been made to make this class a child of map_generator, but the implementation is not finished yet.
|
||||
*/
|
||||
|
||||
#ifndef YA_MAPGEN_HPP
|
||||
#define YA_MAPGEN_HPP
|
||||
|
||||
#include "yamg_params.hpp"
|
||||
#include "yamg_hex.hpp"
|
||||
#include "yamg_hexheap.hpp"
|
||||
|
||||
#ifndef YAMG_STANDALONE
|
||||
#include "config.hpp"
|
||||
#include "generators/map_generator.hpp"
|
||||
#endif
|
||||
|
||||
/**
|
||||
This structure is used to store one hex and it's neighbors
|
||||
*/
|
||||
struct neighbors {
|
||||
yamg_hex *center;
|
||||
yamg_hex *no;
|
||||
yamg_hex *nw;
|
||||
yamg_hex *sw;
|
||||
yamg_hex *so;
|
||||
yamg_hex *se;
|
||||
yamg_hex *ne;
|
||||
};
|
||||
|
||||
/**
|
||||
This structure is used to store the burgs
|
||||
*/
|
||||
struct burg {
|
||||
burg *next;
|
||||
yamg_hex *center;
|
||||
yamg_hex *road1;
|
||||
yamg_hex *road2;
|
||||
};
|
||||
|
||||
//============================== Class definition =========================
|
||||
|
||||
#ifdef YAMG_STANDALONE
|
||||
class ya_mapgen
|
||||
{
|
||||
public:
|
||||
|
||||
#else
|
||||
|
||||
class ya_mapgen: public map_generator
|
||||
{
|
||||
public:
|
||||
ya_mapgen(const config& cfg);
|
||||
#endif
|
||||
ya_mapgen();
|
||||
virtual ~ya_mapgen();
|
||||
|
||||
//----------- Inherited methods from map_generator -----------------
|
||||
|
||||
#ifndef YAMG_STANDALONE
|
||||
std::string name() const; // {return "yamg";};
|
||||
std::string config_name() const; // {return "generator";};
|
||||
std::string create_map(boost::optional<boost::uint32_t> randomseed);
|
||||
#endif
|
||||
|
||||
//----------------- Methods -------------
|
||||
|
||||
unsigned int set_up(yamg_params *); ///< uses parameter list object to configure
|
||||
int do_create_map(); ///< do the job, return OK if everything is OK
|
||||
int get_map(char *buf); ///< write the map to a buffer
|
||||
void reset_map(); ///< reset the generator to new use
|
||||
|
||||
protected:
|
||||
//----------------- Functions -------------
|
||||
|
||||
unsigned int create_empty_map(); ///< creates an empty map according parameters height and width
|
||||
unsigned int free_map(); ///< frees all memory used
|
||||
|
||||
void create_altitudes(unsigned int x, unsigned int xm, unsigned int y,
|
||||
unsigned int ym, unsigned int rough); ///< compute hexes altitudes
|
||||
int normalize_map(); ///< normalize altitudes
|
||||
void set_base_terrains(int range); ///< set hexes base terrains
|
||||
void custom_terrains(); ///< terrain customization
|
||||
|
||||
void make_rivers(); ///< create river and lakes
|
||||
int calc_water_contribs(yamg_hex *h); ///< calculate rain flowing
|
||||
void erode_terrains(yamg_hex *h, int report); ///< erode terrains to make rivers
|
||||
|
||||
void make_burgs(); ///< creates the burgs (some agglomerated villages)
|
||||
void make_castles(); ///< creates the castles
|
||||
void make_forests(); ///< set forests overlays
|
||||
void make_houses(); ///< creates some houses (villages)
|
||||
void make_roads(); ///< creates roads
|
||||
|
||||
void get_neighbors(yamg_hex *h, neighbors* p); ///< get neighbours of some hex
|
||||
int fill_with(const char *over[], yamg_hex *h, int num); ///< utility to fill overlays
|
||||
void clear_done_flag(); ///< reset done flag on all hexes
|
||||
yamg_hex *sel_neigh(yamg_hex *it); ///< lists the available hexes for roads
|
||||
void store_neighbors(yamg_hex *it, unsigned int layMin, unsigned int layMax); ///< get neighbours and store them in the heap
|
||||
|
||||
private:
|
||||
unsigned int status_; ///< this is the state of the generator.
|
||||
unsigned int siz_; ///< the 'real' size of the map (used allocation and computing altitudes) 2^n + 1
|
||||
yamg_params *parms_; ///< its parameter list.
|
||||
yamg_hex ***map_; ///< the generated map
|
||||
yamg_hex *summits_; ///< a list of hexes, various purposes
|
||||
yamg_hex *endpoints_; ///< something to store a list of road startpoints
|
||||
yamg_hex *castles_; ///< a list of castle keeps
|
||||
|
||||
int table_[M_NUMLEVEL]; ///< array defining layers boundaries.
|
||||
int snow_limit_; ///< the snow limit floor.
|
||||
unsigned int riv_; ///< the reference water level
|
||||
const char *terrains_[M_NUMLEVEL]; ///< terrains to use for each layer (overloaded with snow)
|
||||
yamg_hexheap *heap_; ///< an utility heap to sort hexes
|
||||
};
|
||||
|
||||
int m_rand(int limit); ///< returns a random number 0 < n < limit
|
||||
void init_rand(unsigned int seed); ///< init random number generator
|
||||
|
||||
#ifdef INTERN_RAND
|
||||
void init_genrand(unsigned long s); ///< embedded RNG initialization
|
||||
unsigned long genrand(void); ///< RNG production
|
||||
#endif
|
||||
|
||||
#endif // YA_MAPGEN_HPP
|
|
@ -1,146 +0,0 @@
|
|||
/*********************************************************************
|
||||
Yet Another Map Generator.
|
||||
|
||||
This contains common definitions and compile flags
|
||||
|
||||
Copyright (C) 2012 L.Sebilleau (Pyrophorus)
|
||||
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
|
||||
v 0.8 -- 01/03/2012
|
||||
v 0.9 -- 27/11/2012
|
||||
v 1.0 -- 15/12/2012
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
**********************************************************************/
|
||||
|
||||
#ifndef YAMG_DECLS_HPP
|
||||
#define YAMG_DECLS_HPP
|
||||
|
||||
//#include <stdio.h>
|
||||
|
||||
// ================ compilation flags ================
|
||||
//#define YAMG_STANDALONE ///< switches to the standalone version (the only one at this time).
|
||||
#define INTERN_RAND ///< uses embedded RNG instead of system RNG. This allow to make the result platform independent.
|
||||
|
||||
// ================ Common definitions ===============
|
||||
#ifndef NULL
|
||||
#define NULL 0L
|
||||
#endif
|
||||
|
||||
//-------------- Values limits ---------------
|
||||
#define YAMG_MAPMAXSIZE 500
|
||||
#define YAMG_ROUGHMAX 50
|
||||
#define YAMG_TYPES "ptmdec" // p(olar) t(empered) m(editerranean) d(esert) e(quatorial) c(ustom)
|
||||
#define YAMG_SEASONS "seaw" // s(pring) e(aster) a(utumn) w(inter)
|
||||
#define YAMG_ALTMAX 100
|
||||
#define YAMG_VILLMAX 100
|
||||
#define YAMG_BURGMAX 20
|
||||
#define YAMG_TOWNSMAX 5
|
||||
#define YAMG_FORESTMAX 100
|
||||
#define YAMG_PLAYERSMAX 20
|
||||
|
||||
//------------- Map config error codes (bits in one word result) TODO: add new parms errors
|
||||
|
||||
#define YAMG_LIMITS 1 ///< map config errors
|
||||
#define YAMG_ROUGHOFF YAMG_LIMITS<<1
|
||||
#define YAMG_BADTYPE YAMG_ROUGHOFF<<1
|
||||
#define YAMG_BADSEASON YAMG_BADTYPE<<1
|
||||
#define YAMG_SNOW YAMG_BADSEASON<<1
|
||||
#define YAMG_ALTOFF YAMG_SNOW<<1
|
||||
#define YAMG_VILLOFF YAMG_ALTOFF<<1
|
||||
#define YAMG_BURGOFF YAMG_VILLOFF<<1
|
||||
#define YAMG_TOWNSOFF YAMG_BURGOFF<<1
|
||||
#define YAMG_FORESTOFF YAMG_TOWNSOFF<<1
|
||||
#define YAMG_PLAYERSOFF YAMG_FORESTOFF<<1
|
||||
|
||||
//-------------- Generator status codes ---------------
|
||||
enum {
|
||||
YAMG_ERROR = -1, ///< unknown errors (should never happen)
|
||||
YAMG_EMPTY = 0, ///< new generator, defaults values
|
||||
YAMG_CONFIGURED, ///< a parameter list has been set
|
||||
YAMG_LOADED, ///< a map has been created
|
||||
};
|
||||
|
||||
//-------------- Result codes ---------------
|
||||
enum {
|
||||
YAMG_OK = 0, ///< OK
|
||||
YAMG_NOCONFIG, ///< missing config
|
||||
YAMG_NOMAP, ///< No map to return
|
||||
YAMG_HAVEMAP, ///< A map is already created
|
||||
YAMG_FILENOTFOUND, ///< no parameter file of this name
|
||||
};
|
||||
|
||||
#define YAMG_HEXLONG 14 ///< fixed length of map elements in the result buffer
|
||||
|
||||
//-------------- MAPS defines --------------
|
||||
|
||||
#define M_BASE 100000
|
||||
#define M_VARIATION 10000
|
||||
#define M_RANGE 10000
|
||||
#define YAMG_RIVER_ADAPTATION 300 ///< to adapt the evaporation parameter.
|
||||
#define YAMG_DESERT_RIVER_OFFSET 25 ///< define a sublevel in desert maps to create oasis and sand pits.
|
||||
|
||||
#define MAX_HOUSESINBURG 7 ///< max houses in a burg
|
||||
#define MIN_HOUSESINBURG 4 ///< min houses in a burg
|
||||
#define MAX_HEXESINCASTLE 8 ///< max hexes in castles (ignored if hexcastle parameter is not 0)
|
||||
#define MIN_HEXESINCASTLE 3 ///< min hexes in castles (ignored if hexcastle parameter is not 0)
|
||||
|
||||
#define YAMG_ALTWEIGHT_SWAMP 1000 ///< these factors tune the altitude influence of road cost. Increasing them decrease altitude influence.
|
||||
#define YAMG_ALTWEIGHT_MOUNTAINS 500
|
||||
#define YAMG_ALTWEIGHT_GROUND 1000
|
||||
#define YAMG_ALTWEIGHT_HILLS 750
|
||||
|
||||
/**
|
||||
layers defines.
|
||||
The hexes are dispatched in eight distinct layers according to their altitude.
|
||||
MUST BE AN ENUM !!!
|
||||
*/
|
||||
#define M_NUMLEVEL 8
|
||||
enum {
|
||||
YAMG_DEEPSEA = 0,
|
||||
YAMG_SHALLSEA,
|
||||
YAMG_BEACH,
|
||||
YAMG_SWAMPS,
|
||||
YAMG_GROUND,
|
||||
YAMG_HILLS,
|
||||
YAMG_MOUNTAINS,
|
||||
YAMG_IMPMOUNTS,
|
||||
};
|
||||
|
||||
/**
|
||||
multi state locks defines
|
||||
Hexes may have a four states lock, so they can be protected from overloading by some operations only.
|
||||
Typical case is water hexes where no building can be set, but accept roads (bridges).
|
||||
MUST BE AN ENUM !!!
|
||||
*/
|
||||
enum {
|
||||
YAMG_UNLOCK = 0, ///< no lock
|
||||
YAMG_LIGHTLOCK, ///< light lock
|
||||
YAMG_STRONGLOCK, ///< strong lock
|
||||
YAMG_HARDLOCK, ///< absolute lock
|
||||
};
|
||||
|
||||
/**
|
||||
defs for rType hex member, used in roads drawing.
|
||||
This flag identifies:
|
||||
*/
|
||||
enum {
|
||||
R_NONE = 0, ///< no road at this time
|
||||
R_ROAD, ///< a road uses this hex
|
||||
R_STOP, ///< this hex is an endpoint for the roads
|
||||
R_HIT, ///< this endpoint have been reached by a road
|
||||
};
|
||||
|
||||
#endif // YAMG_DECLS_HPP
|
|
@ -1,68 +0,0 @@
|
|||
/*******************************************
|
||||
Yet Another map generator
|
||||
Implementation file.
|
||||
********************************************/
|
||||
|
||||
#include "yamg_hex.hpp"
|
||||
#include <stdio.h>
|
||||
|
||||
char default_hex_code[] = "Gll"; ///< terrain default value for the constructor
|
||||
char default_over[] = "";
|
||||
|
||||
/**
|
||||
This constructor initialize the hexes so createTerrainCode() will never produce invalid values.
|
||||
*/
|
||||
yamg_hex::yamg_hex(unsigned int xcoor, unsigned int ycoor)
|
||||
: next(NULL)
|
||||
, list(NULL)
|
||||
, road(NULL)
|
||||
, x(xcoor)
|
||||
, y(ycoor)
|
||||
, alt(0)
|
||||
, layer(YAMG_GROUND)
|
||||
, base(default_hex_code)
|
||||
, over(default_over)
|
||||
, player(0)
|
||||
, water(0)
|
||||
, key(0)
|
||||
, done(false)
|
||||
, lock(YAMG_UNLOCK)
|
||||
, road_type(R_NONE)
|
||||
, water_flag(false)
|
||||
{}
|
||||
|
||||
/**
|
||||
Write the terrain code of the hex in a buffer.
|
||||
The format is:
|
||||
[player numberSPACE]{base terrain}[^overlay]{SPACE padding UP to 12 chars},SPACE
|
||||
|
||||
-> pointer where to write.
|
||||
<- number of bytes written (always YAMG_HEXLONG)
|
||||
*/
|
||||
unsigned int yamg_hex::create_terrain_code(char *ptrwr) {
|
||||
|
||||
int n = 0;
|
||||
|
||||
//TODO
|
||||
// n = sprintf(ptrwr,"%6u, ",alt);
|
||||
// return n;
|
||||
|
||||
if(base == NULL)
|
||||
return 0; // TODO: this skips bad hexes, but the map will be incorrect. Raise an exception instead
|
||||
if(player != 0)
|
||||
n = sprintf(ptrwr,"%u ",player);
|
||||
|
||||
if(*over == '\0')
|
||||
n += sprintf((ptrwr+n),"%s",base);
|
||||
else
|
||||
n += sprintf((ptrwr+n),"%s^%s",base,over);
|
||||
ptrwr += n;
|
||||
n = 12 - n;
|
||||
for(;n > 0; n--)
|
||||
*ptrwr++ = ' '; // padd with spaces
|
||||
*ptrwr++ = ',';
|
||||
*ptrwr++ = ' ';
|
||||
|
||||
return YAMG_HEXLONG;
|
||||
|
||||
}
|
|
@ -1,66 +0,0 @@
|
|||
/*********************************************************************
|
||||
Yet Another Map Generator. Class YAMG_Hex
|
||||
|
||||
This class represents an individual hex on the map.
|
||||
The map itself is a two dimension array of (pointers to) objects of this class.
|
||||
|
||||
Copyright (C) 2012 L.Sebilleau (Pyrophorus)
|
||||
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
|
||||
v 0.8 -- 01/03/2012
|
||||
v 0.9 -- 27/11/2012
|
||||
v 1.0 -- 15/12/2012
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
**********************************************************************/
|
||||
|
||||
#ifndef YAMG_HEX_HPP
|
||||
#define YAMG_HEX_HPP
|
||||
|
||||
#include "yamg_decls.hpp"
|
||||
|
||||
class yamg_hex
|
||||
{
|
||||
public:
|
||||
yamg_hex(unsigned int xcoor, unsigned int ycoor);
|
||||
|
||||
yamg_hex* next; ///< to organize stacks and lists
|
||||
yamg_hex* list; ///< to organize stacks and lists
|
||||
yamg_hex* road; ///< to draw the roads
|
||||
|
||||
unsigned int x; ///< x,y coordinates
|
||||
unsigned int y;
|
||||
|
||||
int alt; ///< computed altitude
|
||||
unsigned int layer; ///< computed layer
|
||||
|
||||
const char *base; ///< base terrain
|
||||
const char *over; ///< overlay terrain
|
||||
unsigned int player; ///< player number if any
|
||||
unsigned int water; ///< temporary value for water computing
|
||||
int key; ///< temporary value for heap sort
|
||||
bool done; ///< temporary lock flag
|
||||
int lock; ///< the multi state lock
|
||||
int road_type; ///< a flag for use with roads drawing
|
||||
bool water_flag; ///< marking water terrains
|
||||
|
||||
//----------- methods ------------
|
||||
unsigned int create_terrain_code(char *ptr); ///< build the final output map code
|
||||
|
||||
protected:
|
||||
private:
|
||||
};
|
||||
|
||||
#endif // YAMG_HEX_HPP
|
|
@ -1,112 +0,0 @@
|
|||
/*******************************************
|
||||
Yet Another map generator
|
||||
Implementation file.
|
||||
********************************************/
|
||||
|
||||
#include "yamg_hexheap.hpp"
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
yamg_hexheap::yamg_hexheap(size_t taille)
|
||||
: last_(0)
|
||||
, max_(taille - 2)
|
||||
, table_(new yamg_hex *[taille * sizeof(yamg_hex *)])
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
yamg_hexheap::~yamg_hexheap()
|
||||
{
|
||||
//dtor
|
||||
delete table_;
|
||||
}
|
||||
|
||||
/**
|
||||
Add an hex to the heap
|
||||
Note this function sets the done flag of the hex. This not only prevent heap overflow, but helps in various cases: no hex can be inserted more than once.
|
||||
|
||||
-> ptr to the hex to add
|
||||
*/
|
||||
void yamg_hexheap::add_hex(yamg_hex *h) {
|
||||
|
||||
if((last_ >= max_) || (h->done)) // overflow shield
|
||||
return;
|
||||
|
||||
int i = last_++;
|
||||
|
||||
while(i > 0)
|
||||
{
|
||||
int j = i / 2; // searching father of this element
|
||||
if( table_[j]->key <= h->key)
|
||||
break; // insert is finished
|
||||
|
||||
table_[i] = table_[j];
|
||||
i = j;
|
||||
}
|
||||
table_[i] = h;
|
||||
h->done = true;
|
||||
}
|
||||
|
||||
/**
|
||||
Pick (and extract) first element from the heap
|
||||
|
||||
<- ptr on the element
|
||||
*/
|
||||
yamg_hex *yamg_hexheap::pick_hex() {
|
||||
yamg_hex *h, *res;
|
||||
|
||||
if( table_ == NULL || last_ == 0 )
|
||||
return NULL;
|
||||
|
||||
res = table_[0];
|
||||
|
||||
h = table_[--last_];
|
||||
int i = 0;
|
||||
int j = 1;
|
||||
int k;
|
||||
while( j < last_ ) {
|
||||
// select the correct son
|
||||
k = j + 1;
|
||||
if( (k < last_) && ( table_[j]->key > table_[k]->key) )
|
||||
j = k;
|
||||
if(h->key <= table_[j]->key) break;
|
||||
table_[i] = table_[j];
|
||||
i = j; j *= 2;
|
||||
}
|
||||
table_[i] = h;
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
Update all keys values
|
||||
(of course, this don't invalidate sort)
|
||||
-> the value to add
|
||||
*/
|
||||
void yamg_hexheap::update_hexes(int val) {
|
||||
|
||||
for(int i = 0; i < last_; i++)
|
||||
table_[i]->key += val;
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the first hex key value
|
||||
<- key member of the hex
|
||||
*/
|
||||
int yamg_hexheap::test_hex() {
|
||||
if(last_ > 0)
|
||||
return table_[0]->key;
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
Clear all members flag and reset the heap itself
|
||||
*/
|
||||
void yamg_hexheap::clear_heap() {
|
||||
for(int i = 0; i < last_; i++)
|
||||
table_[i]->done = false;
|
||||
last_ = 0;
|
||||
}
|
|
@ -1,53 +0,0 @@
|
|||
/*
|
||||
Copyright (C) 2013 - 2015 by L.Sebilleau <l.sebilleau@free.fr>
|
||||
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
/*
|
||||
Yet Another Map Generator. Class Hexheap
|
||||
|
||||
This class is an utility to sort dynamically hexes.
|
||||
Uses key member as sorting key (ascending).
|
||||
*/
|
||||
|
||||
#ifndef YAMG_HEXHEAP_HPP
|
||||
#define YAMG_HEXHEAP_HPP
|
||||
|
||||
#include "yamg_hex.hpp"
|
||||
#include <stddef.h>
|
||||
|
||||
|
||||
class yamg_hexheap
|
||||
{
|
||||
public:
|
||||
yamg_hexheap(size_t taille);
|
||||
virtual ~yamg_hexheap();
|
||||
|
||||
//*********** Members ************
|
||||
int last_; ///< an index on last record
|
||||
int max_; ///< memory limit index
|
||||
|
||||
//*********** Methods ************
|
||||
void add_hex(yamg_hex *h); ///< add an hex to the heap
|
||||
yamg_hex *pick_hex(); ///< get and remove first hex
|
||||
int test_hex(); ///< get key value of first hex
|
||||
void update_hexes(int val); ///< update all key values
|
||||
void clear_heap(); ///< clear the heap and reset all items 'done' flag in it.
|
||||
|
||||
protected:
|
||||
//*********** Members ************
|
||||
yamg_hex **table_; ///< holds the pointers table
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
#endif // YAMG_HEXHEAP_HPP
|
|
@ -1,479 +0,0 @@
|
|||
/*
|
||||
Copyright (C) 2013 - 2015 by L.Sebilleau <l.sebilleau@free.fr>
|
||||
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
/*
|
||||
Yet Another map generator
|
||||
Implementation file.
|
||||
*/
|
||||
|
||||
#ifdef YAMG_STANDALONE
|
||||
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#else
|
||||
|
||||
#include "global.hpp"
|
||||
|
||||
#endif
|
||||
|
||||
#include "yamg_params.hpp"
|
||||
|
||||
//yamg_params::yamg_params(config& /*cfg*/)
|
||||
//{
|
||||
// yamg_params::yamg_params();
|
||||
//}
|
||||
|
||||
|
||||
yamg_params::yamg_params()
|
||||
: seed(0)
|
||||
, width(65)
|
||||
, height(65)
|
||||
, rough(12)
|
||||
, type('t')
|
||||
, season('s')
|
||||
, snowlev(M_NUMLEVEL * 10)
|
||||
, water_ratio(100)
|
||||
, alt_mid(0)
|
||||
, alt_nw(0)
|
||||
, alt_ne(0)
|
||||
, alt_se(0)
|
||||
, alt_sw(0)
|
||||
, vill(10)
|
||||
, burgs(4)
|
||||
, forests(20)
|
||||
, players(0)
|
||||
, casthexes(6)
|
||||
, bridges(50)
|
||||
, roads(true)
|
||||
, ro_road(0)
|
||||
, thickness()
|
||||
, base_cust()
|
||||
, forest_cust()
|
||||
, houses_cust()
|
||||
, keeps_castles_cust()
|
||||
, hexes_castles_cust()
|
||||
, base_snow_cust()
|
||||
, roads_cust()
|
||||
, lilies_cust(NULL)
|
||||
, fields_cust(NULL)
|
||||
, bridges_cust(NULL)
|
||||
{
|
||||
//ctor set defaults values
|
||||
#ifdef YAMG_STANDALONE
|
||||
strcpy(path,"wesmap.map"); ///< pathname of the file
|
||||
#endif
|
||||
//TODO
|
||||
|
||||
thickness[YAMG_DEEPSEA] = 10; ///< layers thickness
|
||||
thickness[YAMG_SHALLSEA] = 10;
|
||||
thickness[YAMG_BEACH] = 5;
|
||||
thickness[YAMG_SWAMPS] = 5;
|
||||
thickness[YAMG_GROUND] = 35;
|
||||
thickness[YAMG_HILLS] = 15;
|
||||
thickness[YAMG_MOUNTAINS] = 15;
|
||||
thickness[YAMG_IMPMOUNTS] = 10;
|
||||
|
||||
int i;
|
||||
for(i=0; i < M_NUMLEVEL; i++)
|
||||
base_cust[i] = NULL;
|
||||
for(i=0; i < 12; i++)
|
||||
forest_cust[i] = NULL;
|
||||
for(i=0; i < 14; i++)
|
||||
houses_cust[i] = NULL;
|
||||
for(i=0; i < 10; i++)
|
||||
keeps_castles_cust[i] = NULL;
|
||||
for(i=0; i < 10; i++)
|
||||
hexes_castles_cust[i] = NULL;
|
||||
for(i=0; i < M_NUMLEVEL; i++)
|
||||
base_snow_cust[i] = NULL;
|
||||
for(i=0; i < 4; i++)
|
||||
roads_cust[i] = NULL;
|
||||
}
|
||||
|
||||
yamg_params::~yamg_params()
|
||||
{
|
||||
int i;
|
||||
for(i=0; i < M_NUMLEVEL; i++)
|
||||
if(base_cust[i] != NULL)
|
||||
delete base_cust[i];
|
||||
for(i=0; i < 12; i++)
|
||||
if(forest_cust[i] != NULL)
|
||||
delete forest_cust[i];
|
||||
for(i=0; i < 14; i++)
|
||||
if(houses_cust[i] != NULL)
|
||||
delete houses_cust[i];
|
||||
for(i=0; i < 10; i++)
|
||||
if(keeps_castles_cust[i] != NULL)
|
||||
delete keeps_castles_cust[i];
|
||||
for(i=0; i < 10; i++)
|
||||
if(hexes_castles_cust[i] != NULL)
|
||||
delete hexes_castles_cust[i];
|
||||
for(i=0; i < M_NUMLEVEL; i++)
|
||||
if(base_snow_cust[i] != NULL)
|
||||
delete base_snow_cust[i];
|
||||
for(i=0; i < 4; i++)
|
||||
if(roads_cust[i] != NULL)
|
||||
delete roads_cust[i];
|
||||
if(lilies_cust != NULL)
|
||||
delete lilies_cust;
|
||||
if(bridges_cust != NULL)
|
||||
delete bridges_cust;
|
||||
if(fields_cust != NULL)
|
||||
delete fields_cust;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Check parameters limits and consistency
|
||||
TODO: finish this
|
||||
*/
|
||||
unsigned int yamg_params::verify()
|
||||
{
|
||||
|
||||
unsigned int result = YAMG_OK;
|
||||
|
||||
if((width > YAMG_MAPMAXSIZE) || (height > YAMG_MAPMAXSIZE) )
|
||||
result |= YAMG_LIMITS;
|
||||
|
||||
if((rough > YAMG_ROUGHMAX) || (rough == 0))
|
||||
result |= YAMG_ROUGHOFF;
|
||||
|
||||
if(!find_in_string(YAMG_TYPES,type))
|
||||
result |= YAMG_BADTYPE;
|
||||
|
||||
if(!find_in_string(YAMG_SEASONS,season))
|
||||
result |= YAMG_BADSEASON;
|
||||
|
||||
//TODO this line causes a warning
|
||||
if((snowlev > ((M_NUMLEVEL+1) * 10))) // || (snowlev < 0))
|
||||
result |= YAMG_SNOW;
|
||||
|
||||
if((alt_mid > YAMG_ALTMAX) || (alt_mid < -YAMG_ALTMAX))
|
||||
result |= YAMG_ALTOFF;
|
||||
|
||||
if(vill > YAMG_VILLMAX)
|
||||
result |= YAMG_VILLOFF;
|
||||
|
||||
if(burgs > YAMG_BURGMAX)
|
||||
result |= YAMG_BURGOFF;
|
||||
|
||||
// if(towns > YAMG_TOWNSMAX)
|
||||
// result |= YAMG_TOWNSOFF;
|
||||
|
||||
if(forests > YAMG_FORESTMAX)
|
||||
result |= YAMG_FORESTOFF;
|
||||
|
||||
if(players > YAMG_PLAYERSMAX)
|
||||
result |= YAMG_PLAYERSOFF;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#ifdef YAMG_STANDALONE
|
||||
/**
|
||||
This part is needed only if parameters are read from a file
|
||||
*/
|
||||
const char *parmlist[] =
|
||||
{
|
||||
"mapname",
|
||||
"seed",
|
||||
"width",
|
||||
"height",
|
||||
"rough",
|
||||
"type",
|
||||
"season",
|
||||
"snowlevel",
|
||||
"altmiddle",
|
||||
"roads",
|
||||
"bridges",
|
||||
"castlesHexes",
|
||||
"villages",
|
||||
"burgs",
|
||||
"towns",
|
||||
"forests",
|
||||
"castles",
|
||||
"evaporation",
|
||||
"deepsea",
|
||||
"shallowsea",
|
||||
"beach",
|
||||
"swamps",
|
||||
"fields",
|
||||
"hills",
|
||||
"mountains",
|
||||
"peaks",
|
||||
"straightness",
|
||||
"altbases",
|
||||
"altforests",
|
||||
"althouses",
|
||||
"altkeeps",
|
||||
"altcastles",
|
||||
"altsnow",
|
||||
"altroads",
|
||||
"altlilies",
|
||||
"altfields",
|
||||
"altbridges",
|
||||
"altNW",
|
||||
"altNE",
|
||||
"altSE",
|
||||
"altSW",
|
||||
};
|
||||
|
||||
/**
|
||||
Storing custom terrain codes from parameters file
|
||||
*/
|
||||
void yamg_params::store_terrain_codes(const char *input, const char **table, unsigned int cnt)
|
||||
{
|
||||
unsigned int i,l,nt;
|
||||
const char *pt;
|
||||
char *w;
|
||||
|
||||
for(i = 0; i < cnt; i++)
|
||||
{
|
||||
pt = input;
|
||||
while((*pt != ',') && (*pt != '\0'))
|
||||
pt++;
|
||||
l = pt - input;
|
||||
if((l > 1) && (l <= 6))
|
||||
{
|
||||
table[i] = new char[10];
|
||||
for(nt = 0, w = (char *)table[i]; nt < l; nt++, w++, input++)
|
||||
{
|
||||
*w = *input;
|
||||
}
|
||||
*w = '\0';
|
||||
}
|
||||
if( *pt == '\0')
|
||||
return;
|
||||
else
|
||||
input = pt + 1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Read a parameter file
|
||||
-> path to file
|
||||
*/
|
||||
unsigned int yamg_params::read_params(const char *ficnom)
|
||||
{
|
||||
FILE *f;
|
||||
char buf[20000], instr[100], value[2048], *wr = NULL, *ptr, *end;
|
||||
int n,i;
|
||||
|
||||
f = fopen(ficnom,"r");
|
||||
if(f == NULL)
|
||||
return YAMG_FILENOTFOUND;
|
||||
|
||||
n = fread(buf,1,20000,f);
|
||||
ptr = buf;
|
||||
end = buf + n;
|
||||
n = 3;
|
||||
// ---- read loop ----
|
||||
while(ptr < end)
|
||||
{
|
||||
switch(n)
|
||||
{
|
||||
case 0:
|
||||
// catch parameter name.
|
||||
while( (*ptr != '=') && (*ptr != '#') && (ptr < end))
|
||||
*wr++ = *ptr++;
|
||||
if(*ptr == '#')
|
||||
n = 2; // skip the line
|
||||
else
|
||||
{
|
||||
*wr++ = '\0';
|
||||
wr = value;
|
||||
ptr++;
|
||||
n = 1;
|
||||
}
|
||||
break;
|
||||
|
||||
case 1:
|
||||
// get the value
|
||||
while( (!isspace(*ptr)) && (*ptr != '#') && (ptr < end))
|
||||
*wr++ = *ptr++;
|
||||
|
||||
*wr++ = '\0';
|
||||
for(i=0; i < 41; i++)
|
||||
{
|
||||
if(strcmp(instr,parmlist[i]) == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
switch(i)
|
||||
{
|
||||
case 0: // mapname
|
||||
strcpy(path,value);
|
||||
break;
|
||||
case 1:
|
||||
sscanf(value,"%u",&seed);
|
||||
break;
|
||||
case 2:
|
||||
sscanf(value,"%u",&width);
|
||||
break;
|
||||
case 3:
|
||||
sscanf(value,"%u",&height);
|
||||
break;
|
||||
case 4:
|
||||
sscanf(value,"%u",&rough);
|
||||
break;
|
||||
case 5:
|
||||
type = value[0];
|
||||
break;
|
||||
case 6:
|
||||
season = value[0];
|
||||
break;
|
||||
case 7:
|
||||
sscanf(value,"%u",&snowlev);
|
||||
snowlev -= 10;
|
||||
break;
|
||||
case 8:
|
||||
sscanf(value,"%i",&alt_mid);
|
||||
break;
|
||||
case 9:
|
||||
roads = ((*value == 'n') || (*value == 'N')) ? false:true;
|
||||
break;
|
||||
case 10:
|
||||
sscanf(value,"%i",&bridges);
|
||||
break;
|
||||
case 11:
|
||||
sscanf(value,"%u",&casthexes);
|
||||
break;
|
||||
case 12:
|
||||
sscanf(value,"%u",&vill);
|
||||
break;
|
||||
case 13:
|
||||
sscanf(value,"%u",&burgs);
|
||||
break;
|
||||
case 14:
|
||||
//sscanf(value,"%u",&towns);
|
||||
break;
|
||||
case 15:
|
||||
sscanf(value,"%u",&forests);
|
||||
break;
|
||||
case 16:
|
||||
sscanf(value,"%u",&players);
|
||||
break;
|
||||
case 17:
|
||||
sscanf(value,"%u",&water_ratio);
|
||||
break;
|
||||
case 18:
|
||||
sscanf(value,"%u",&thickness[0]);
|
||||
break;
|
||||
case 19:
|
||||
sscanf(value,"%u",&thickness[1]);
|
||||
break;
|
||||
case 20:
|
||||
sscanf(value,"%u",&thickness[2]);
|
||||
break;
|
||||
case 21:
|
||||
sscanf(value,"%u",&thickness[3]);
|
||||
break;
|
||||
case 22:
|
||||
sscanf(value,"%u",&thickness[4]);
|
||||
break;
|
||||
case 23:
|
||||
sscanf(value,"%u",&thickness[5]);
|
||||
break;
|
||||
case 24:
|
||||
sscanf(value,"%u",&thickness[6]);
|
||||
break;
|
||||
case 25:
|
||||
sscanf(value,"%u",&thickness[7]);
|
||||
break;
|
||||
case 26:
|
||||
sscanf(value,"%u",&ro_road);
|
||||
break;
|
||||
case 27:
|
||||
store_terrain_codes(value, base_cust, M_NUMLEVEL);
|
||||
break;
|
||||
case 28:
|
||||
store_terrain_codes(value, forest_cust, 12);
|
||||
break;
|
||||
case 29:
|
||||
store_terrain_codes(value, houses_cust, 14);
|
||||
break;
|
||||
case 30:
|
||||
store_terrain_codes(value, keeps_castles_cust, 10);
|
||||
break;
|
||||
case 31:
|
||||
store_terrain_codes(value, hexes_castles_cust, 10);
|
||||
break;
|
||||
case 32:
|
||||
store_terrain_codes(value, base_snow_cust, M_NUMLEVEL);
|
||||
break;
|
||||
case 33:
|
||||
store_terrain_codes(value, roads_cust, 4);
|
||||
break;
|
||||
case 34:
|
||||
lilies_cust = new char[10];
|
||||
strncpy(lilies_cust,value,5);
|
||||
break;
|
||||
case 35:
|
||||
fields_cust = new char[10];
|
||||
strncpy(fields_cust,value,5);
|
||||
break;
|
||||
case 36:
|
||||
bridges_cust = new char[10];
|
||||
strncpy(bridges_cust,value,5);
|
||||
break;
|
||||
case 37:
|
||||
sscanf(value,"%u",&alt_nw);
|
||||
break;
|
||||
case 38:
|
||||
sscanf(value,"%u",&alt_ne);
|
||||
break;
|
||||
case 39:
|
||||
sscanf(value,"%u",&alt_se);
|
||||
break;
|
||||
case 40:
|
||||
sscanf(value,"%u",&alt_sw);
|
||||
break;
|
||||
|
||||
default: // unknow parameter
|
||||
break;
|
||||
}
|
||||
|
||||
case 2:
|
||||
// go to end of line
|
||||
while( (*ptr != '\n') && (ptr < end))
|
||||
ptr++;
|
||||
ptr++;
|
||||
if((ptr >= end) || (*ptr == '\n'))
|
||||
break;
|
||||
// no break if we are only at the end of a line.
|
||||
case 3:
|
||||
wr = instr;
|
||||
n = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
fclose(f);
|
||||
return verify();
|
||||
}
|
||||
#endif
|
||||
|
||||
//----------------- Utils ----------------
|
||||
bool find_in_string(const char *str, char c)
|
||||
{
|
||||
const char *ptr = str;
|
||||
|
||||
while( *ptr != '\0')
|
||||
if(*ptr == c)
|
||||
return true;
|
||||
else
|
||||
ptr++;
|
||||
return false;
|
||||
}
|
|
@ -1,93 +0,0 @@
|
|||
/*
|
||||
Copyright (C) 2013 - 2015 by L.Sebilleau <l.sebilleau@free.fr>
|
||||
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
Yet Another Map Generator. Class YAMG_Params
|
||||
|
||||
This class groups generation parameters.
|
||||
It has mainly a constructor to initialize it and a checking method.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef YAMG_PARAMS_HPP
|
||||
#define YAMG_PARAMS_HPP
|
||||
|
||||
#include "yamg_decls.hpp"
|
||||
|
||||
|
||||
class yamg_params
|
||||
{
|
||||
public:
|
||||
|
||||
// yamg_params(config& cfg);
|
||||
yamg_params();
|
||||
~yamg_params();
|
||||
|
||||
#ifdef YAMG_STANDALONE
|
||||
char path[2048]; ///< dest filepath
|
||||
#endif
|
||||
unsigned int seed; ///< random seed
|
||||
unsigned int width; ///< map width
|
||||
unsigned int height; ///< map height
|
||||
unsigned int rough; ///< map roughness
|
||||
char type; ///< landscape type
|
||||
char season; ///< season to use
|
||||
unsigned int snowlev; ///< snow level
|
||||
unsigned int water_ratio; ///< water ratio
|
||||
int alt_mid; ///< map altitude center
|
||||
int alt_nw; ///< map altitude NW
|
||||
int alt_ne; ///< map altitude NE
|
||||
int alt_se; ///< map altitude SE
|
||||
int alt_sw; ///< map altitude SW
|
||||
|
||||
unsigned int vill; ///< number of isolated houses
|
||||
unsigned int burgs; ///< number of villages
|
||||
//unsigned int towns; ///< number of towns
|
||||
unsigned int forests; ///< forests rate of terrain
|
||||
unsigned int players; ///< number of players
|
||||
unsigned int casthexes; ///< number of hex in castles
|
||||
int bridges; ///< bridge creation cost
|
||||
bool roads; ///< roads generation
|
||||
unsigned int ro_road; ///< tune the paths windiness
|
||||
|
||||
int thickness[M_NUMLEVEL]; ///< layers thickness
|
||||
const char *base_cust[M_NUMLEVEL]; ///< custom terrains
|
||||
const char *forest_cust[12];
|
||||
const char *houses_cust[14];
|
||||
const char *keeps_castles_cust[10];
|
||||
const char *hexes_castles_cust[10];
|
||||
const char *base_snow_cust[M_NUMLEVEL];
|
||||
const char *roads_cust[4];
|
||||
char *lilies_cust;
|
||||
char *fields_cust;
|
||||
char *bridges_cust;
|
||||
|
||||
|
||||
unsigned int verify(); ///< verify parameters
|
||||
#ifdef YAMG_STANDALONE
|
||||
unsigned int read_params(const char *ficnom); ///< read the params file
|
||||
#endif
|
||||
|
||||
protected:
|
||||
#ifdef YAMG_STANDALONE
|
||||
void store_terrain_codes(const char *input, const char **table, unsigned int cnt); ///< read the terrain code parameters
|
||||
#endif
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
bool find_in_string(const char *str, char c);
|
||||
|
||||
#endif // YAMG_PARAMS_HPP
|
Loading…
Add table
Reference in a new issue