mirror of
https://github.com/cxong/cdogs-sdl.git
synced 2025-07-23 07:23:01 +02:00
Make drains regular map objects
Drains only required for classic maps
This commit is contained in:
@@ -973,6 +973,33 @@
|
||||
"Offset": [-8, -6],
|
||||
"Health": 0
|
||||
},
|
||||
{
|
||||
"Name": "drain0",
|
||||
"Pic": {
|
||||
"Type": "Normal",
|
||||
"Pic": "drain0"
|
||||
},
|
||||
"Offset": [-8, -6],
|
||||
"Health": 0
|
||||
},
|
||||
{
|
||||
"Name": "drain1",
|
||||
"Pic": {
|
||||
"Type": "Normal",
|
||||
"Pic": "drain1"
|
||||
},
|
||||
"Offset": [-8, -6],
|
||||
"Health": 0
|
||||
},
|
||||
{
|
||||
"Name": "drain2",
|
||||
"Pic": {
|
||||
"Type": "Normal",
|
||||
"Pic": "drain2"
|
||||
},
|
||||
"Offset": [-8, -6],
|
||||
"Health": 0
|
||||
},
|
||||
{
|
||||
"Name": "health spawner",
|
||||
"Pic": {
|
||||
|
Before Width: | Height: | Size: 175 B After Width: | Height: | Size: 175 B |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 294 B After Width: | Height: | Size: 294 B |
@@ -245,10 +245,6 @@ void MapChangeFloor(
|
||||
Tile *tAbove = MapGetTile(map, Vec2iNew(pos.x, pos.y - 1));
|
||||
int canSeeTileAbove = !(pos.y > 0 && !TileCanSee(tAbove));
|
||||
Tile *t = MapGetTile(map, pos);
|
||||
if (t->flags & MAPTILE_IS_DRAINAGE)
|
||||
{
|
||||
return;
|
||||
}
|
||||
switch (IMapGet(map, pos) & MAP_MASKACCESS)
|
||||
{
|
||||
case MAP_FLOOR:
|
||||
@@ -710,6 +706,25 @@ void MapLoad(
|
||||
MapSetupTilesAndWalls(map, mission);
|
||||
MapSetupDoors(map, mission);
|
||||
|
||||
if (mission->Type == MAPTYPE_CLASSIC)
|
||||
{
|
||||
// Randomly add drainage tiles for classic map type;
|
||||
// For other map types drains are regular map objects
|
||||
const MapObject *drain = StrMapObject("drain0");
|
||||
for (int i = 0; i < map->Size.x*map->Size.y / 45; i++)
|
||||
{
|
||||
// Make sure drain tiles aren't next to each other
|
||||
v = Vec2iNew(
|
||||
(rand() % map->Size.x) & 0xFFFFFE,
|
||||
(rand() % map->Size.y) & 0xFFFFFE);
|
||||
const Tile *t = MapGetTile(map, v);
|
||||
if (TileIsNormalFloor(t))
|
||||
{
|
||||
MapTryPlaceOneObject(map, v, drain, 0, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Set exit now since we have set up all the tiles
|
||||
if (Vec2iIsZero(map->ExitStart) && Vec2iIsZero(map->ExitEnd))
|
||||
{
|
||||
|
@@ -106,20 +106,6 @@ void MapSetupTilesAndWalls(Map *map, const Mission *m)
|
||||
}
|
||||
}
|
||||
|
||||
// Randomly change normal floor tiles to drainage tiles
|
||||
for (int i = 0; i < map->Size.x*map->Size.y / 45; i++)
|
||||
{
|
||||
// Make sure drain tiles aren't next to each other
|
||||
Tile *t = MapGetTile(map, Vec2iNew(
|
||||
(rand() % map->Size.x) & 0xFFFFFE,
|
||||
(rand() % map->Size.y) & 0xFFFFFE));
|
||||
if (TileIsNormalFloor(t))
|
||||
{
|
||||
TileSetAlternateFloor(t, PicManagerGetRandomDrain(&gPicManager));
|
||||
t->flags |= MAPTILE_IS_DRAINAGE;
|
||||
}
|
||||
}
|
||||
|
||||
// Randomly change normal floor tiles to alternative floor tiles
|
||||
for (int i = 0; i < map->Size.x*map->Size.y / 22; i++)
|
||||
{
|
||||
|
@@ -44,7 +44,6 @@ void PicManagerInit(PicManager *pm)
|
||||
pm->sprites = hashmap_new();
|
||||
pm->customPics = hashmap_new();
|
||||
pm->customSprites = hashmap_new();
|
||||
CArrayInit(&pm->drainPics, sizeof(NamedPic *));
|
||||
CArrayInit(&pm->wallStyleNames, sizeof(char *));
|
||||
CArrayInit(&pm->tileStyleNames, sizeof(char *));
|
||||
CArrayInit(&pm->exitStyleNames, sizeof(char *));
|
||||
@@ -266,7 +265,6 @@ void PicManagerLoad(PicManager *pm, const char *path)
|
||||
}
|
||||
|
||||
|
||||
static void FindDrainPics(PicManager *pm);
|
||||
static void FindStylePics(
|
||||
PicManager *pm, CArray *styleNames, PFany hashmapFunc);
|
||||
static int MaybeAddWallPicName(any_t data, any_t item);
|
||||
@@ -276,26 +274,12 @@ static int MaybeAddKeyPicName(any_t data, any_t item);
|
||||
static int MaybeAddDoorPicName(any_t data, any_t item);
|
||||
static void AfterAdd(PicManager *pm)
|
||||
{
|
||||
FindDrainPics(pm);
|
||||
FindStylePics(pm, &pm->wallStyleNames, MaybeAddWallPicName);
|
||||
FindStylePics(pm, &pm->tileStyleNames, MaybeAddTilePicName);
|
||||
FindStylePics(pm, &pm->exitStyleNames, MaybeAddExitPicName);
|
||||
FindStylePics(pm, &pm->doorStyleNames, MaybeAddDoorPicName);
|
||||
FindStylePics(pm, &pm->keyStyleNames, MaybeAddKeyPicName);
|
||||
}
|
||||
static void FindDrainPics(PicManager *pm)
|
||||
{
|
||||
// Scan all pics for drainage pics
|
||||
CArrayClear(&pm->drainPics);
|
||||
for (int i = 0;; i++)
|
||||
{
|
||||
char buf[CDOGS_FILENAME_MAX];
|
||||
sprintf(buf, "drains/%d", i);
|
||||
NamedPic *p = PicManagerGetNamedPic(pm, buf);
|
||||
if (p == NULL) break;
|
||||
CArrayPushBack(&pm->drainPics, &p);
|
||||
}
|
||||
}
|
||||
static int CompareStyleNames(const void *v1, const void *v2);
|
||||
static void FindStylePics(
|
||||
PicManager *pm, CArray *styleNames, PFany hashmapFunc)
|
||||
@@ -417,7 +401,6 @@ void PicManagerTerminate(PicManager *pm)
|
||||
hashmap_destroy(pm->sprites, NamedSpritesDestroy);
|
||||
hashmap_destroy(pm->customPics, NamedPicDestroy);
|
||||
hashmap_destroy(pm->customSprites, NamedSpritesDestroy);
|
||||
CArrayTerminate(&pm->drainPics);
|
||||
StylesTerminate(&pm->wallStyleNames);
|
||||
StylesTerminate(&pm->tileStyleNames);
|
||||
StylesTerminate(&pm->exitStyleNames);
|
||||
@@ -597,12 +580,6 @@ static NamedSprites *AddNamedSprites(map_t sprites, const char *name)
|
||||
return ns;
|
||||
}
|
||||
|
||||
NamedPic *PicManagerGetRandomDrain(PicManager *pm)
|
||||
{
|
||||
NamedPic **p = CArrayGet(&pm->drainPics, rand() % pm->drainPics.size);
|
||||
return *p;
|
||||
}
|
||||
|
||||
NamedPic *PicManagerGetExitPic(
|
||||
PicManager *pm, const char *style, const bool isShadow)
|
||||
{
|
||||
|
@@ -38,8 +38,6 @@ typedef struct
|
||||
map_t customPics; // of NamedPic
|
||||
map_t customSprites; // of NamedSprites
|
||||
|
||||
CArray drainPics; // of NamedPic *
|
||||
|
||||
CArray wallStyleNames; // of char *
|
||||
CArray tileStyleNames; // of char *
|
||||
CArray exitStyleNames; // of char *
|
||||
@@ -78,7 +76,6 @@ void PicManagerGenerateMaskedStylePic(
|
||||
PicManager *pm, const char *name, const char *style, const char *type,
|
||||
const color_t mask, const color_t maskAlt);
|
||||
|
||||
NamedPic *PicManagerGetRandomDrain(PicManager *pm);
|
||||
NamedPic *PicManagerGetExitPic(
|
||||
PicManager *pm, const char *style, const bool isShadow);
|
||||
int PicManagerGetWallStyleIndex(PicManager *pm, const char *style);
|
||||
|
@@ -92,15 +92,14 @@ bool TileCanWalk(const Tile *t)
|
||||
{
|
||||
return !(t->flags & MAPTILE_NO_WALK);
|
||||
}
|
||||
bool TileIsNormalFloor(Tile *t)
|
||||
bool TileIsNormalFloor(const Tile *t)
|
||||
{
|
||||
return t->flags & MAPTILE_IS_NORMAL_FLOOR;
|
||||
}
|
||||
bool TileIsClear(Tile *t)
|
||||
{
|
||||
// Check if tile is normal floor
|
||||
const int normalFloorFlags =
|
||||
MAPTILE_IS_NORMAL_FLOOR | MAPTILE_IS_DRAINAGE | MAPTILE_OFFSET_PIC;
|
||||
const int normalFloorFlags = MAPTILE_IS_NORMAL_FLOOR | MAPTILE_OFFSET_PIC;
|
||||
if (t->flags & ~normalFloorFlags) return false;
|
||||
// Check if tile has no things on it, excluding particles
|
||||
CA_FOREACH(const ThingId, tid, t->things)
|
||||
|
@@ -75,11 +75,10 @@ typedef enum
|
||||
MAPTILE_IS_WALL = 0x0008,
|
||||
MAPTILE_IS_NOTHING = 0x0010,
|
||||
MAPTILE_IS_NORMAL_FLOOR = 0x0020,
|
||||
MAPTILE_IS_DRAINAGE = 0x0040,
|
||||
MAPTILE_OFFSET_PIC = 0x0080,
|
||||
MAPTILE_OFFSET_PIC = 0x0040,
|
||||
// These constants are used internally in draw, it is never set in the map
|
||||
MAPTILE_DELAY_DRAW = 0x0100,
|
||||
MAPTILE_OUT_OF_SIGHT = 0x0200
|
||||
MAPTILE_DELAY_DRAW = 0x0080,
|
||||
MAPTILE_OUT_OF_SIGHT = 0x0100
|
||||
} MapTileFlags;
|
||||
|
||||
typedef enum
|
||||
@@ -155,7 +154,7 @@ void TileDestroy(Tile *t);
|
||||
bool IsTileItemInsideTile(TTileItem *i, Vec2i tilePos);
|
||||
bool TileCanSee(Tile *t);
|
||||
bool TileCanWalk(const Tile *t);
|
||||
bool TileIsNormalFloor(Tile *t);
|
||||
bool TileIsNormalFloor(const Tile *t);
|
||||
bool TileIsClear(Tile *t);
|
||||
bool TileHasCharacter(Tile *t);
|
||||
void TileSetAlternateFloor(Tile *t, NamedPic *p);
|
||||
|
Reference in New Issue
Block a user