1 /* 2 XorGramana Copyright 2009 James W. Morris, james@jwm-art.net 3 4 This file is part of XorGramana. 5 6 XorGramana is free software: you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation, either version 3 of the License, or 9 (at your option) any later version. 10 11 XorGramana is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with XorGramana. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 #ifndef _ACTIONS_H 20 #define _ACTIONS_H 21 22 #include "types.h" 23 #include "icons.h" 24 /* 25 contact here means one object (in movement) attempting to 26 move onto another object - ie two objects are not in 27 contact when situated side by side. 28 */ 29 30 enum MOVES 31 { 32 /* movement directions */ 33 MV_NONE= 0x00, 34 MV_LEFT= 0x01, 35 MV_RIGHT= 0x02, 36 MV_UP= 0x04, 37 MV_DOWN= 0x08, 38 39 /* combos - happenings */ 40 MV_HORIZ= 0x03, 41 MV_VERT= 0x0c, 42 MV_ANY= 0x0f, /* ALL/ANY (direction (context)) */ 43 44 /* special extra-ordinary cases (not used by routines here) */ 45 MV_PLAYER_SWAP=0x10, 46 MV_PLAYER_QUIT=0x20 47 }; 48 49 enum MVINIT /* movement without contact */ 50 { 51 MVI_NONE= 0, /* does not move (but might be pushed) */ 52 MVI_PLAYER= 1, /* moved by player hitting cursor keys ;-) */ 53 MVI_GRAVITY= 2 /* moved by gravity (when path unblocked) */ 54 }; 55 56 enum CONTACT /* happenings initiated by contact */ 57 { 58 CT_BLOCK= 0x000, /* blocks movement in all directions */ 59 CT_PASS= 0x001, /* object does nothing (ie space) */ 60 CT_FILTER= 0x002, /* object filters movement */ 61 CT_PICKUP= 0x004, /* object is collected (player) */ 62 CT_PUSH= 0x008, /* object is pushed (player) */ 63 CT_FLIP= 0x010, /* object flips */ 64 CT_HARDPUSH= 0x020, /* object keeps moving (needs momentum) */ 65 CT_EXPLODE= 0x040, /* object explodes (non player contact) */ 66 CT_TELEPORT= 0x080, /* object teleports player */ 67 CT_SWITCH= 0x100, /* toggle wall visibility */ 68 CT_EXIT= 0x200, /* easy coded exit level if masks collected */ 69 CT_ERROR= 0x400 70 }; 71 72 struct xor_action 73 { 74 unsigned mvini : 4; 75 unsigned cont : 12; 76 unsigned mvi_dir : 4; 77 unsigned cont_dir : 4; 78 }; 79 80 struct xor_move /* one per object determined to have potential movement */ 81 { 82 xy_t from_x; 83 xy_t from_y; 84 su_t from_obj; 85 su_t dir; 86 xy_t to_x; 87 xy_t to_y; 88 su_t to_obj; 89 su_t moves_count; /* count of moves (gravitating objects only)*/ 90 /* links for chains of xor moves */ 91 struct xor_move* up; 92 struct xor_move* down; 93 struct xor_move* right; 94 struct xor_move* left; 95 }; 96 97 extern struct xor_action actions[ICON_XXX]; 98 99 /* perhaps icons_init_overlays should be in icons.h+icons.c, * 100 * but seeing as it requires the above array to be initialised * 101 * that is, what this func does depends on that array, it is * 102 * in here, so as to avoid premature calling (???) */ 103 104 void icons_init_overlays(); 105 106 /* 107 create_xor_move: 108 to move a known object in specified direction 109 */ 110 struct xor_move* create_xor_move(xy_t x, xy_t y, su_t move); 111 112 /* 113 these two functions create a chain of xor_moves where 114 the chain begins at map x,y and continues in the opposite 115 direction to dir, where each following xor_move holds the 116 same characteristics. the chain ends when an object in the 117 map is encountered which does not have the relevant 118 characteristics. returns the head of the chain or 0 if 119 no object with the relevant characteristics is found. 120 second form takes x,y,dir from the xor_move passed. 121 */ 122 struct xor_move* create_gravity_chain_xydir(xy_t x, xy_t y, su_t dir); 123 struct xor_move* create_gravity_chain(struct xor_move* xmv); 124 void destroy_gravity_chain(struct xor_move* xmv); 125 126 su_t bomb_type(su_t icon); 127 128 #endif 129