1 /* 2 C-Dogs SDL 3 A port of the legendary (and fun) action/arcade cdogs. 4 Copyright (c) 2018-2020 Cong Xu 5 All rights reserved. 6 7 Redistribution and use in source and binary forms, with or without 8 modification, are permitted provided that the following conditions are met: 9 10 Redistributions of source code must retain the above copyright notice, this 11 list of conditions and the following disclaimer. 12 Redistributions in binary form must reproduce the above copyright notice, 13 this list of conditions and the following disclaimer in the documentation 14 and/or other materials provided with the distribution. 15 16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 POSSIBILITY OF SUCH DAMAGE. 27 */ 28 #pragma once 29 30 #include <stdbool.h> 31 32 #include "c_hashmap/hashmap.h" 33 #include "pic_manager.h" 34 35 #define TILE_WIDTH 16 36 #define TILE_HEIGHT 12 37 #define TILE_SIZE svec2i(TILE_WIDTH, TILE_HEIGHT) 38 39 #define X_TILES ((gGraphicsDevice.cachedConfig.Res.x + TILE_WIDTH - 1) / TILE_WIDTH + 1) 40 41 #define X_TILES_HALF ((X_TILES + 1) / 2) 42 43 // + 1 because walls from bottom row show up one row above 44 #define Y_TILES ((gGraphicsDevice.cachedConfig.Res.y + TILE_HEIGHT - 1) / TILE_HEIGHT + 2) 45 #define Y_TILES_HALF ((Y_TILES + 1 / 2) 46 47 typedef enum 48 { 49 TILE_CLASS_FLOOR, 50 TILE_CLASS_WALL, 51 TILE_CLASS_DOOR, 52 TILE_CLASS_NOTHING, 53 TILE_CLASS_COUNT, 54 } TileClassType; 55 56 const char *TileClassTypeStr(const TileClassType t); 57 TileClassType StrTileClassType(const char *s); 58 59 typedef struct 60 { 61 char *Name; 62 const Pic *Pic; 63 char *Style; 64 char *StyleType; 65 color_t Mask; 66 color_t MaskAlt; 67 bool canWalk; // can walk on tile 68 bool isOpaque; // cannot see through 69 bool shootable; // blocks bullets 70 bool IsRoom; // affects random placement of indoor/outdoor map objects 71 TileClassType Type; 72 } TileClass; 73 74 typedef struct 75 { 76 map_t classes; // of TileClass * 77 map_t customClasses; // of TileClass * 78 } TileClasses; 79 extern TileClasses gTileClasses; 80 extern TileClass gTileFloor; 81 extern TileClass gTileRoom; 82 extern TileClass gTileWall; 83 extern TileClass gTileNothing; 84 extern TileClass gTileExit; 85 extern TileClass gTileDoor; 86 87 void TileClassesInit(TileClasses *c); 88 void TileClassesClearCustom(TileClasses *c); 89 void TileClassesTerminate(TileClasses *c); 90 void TileClassDestroy(any_t data); 91 void TileClassTerminate(TileClass *tc); 92 93 void TileClassInit( 94 TileClass *t, PicManager *pm, const TileClass *base, 95 const char *style, const char *type, 96 const color_t mask, const color_t maskAlt); 97 void TileClassInitDefault( 98 TileClass *t, PicManager *pm, const TileClass *base, 99 const char *forceStyle, const color_t *forceMask); 100 void TileClassReloadPic(TileClass *t, PicManager *pm); 101 const char *TileClassBaseStyleType(const TileClassType type); 102 void TileClassCopy(TileClass *dst, const TileClass *src); 103 const TileClass *StrTileClass(const char *name); 104 const TileClass *TileClassesGetMaskedTile( 105 const TileClass *baseClass, const char *style, const char *type, 106 const color_t mask, const color_t maskAlt); 107 TileClass *TileClassesAdd( 108 TileClasses *c, PicManager *pm, const TileClass *baseClass, 109 const char *style, const char *type, 110 const color_t mask, const color_t maskAlt); 111 const Pic *TileClassGetPic(const PicManager *pm, const TileClass *tc); 112 void TileClassGetName( 113 char *buf, const TileClass *base, const char *style, const char *type, 114 const color_t mask, const color_t maskAlt); 115 void TileClassGetBaseName(char *buf, const TileClass *tc); 116 const TileClass *TileClassesGetExit( 117 TileClasses *c, PicManager *pm, const char *style, const bool isShadow); 118