1 /* Tower Toppler - Nebulus 2 * Copyright (C) 2000-2012 Andreas R�ver 3 * 4 * This program is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU General Public License 6 * as published by the Free Software Foundation; either version 2 7 * of the License, or (at your option) any later version. 8 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 */ 18 19 #ifndef LEVEL_H 20 #define LEVEL_H 21 22 #include <SDL_types.h> 23 24 /* handles one mission with towers and the necessary manipulations 25 on the towerlayout when the game is going on */ 26 27 /* tower blocks. 28 if you change these, also change towerblockdata[] in level.cc */ 29 typedef enum { 30 TB_EMPTY, 31 TB_STATION_TOP, 32 TB_STATION_MIDDLE, 33 TB_STATION_BOTTOM, 34 TB_ROBOT1, 35 TB_ROBOT2, 36 TB_ROBOT3, 37 TB_ROBOT4, 38 TB_ROBOT5, 39 TB_ROBOT6, 40 TB_ROBOT7, 41 TB_STICK, 42 TB_STEP, 43 TB_STEP_VANISHER, 44 TB_STEP_LSLIDER, 45 TB_STEP_RSLIDER, 46 TB_BOX, 47 TB_DOOR, 48 TB_DOOR_TARGET, 49 TB_STICK_TOP, 50 TB_STICK_MIDDLE, 51 TB_STICK_BOTTOM, 52 TB_ELEV_TOP, 53 TB_ELEV_MIDDLE, 54 TB_ELEV_BOTTOM, 55 TB_STICK_DOOR, 56 TB_STICK_DOOR_TARGET, 57 TB_ELEV_DOOR, 58 TB_ELEV_DOOR_TARGET, 59 NUM_TBLOCKS 60 } towerblock; 61 62 /* lev_is_consistent() returns one of these. 63 * If you add to these, also add to problemstr[] in leveledit.cc */ 64 65 typedef enum { 66 TPROB_NONE, // no problems found 67 TPROB_NOSTARTSTEP, // no starting step 68 TPROB_STARTBLOCKED, // starting position is blocked 69 TPROB_UNDEFBLOCK, // unknown block 70 TPROB_NOELEVATORSTOP, // elevator doesn't have stopping station(s) 71 TPROB_ELEVATORBLOCKED, // elevator is blocked 72 TPROB_NOOTHERDOOR, // door doesn't have opposing end 73 TPROB_BROKENDOOR, // door is not whole 74 TPROB_NOEXIT, // no exit doorway 75 TPROB_UNREACHABLEEXIT, // exit is unreachable 76 TPROB_SHORTTIME, // there's not enough time 77 TPROB_SHORTTOWER, // the tower is too short 78 TPROB_NONAME, // the tower has no name 79 NUM_TPROBLEMS, 80 } lev_problem; 81 82 /* tries to find all missions installed on this system 83 * returns the number of missions found 84 */ 85 void lev_findmissions(); 86 Uint16 lev_missionnumber(); 87 88 /* returns the name of the Nth mission */ 89 const char * lev_missionname(Uint16 num); 90 91 /* Convert a char into towerblock */ 92 Uint8 conv_char2towercode(wchar_t ch); 93 94 /* Get tower password. Note that the password changes when 95 the tower changes. */ 96 char *lev_get_passwd(void); 97 /* Do we show the tower password to user at the beginning 98 of current tower? */ 99 bool lev_show_passwd(int levnum); 100 /* Which tower does password allow entry to in the 101 current mission? */ 102 int lev_tower_passwd_entry(const char *passwd); 103 104 /* loads a mission from the file with the given name */ 105 bool lev_loadmission(Uint16 num); 106 107 /* free all the memory allocated by the mission and the mission list */ 108 void lev_done(); 109 110 /* clear the tower array */ 111 void lev_clear_tower(void); 112 113 /* returns the number of towers that are in the current mission */ 114 Uint8 lev_towercount(void); 115 116 /* selects one of the towers in this mission */ 117 void lev_selecttower(Uint8 number); 118 119 /* returns the color for the current tower */ 120 Uint8 lev_towercol_red(void); 121 Uint8 lev_towercol_green(void); 122 Uint8 lev_towercol_blue(void); 123 124 void lev_set_towercol(Uint8 r, Uint8 g, Uint8 b); 125 126 /* returns the value at this position in the level array */ 127 Uint8 lev_tower(Uint16 row, Uint8 column); 128 /* sets the value at this pos in the level array */ 129 Uint8 lev_set_tower(Uint16 row, Uint8 column, Uint8 block); 130 131 /* returns the height of the tower */ 132 Uint8 lev_towerrows(void); 133 134 /* the name of the tower */ 135 char *lev_towername(void); 136 void lev_set_towername(const char *str); 137 138 /* tower demo */ 139 void lev_set_towerdemo(int demolen, Uint16 *demobuf); 140 void lev_get_towerdemo(int &demolen, Uint16 *&demobuf); 141 142 /* the number of the actual tower */ 143 Uint8 lev_towernr(void); 144 145 /* returns true, if current tower is the last one */ 146 bool lev_lasttower(void); 147 148 /* the number of the robot used */ 149 Uint8 lev_robotnr(void); 150 void lev_set_robotnr(Uint8 robot); 151 152 /* the time the player has to reach the top */ 153 Uint16 lev_towertime(void); 154 155 void lev_set_towertime(Uint16 time); 156 157 /* removes one layer of the tower (for destruction) */ 158 void lev_removelayer(Uint8 layer); 159 160 /* if the positions contains a vanishing step, remove it */ 161 void lev_removevanishstep(int row, int col); 162 163 // returns true if the given position contains an upper end of a door 164 bool lev_is_door_upperend(int row, int col); 165 166 // returns true, if the given positions contains a level of a door 167 bool lev_is_door(int row, int col); 168 169 // returns true, if block in tower pos is a robot 170 bool lev_is_robot(int row, int col); 171 172 // returns true, if the given coordinates contains a layer of a target door 173 bool lev_is_targetdoor(int row, int col); 174 175 /* all for the elevators */ 176 177 /* completely empty */ 178 bool lev_is_empty(int row, int col); 179 180 /* contains a flashing box */ 181 bool lev_is_box(int row, int col); 182 183 /* empty this field */ 184 void lev_clear(int row, int col); 185 186 /* a station (not necessary with a platform */ 187 bool lev_is_station(int row, int col); 188 bool lev_is_up_station(int row, int col); 189 bool lev_is_down_station(int row, int col); 190 bool lev_is_bottom_station(int row, int col); 191 192 /* contains a platform */ 193 bool lev_is_platform(int row, int col); 194 195 /* contains stick */ 196 bool lev_is_stick(int row, int col); 197 198 /* is part of an elevator */ 199 bool lev_is_elevator(int row, int col); 200 201 /* sliding step 202 returns: 0 = no sliding, 1 = sliding right, -1 = sliding left */ 203 int lev_is_sliding(int row, int col); 204 205 /* start and stop elevator */ 206 void lev_platform2stick(int row, int col); 207 void lev_stick2platform(int row, int col); 208 209 /* move up and down */ 210 void lev_stick2empty(int row, int col); 211 void lev_empty2stick(int row, int col); 212 void lev_platform2empty(int row, int col); 213 214 /* checks the given figure for validity of its position (can 215 it be there without colliding ?) */ 216 bool lev_testfigure(long angle, long vert, long back, 217 long fore, long typ, long height, long width); 218 219 220 /* used for the elevator */ 221 unsigned char lev_putplatform(int row, int col); 222 void lev_restore(int row, int col, unsigned char bg); 223 224 /* --- the following commands are for the level editor --- */ 225 226 /* load and save a tower in a human readable format */ 227 bool lev_loadtower(const char *fname); 228 bool lev_savetower(const char *fname); 229 230 /* rotate row clock and counter clockwise */ 231 void lev_rotaterow(int row, bool clockwise); 232 233 234 /* insert and delete one row */ 235 void lev_insertrow(int position); 236 void lev_deleterow(int position); 237 238 /* creates a simple tower consisting of 'hei' rows */ 239 void lev_new(Uint8 hei); 240 241 /* functions to change one field on the tower */ 242 void lev_putspace(int row, int col); 243 void lev_putrobot1(int row, int col); 244 void lev_putrobot2(int row, int col); 245 void lev_putrobot3(int row, int col); 246 void lev_putrobot4(int row, int col); 247 void lev_putrobot5(int row, int col); 248 void lev_putrobot6(int row, int col); 249 void lev_putrobot7(int row, int col); 250 void lev_putrobot8(int row, int col); 251 void lev_putstep(int row, int col); 252 void lev_putvanishingstep(int row, int col); 253 void lev_putslidingstep_left(int row, int col); 254 void lev_putslidingstep_right(int row, int col); 255 void lev_putdoor(int row, int col); 256 void lev_puttarget(int row, int col); 257 void lev_putstick(int row, int col); 258 void lev_putbox(int row, int col); 259 void lev_putelevator(int row, int col); 260 void lev_putmiddlestation(int row, int col); 261 void lev_puttopstation(int row, int col); 262 263 /* creates a copy of the current tower, the functions 264 * allocate the necessary RAM and the restore function 265 * frees the RAM again 266 */ 267 void lev_save(unsigned char *&data); 268 void lev_restore(unsigned char *&data); 269 270 /* check the tower for consistency. This function checks doors 271 * and elevators, and if something is found, row and col contain the 272 * coordinates, and the return value is one of TPROB_xxx 273 */ 274 lev_problem lev_is_consistent(int &row, int &col); 275 276 /* mission creation: first call mission_new(), then 277 * for each tower mission_addtower() and finally to complete 278 * the mission mission_finish(). never use another calling order 279 * or you may create corrupted mission files. 280 */ 281 bool lev_mission_new(char * name, Uint8 prio = 255); 282 void lev_mission_addtower(char * name); 283 void lev_mission_finish(); 284 285 #endif 286