1 //************************************************************************** 2 //** 3 //** ## ## ## ## ## #### #### ### ### 4 //** ## ## ## ## ## ## ## ## ## ## #### #### 5 //** ## ## ## ## ## ## ## ## ## ## ## ## ## ## 6 //** ## ## ######## ## ## ## ## ## ## ## ### ## 7 //** ### ## ## ### ## ## ## ## ## ## 8 //** # ## ## # #### #### ## ## 9 //** 10 //** $Id: lockdefs.cpp 4297 2010-06-03 22:49:00Z firebrand_kh $ 11 //** 12 //** Copyright (C) 1999-2006 Jānis Legzdiņš 13 //** 14 //** This program is free software; you can redistribute it and/or 15 //** modify it under the terms of the GNU General Public License 16 //** as published by the Free Software Foundation; either version 2 17 //** of the License, or (at your option) any later version. 18 //** 19 //** This program is distributed in the hope that it will be useful, 20 //** but WITHOUT ANY WARRANTY; without even the implied warranty of 21 //** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 //** GNU General Public License for more details. 23 //** 24 //************************************************************************** 25 26 // HEADER FILES ------------------------------------------------------------ 27 28 #include "gamedefs.h" 29 30 // MACROS ------------------------------------------------------------------ 31 32 // TYPES ------------------------------------------------------------------- 33 34 // EXTERNAL FUNCTION PROTOTYPES -------------------------------------------- 35 36 // PUBLIC FUNCTION PROTOTYPES ---------------------------------------------- 37 38 // PRIVATE FUNCTION PROTOTYPES --------------------------------------------- 39 40 // EXTERNAL DATA DECLARATIONS ---------------------------------------------- 41 42 // PUBLIC DATA DEFINITIONS ------------------------------------------------- 43 44 // PRIVATE DATA DEFINITIONS ------------------------------------------------ 45 46 static VLockDef* LockDefs[256]; 47 48 // CODE -------------------------------------------------------------------- 49 50 //========================================================================== 51 // 52 // ParseLockDefs 53 // 54 //========================================================================== 55 ParseLockDefs(VScriptParser * sc)56static void ParseLockDefs(VScriptParser* sc) 57 { 58 guard(ParseLockDefs); 59 while (!sc->AtEnd()) 60 { 61 if (sc->Check("ClearLocks")) 62 { 63 for (int i = 0; i < 256; i++) 64 { 65 if (LockDefs[i]) 66 { 67 delete LockDefs[i]; 68 LockDefs[i] = NULL; 69 } 70 } 71 } 72 else if (sc->Check("Lock")) 73 { 74 // Lock number 75 sc->ExpectNumber(); 76 int Lock = sc->Number; 77 if (Lock <= 0 || Lock >= 255) 78 { 79 sc->Error("Bad lock number"); 80 } 81 if (LockDefs[Lock]) 82 { 83 delete LockDefs[Lock]; 84 LockDefs[Lock] = NULL; 85 } 86 VLockDef* LDef = new VLockDef; 87 LockDefs[Lock] = LDef; 88 LDef->MapColour = 0; 89 LDef->LockedSound = "misc/keytry"; 90 91 // Skip game specifier 92 sc->Check("Doom") || sc->Check("Heretic") || 93 sc->Check("Hexen") || sc->Check("Strife"); 94 95 sc->Expect("{"); 96 while (!sc->Check("}")) 97 { 98 if (sc->Check("Message")) 99 { 100 sc->ExpectString(); 101 LDef->Message = sc->String; 102 } 103 else if (sc->Check("RemoteMessage")) 104 { 105 sc->ExpectString(); 106 LDef->RemoteMessage = sc->String; 107 } 108 else if (sc->Check("MapColor")) 109 { 110 sc->ExpectNumber(); 111 int r = sc->Number; 112 sc->ExpectNumber(); 113 int g = sc->Number; 114 sc->ExpectNumber(); 115 int b = sc->Number; 116 LDef->MapColour = 0xff000000 | (r << 16) | (g << 8) | b; 117 } 118 else if (sc->Check("LockedSound")) 119 { 120 sc->ExpectString(); 121 LDef->LockedSound = *sc->String; 122 } 123 else if (sc->Check("Any")) 124 { 125 sc->Expect("{"); 126 VLockGroup& Grp = LDef->Locks.Alloc(); 127 while (!sc->Check("}")) 128 { 129 sc->ExpectString(); 130 VClass* Cls = VClass::FindClass(*sc->String); 131 if (!Cls) 132 { 133 GCon->Logf("No such class %s", *sc->String); 134 } 135 else 136 { 137 Grp.AnyKeyList.Append(Cls); 138 } 139 } 140 } 141 else 142 { 143 sc->ExpectString(); 144 VClass* Cls = VClass::FindClass(*sc->String); 145 if (!Cls) 146 { 147 GCon->Logf("No such class %s", *sc->String); 148 } 149 else 150 { 151 LDef->Locks.Alloc().AnyKeyList.Append(Cls); 152 } 153 } 154 } 155 // Copy message if other one is not defined 156 if (LDef->Message.IsEmpty()) 157 { 158 LDef->Message = LDef->RemoteMessage; 159 } 160 if (LDef->RemoteMessage.IsEmpty()) 161 { 162 LDef->RemoteMessage = LDef->Message; 163 } 164 } 165 else 166 { 167 sc->Error("Bad syntax"); 168 } 169 } 170 delete sc; 171 sc = NULL; 172 unguard; 173 } 174 175 //========================================================================== 176 // 177 // InitLockDefs 178 // 179 //========================================================================== 180 InitLockDefs()181void InitLockDefs() 182 { 183 guard(InitLockDefs); 184 for (int Lump = W_IterateNS(-1, WADNS_Global); Lump >= 0; 185 Lump = W_IterateNS(Lump, WADNS_Global)) 186 { 187 if (W_LumpName(Lump) == NAME_lockdefs) 188 { 189 ParseLockDefs(new VScriptParser(*W_LumpName(Lump), 190 W_CreateLumpReaderNum(Lump))); 191 } 192 } 193 unguard; 194 } 195 196 //========================================================================== 197 // 198 // ShutdownLockDefs 199 // 200 //========================================================================== 201 ShutdownLockDefs()202void ShutdownLockDefs() 203 { 204 guard(ShutdownLockDefs); 205 for (int i = 0; i < 256; i++) 206 { 207 if (LockDefs[i]) 208 { 209 delete LockDefs[i]; 210 LockDefs[i] = NULL; 211 } 212 } 213 unguard; 214 } 215 216 //========================================================================== 217 // 218 // GetLockDef 219 // 220 //========================================================================== 221 GetLockDef(int Lock)222VLockDef* GetLockDef(int Lock) 223 { 224 guard(GetLockDef); 225 return Lock < 0 || Lock > 255 ? NULL : LockDefs[Lock]; 226 unguard; 227 } 228