1 /* 2 * ComboManager.h 3 * Daniel Nelson - 8/24/0 4 * 5 * Copyright (C) 2000 Daniel Nelson 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 20 * 21 * Daniel Nelson - aluminumangel.org 22 * 174 W. 18th Ave. 23 * Columbus, OH 43210 24 */ 25 26 #ifndef COMBOMANAGER_H 27 #define COMBOMANAGER_H 28 29 #include <cassert> 30 31 using namespace std; 32 33 #include "ComboTabulator.h" 34 #include "BlockManager.h" 35 #include "Block.h" 36 37 class Block; 38 39 /* static */ class ComboManager { 40 public: 41 static void gameStart ( ); 42 static void timeStep ( ); 43 newComboTabulator()44 static inline ComboTabulator &newComboTabulator ( ) 45 { 46 int id = findFreeId(); 47 allocateId(id); 48 ComboTabulator &combo = tabulatorStore[id]; 49 50 combo.initialize(); 51 return combo; 52 } 53 deleteComboTabulator(ComboTabulator & combo)54 static inline void deleteComboTabulator ( ComboTabulator &combo ) 55 { 56 freeId(combo.id); 57 } 58 specialBlockTally(ComboTabulator & combo,Block & block)59 static inline void specialBlockTally ( ComboTabulator &combo, Block &block ) 60 { 61 if (BlockManager::isBaseFlavor(block.flavor)) return; 62 combo.special[BlockManager::mapSpecialFlavorToCode(block.flavor)]++; 63 } 64 65 66 private: findFreeId()67 static inline int findFreeId ( ) 68 { 69 int n; 70 for (n = 0; storeMap[n]; n++); 71 return n; 72 } 73 allocateId(int id)74 static inline void allocateId ( int id ) 75 { 76 assert(!storeMap[id]); 77 storeMap[id] = true; 78 combo_count++; 79 } 80 freeId(int id)81 static inline void freeId ( int id ) 82 { 83 assert(storeMap[id]); 84 storeMap[id] = false; 85 combo_count--; 86 } 87 88 static ComboTabulator tabulatorStore[GC_COMBO_TABULATOR_STORE_SIZE]; 89 static bool storeMap[GC_COMBO_TABULATOR_STORE_SIZE]; 90 static int combo_count; 91 }; 92 93 #endif 94