Cleaned up code, fixed some overlapping gold mines

This commit is contained in:
jsalmon3 2002-12-05 05:11:06 +00:00
parent 05e9924140
commit 0743f8de29
2 changed files with 118 additions and 76 deletions
src
editor
include

View file

@ -576,10 +576,12 @@ global void EditorTileChanged(int x, int y)
** TileFill( centerx, centery, tile_type_water, map_width )
** will fill map with water...
*/
global void TileFill(int x, int y, int tile, int size)
local void TileFill(int x, int y, int tile, int size)
{
int ix, ax;
int iy, ay;
int ix;
int ax;
int iy;
int ay;
ix = x - size / 2;
@ -587,14 +589,24 @@ global void TileFill(int x, int y, int tile, int size)
iy = y - size / 2;
ay = y + size / 2;
if ( ix < 0 ) ix = 0;
if ( ax >= TheMap.Width ) ax = TheMap.Width - 1;
if ( iy < 0 ) iy = 0;
if ( ay >= TheMap.Height ) ay = TheMap.Height - 1;
if ( ix < 0 ) {
ix = 0;
}
if ( ax >= TheMap.Width ) {
ax = TheMap.Width - 1;
}
if ( iy < 0 ) {
iy = 0;
}
if ( ay >= TheMap.Height ) {
ay = TheMap.Height - 1;
}
for( x = ix; x <= ax; x++ )
for( y = iy; y <= ay; y++ )
EditorChangeTile( x, y, tile, 15 );
for( x = ix; x <= ax; x++ ) {
for( y = iy; y <= ay; y++ ) {
EditorChangeTile( x, y, tile, 15 );
}
}
}
#define WATER_TILE 0x10
@ -603,90 +615,120 @@ global void TileFill(int x, int y, int tile, int size)
#define WOOD_TILE 0x70
#define ROCK_TILE 0x80
global void EditorRandomizeTile( int tile, int count, int max_size )
/**
** FIXME: docu
*/
local void EditorRandomizeTile( int tile, int count, int max_size )
{
int mx = TheMap.Width;
int my = TheMap.Height;
int i;
for( i = 0; i < count; i++ )
{
int rx = rand() % (mx / 2);
int ry = rand() % (my / 2);
int rz = rand() % max_size + 1;
TileFill( rx, ry, tile, rz );
TileFill( mx - rx - 1, ry, tile, rz );
TileFill( rx, my - ry - 1, tile, rz );
TileFill( mx - rx - 1, mx - ry - 1, tile, rz );
}
int mx;
int my;
int i;
int rx;
int ry;
int rz;
mx = TheMap.Width;
my = TheMap.Height;
for( i = 0; i < count; i++ ) {
rx = rand() % (mx / 2);
ry = rand() % (my / 2);
rz = rand() % max_size + 1;
TileFill( rx, ry, tile, rz );
TileFill( mx - rx - 1, ry, tile, rz );
TileFill( rx, my - ry - 1, tile, rz );
TileFill( mx - rx - 1, mx - ry - 1, tile, rz );
}
}
global void EditorRandomizeUnit( const char *unit_type, int count, int value )
/**
** FIXME: docu
*/
local void EditorRandomizeUnit( const char *unit_type, int count, int value )
{
int mx = TheMap.Width;
int my = TheMap.Height;
int i;
UnitType* type = UnitTypeByIdent(unit_type);
for( i = 0; i < count; i++ )
{
int mx;
int my;
int i;
int rx;
int ry;
int tile;
int z;
int tw;
int th;
UnitType* type;
Unit *unit;
int rx = rand() % (mx / 2);
int ry = rand() % (my / 2);
int tile = GRASS_TILE;
int z = type->TileHeight;
//FIXME: vladi: the idea is simple: make proper land for unit(s) :)
TileFill( rx, ry, tile, z*2 );
TileFill( mx - rx - 1, ry, tile, z*2 );
TileFill( rx, my - ry - 1, tile, z*2 );
TileFill( mx - rx - 1, mx - ry - 1, tile, z*2 );
unit=MakeUnitAndPlace( rx, ry , type, &Players[15]);
unit->Value=value;
unit=MakeUnitAndPlace( mx - rx - 1, ry, type, &Players[15]);
unit->Value=value;
unit=MakeUnitAndPlace( rx, my - ry - 1, type, &Players[15]);
unit->Value=value;
unit=MakeUnitAndPlace( mx - rx - 1, mx - ry - 1, type, &Players[15]);
unit->Value=value;
}
mx = TheMap.Width;
my = TheMap.Height;
type = UnitTypeByIdent(unit_type);
tw = type->TileWidth;
th = type->TileHeight;
for( i = 0; i < count; i++ ) {
rx = rand() % (mx / 2 - tw + 1);
ry = rand() % (my / 2 - th + 1);
tile = GRASS_TILE;
z = type->TileHeight;
// FIXME: vladi: the idea is simple: make proper land for unit(s) :)
// FIXME: handle units larger than 1 square
TileFill( rx, ry, tile, z*2 );
TileFill( mx - rx - 1, ry, tile, z*2 );
TileFill( rx, my - ry - 1, tile, z*2 );
TileFill( mx - rx - 1, mx - ry - 1, tile, z*2 );
// FIXME: can overlap units
unit=MakeUnitAndPlace( rx, ry , type, &Players[15]);
unit->Value=value;
unit=MakeUnitAndPlace( mx - rx - tw, ry, type, &Players[15]);
unit->Value=value;
unit=MakeUnitAndPlace( rx, my - ry - th, type, &Players[15]);
unit->Value=value;
unit=MakeUnitAndPlace( mx - rx - tw, mx - ry - th, type, &Players[15]);
unit->Value=value;
}
}
/**
** Destroy all units
*/
global void EditorDestroyAllUnits()
local void EditorDestroyAllUnits(void)
{
int i;
for( i = 0; i < NumUnits; i++)
{
Unit* unit=Units[i];
RemoveUnit( unit );
UnitLost( unit );
UnitClearOrders( unit );
ReleaseUnit( unit );
Unit* unit;
for( i = 0; i < NumUnits; i++) {
unit=Units[i];
RemoveUnit( unit );
UnitLost( unit );
UnitClearOrders( unit );
ReleaseUnit( unit );
}
}
global void EditorCreateRandomMap()
/**
** FIXME: docu
**
** FIXME: If called more than once the old mines should be removed
*/
global void EditorCreateRandomMap(void)
{
int mz = TheMap.Width > TheMap.Height ? TheMap.Width : TheMap.Height;
// make water-base
TileFill( 0, 0, WATER_TILE, mz * 3 );
// remove all units
EditorDestroyAllUnits();
EditorRandomizeTile( COAST_TILE, 10, 16 );
EditorRandomizeTile( GRASS_TILE, 20, 16 );
EditorRandomizeTile( WOOD_TILE, 60, 4 );
EditorRandomizeTile( ROCK_TILE, 30, 2 );
int mz;
mz = TheMap.Width > TheMap.Height ? TheMap.Width : TheMap.Height;
EditorRandomizeUnit( "unit-gold-mine", 5, 50000 );
// make water-base
TileFill( 0, 0, WATER_TILE, mz * 3 );
// remove all units
EditorDestroyAllUnits();
EditorRandomizeTile( COAST_TILE, 10, 16 );
EditorRandomizeTile( GRASS_TILE, 20, 16 );
EditorRandomizeTile( WOOD_TILE, 60, 4 );
EditorRandomizeTile( ROCK_TILE, 30, 2 );
EditorRandomizeUnit( "unit-gold-mine", 5, 50000 );
}
//@}

View file

@ -72,7 +72,7 @@ extern void ChangeTile(int x, int y, int tile);
/// Update surroundings for tile changes
extern void EditorTileChanged(int x, int y);
/// Make random map
extern void EditorCreateRandomMap();
extern void EditorCreateRandomMap(void);
//@}