mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-15 17:02:05 +00:00
e5572a1c4e
- Added .txt files to the list of types (wad, zip, and pk3) that can be loaded without listing them after -file. - Fonts that are created by the ACS setfont command to wrap a texture now support animated textures. - FON2 fonts can now use their full palette for CR_UNTRANSLATED when drawn with the hardware 2D path instead of being restricted to the game palette. - Fixed: Toggling vid_vsync would reset the displayed fullscreen gamma to 1 on a Radeon 9000. - Added back the off-by-one palette handling, but in a much more limited scope than before. The skipped entry is assumed to always be at 248, and it is assumed that all Shader Model 1.4 cards suffer from this. That's because all SM1.4 cards are based on variants of the ATI R200 core, and the RV250 in a Radeon 9000 craps up like this. I see no reason to assume that other flavors of the R200 are any different. (Interesting note: With the Radeon 9000, D3DTADDRESS_CLAMP is an invalid address mode when using the debug Direct3D 9 runtime, but it works perfectly fine with the retail Direct3D 9 runtime.) (Insight: The R200 probably uses bytes for all its math inside pixel shaders. That would explain perfectly why I can't use constants greater than 1 with PS1.4 and why it can't do an exact mapping to every entry in the color palette. - Fixed: The software shaded drawer did not work for 2D, because its selected "color"map was replaced with the identitymap before being used. - Fixed: I cannot use Printf to output messages before the framebuffer was completely setup, meaning that Shader Model 1.4 cards could not change resolution. - I have decided to let remap palettes specify variable alpha values for their colors. D3DFB no longer forces them to 255. - Updated re2c to version 0.12.3. - Fixed: A_Wander used threshold as a timer, when it should have used reactiontime. - Fixed: A_CustomRailgun would not fire at all for actors without a target when the aim parameter was disabled. - Made the warp command work in multiplayer, again courtesy of Karate Chris. - Fixed: Trying to spawn a bot while not in a game made for a crashing time. (Patch courtesy of Karate Chris.) - Removed some floating point math from hu_scores.cpp that somebody's GCC gave warnings for (not mine, though). - Fixed: The SBarInfo drawbar command crashed if the sprite image was unavailable. - Fixed: FString::operator=(const char *) did not release its old buffer when being assigned to the null string. - The scanner no longer has an upper limit on the length of strings it accepts, though short strings will be faster than long ones. - Moved all the text scanning functions into a class. Mainly, this means that multiple script scanner states can be stored without being forced to do so recursively. I think I might be taking advantage of that in the near future. Possibly. Maybe. - Removed some potential buffer overflows from the decal parser. - Applied Blzut3's SBARINFO update #9: * Fixed: When using even length values in drawnumber it would cap to a 98 value instead of a 99 as intended. * The SBarInfo parser can now accept negatives for coordinates. This doesn't allow much right now, but later I plan to add better fullscreen hud support in which the negatives will be more useful. This also cleans up the source a bit since all calls for (x, y) coordinates are with the function getCoordinates(). - Added support for stencilling actors. - Added support for non-black colors specified with DTA_ColorOverlay to the software renderer. - Fixed: The inverse, gold, red, and green fixed colormaps each allocated space for 32 different colormaps, even though each only used the first one. - Added two new blending flags to make reverse subtract blending more useful: STYLEF_InvertSource and STYLEF_InvertOverlay. These invert the color that gets blended with the background, since that seems like a good idea for reverse subtraction. They also work with the other two blending operations. - Added subtract and reverse subtract blending operations to the renderer. Since the ERenderStyle enumeration was getting rather unwieldy, I converted it into a new FRenderStyle structure that lets each parameter of the blending equation be set separately. This simplified the set up for the blend quite a bit, and it means a number of new combinations are available by setting the parameters properly. SVN r710 (trunk)
496 lines
10 KiB
C++
496 lines
10 KiB
C++
#include "a_keys.h"
|
|
#include "tarray.h"
|
|
#include "gi.h"
|
|
#include "gstrings.h"
|
|
#include "d_player.h"
|
|
#include "c_console.h"
|
|
#include "s_sound.h"
|
|
#include "sc_man.h"
|
|
#include "v_palette.h"
|
|
#include "w_wad.h"
|
|
|
|
|
|
|
|
struct OneKey
|
|
{
|
|
const PClass * key;
|
|
int count;
|
|
|
|
bool check(AActor * owner)
|
|
{
|
|
return !!owner->FindInventory(key);
|
|
}
|
|
};
|
|
|
|
struct Keygroup
|
|
{
|
|
TArray<OneKey> anykeylist;
|
|
|
|
bool check(AActor * owner)
|
|
{
|
|
for(unsigned int i=0;i<anykeylist.Size();i++)
|
|
{
|
|
if (anykeylist[i].check(owner)) return true;
|
|
}
|
|
return false;
|
|
}
|
|
};
|
|
|
|
struct Lock
|
|
{
|
|
TArray<Keygroup *> keylist;
|
|
char * message;
|
|
char * remotemsg;
|
|
int locksound;
|
|
int rgb;
|
|
|
|
Lock()
|
|
{
|
|
message=remotemsg=NULL;
|
|
rgb=0;
|
|
}
|
|
|
|
~Lock()
|
|
{
|
|
for(unsigned int i=0;i<keylist.Size();i++) delete keylist[i];
|
|
keylist.Clear();
|
|
if (message) delete [] message;
|
|
if (remotemsg) delete [] remotemsg;
|
|
}
|
|
|
|
bool check(AActor * owner)
|
|
{
|
|
// An empty key list means that any key will do
|
|
if (!keylist.Size())
|
|
{
|
|
for (AInventory * item = owner->Inventory; item != NULL; item = item->Inventory)
|
|
{
|
|
if (item->IsKindOf (RUNTIME_CLASS(AKey)))
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
else for(unsigned int i=0;i<keylist.Size();i++)
|
|
{
|
|
if (!keylist[i]->check(owner)) return false;
|
|
}
|
|
return true;
|
|
}
|
|
};
|
|
|
|
|
|
static Lock * locks[256]; // all valid locks
|
|
static bool keysdone=false; // have the locks been initialized?
|
|
static int currentnumber; // number to be assigned to next key
|
|
static bool ignorekey; // set to true when the current lock is not being used
|
|
|
|
static void ClearLocks();
|
|
|
|
static const char * keywords_lock[]={
|
|
"ANY",
|
|
"MESSAGE",
|
|
"REMOTEMESSAGE",
|
|
"MAPCOLOR",
|
|
"LOCKEDSOUND",
|
|
NULL
|
|
};
|
|
|
|
//===========================================================================
|
|
//
|
|
//
|
|
//===========================================================================
|
|
|
|
static void AddOneKey(Keygroup *keygroup, const PClass *mi, FScanner &sc)
|
|
{
|
|
if (mi)
|
|
{
|
|
// Any inventory item can be used to unlock a door
|
|
if (mi->IsDescendantOf(RUNTIME_CLASS(AInventory)))
|
|
{
|
|
OneKey k = {mi,1};
|
|
keygroup->anykeylist.Push (k);
|
|
|
|
//... but only keys get key numbers!
|
|
if (mi->IsDescendantOf(RUNTIME_CLASS(AKey)))
|
|
{
|
|
if (!ignorekey &&
|
|
static_cast<AKey*>(GetDefaultByType(mi))->KeyNumber == 0)
|
|
{
|
|
static_cast<AKey*>(GetDefaultByType(mi))->KeyNumber=++currentnumber;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
sc.ScriptError("'%s' is not an inventory item", sc.String);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
sc.ScriptError("Unknown item '%s'", sc.String);
|
|
}
|
|
}
|
|
|
|
|
|
//===========================================================================
|
|
//
|
|
//
|
|
//===========================================================================
|
|
|
|
static Keygroup * ParseKeygroup(FScanner &sc)
|
|
{
|
|
Keygroup * keygroup;
|
|
const PClass * mi;
|
|
|
|
sc.MustGetStringName("{");
|
|
keygroup = new Keygroup;
|
|
while (!sc.CheckString("}"))
|
|
{
|
|
sc.MustGetString();
|
|
mi = PClass::FindClass(sc.String);
|
|
AddOneKey(keygroup, mi, sc);
|
|
}
|
|
if (keygroup->anykeylist.Size() == 0)
|
|
{
|
|
delete keygroup;
|
|
return NULL;
|
|
}
|
|
keygroup->anykeylist.ShrinkToFit();
|
|
return keygroup;
|
|
}
|
|
|
|
//===========================================================================
|
|
//
|
|
//
|
|
//===========================================================================
|
|
|
|
static void PrintMessage (const char *str)
|
|
{
|
|
if (str != NULL)
|
|
{
|
|
if (str[0]=='$')
|
|
{
|
|
str=GStrings(str+1);
|
|
}
|
|
C_MidPrint (str);
|
|
}
|
|
}
|
|
|
|
//===========================================================================
|
|
//
|
|
//
|
|
//===========================================================================
|
|
|
|
static void ParseLock(FScanner &sc)
|
|
{
|
|
int i,r,g,b;
|
|
int keynum;
|
|
Lock sink;
|
|
Lock * lock=&sink;
|
|
Keygroup * keygroup;
|
|
const PClass * mi;
|
|
|
|
sc.MustGetNumber();
|
|
keynum = sc.Number;
|
|
|
|
sc.MustGetString();
|
|
if (sc.Compare("DOOM"))
|
|
{
|
|
if (gameinfo.gametype != GAME_Doom) keynum=-1;
|
|
}
|
|
else if (sc.Compare("HERETIC"))
|
|
{
|
|
if (gameinfo.gametype != GAME_Heretic) keynum=-1;
|
|
}
|
|
else if (sc.Compare("HEXEN"))
|
|
{
|
|
if (gameinfo.gametype != GAME_Hexen) keynum=-1;
|
|
}
|
|
else if (sc.Compare("STRIFE"))
|
|
{
|
|
if (gameinfo.gametype != GAME_Strife) keynum=-1;
|
|
}
|
|
else sc.UnGet();
|
|
|
|
ignorekey = true;
|
|
if (keynum > 0 && keynum < 255)
|
|
{
|
|
lock = new Lock;
|
|
if (locks[keynum])
|
|
{
|
|
delete locks[keynum];
|
|
}
|
|
locks[keynum] = lock;
|
|
locks[keynum]->locksound = S_FindSound("misc/keytry");
|
|
ignorekey=false;
|
|
}
|
|
else if (keynum != -1)
|
|
{
|
|
sc.ScriptError("Lock index %d out of range", keynum);
|
|
}
|
|
|
|
sc.MustGetStringName("{");
|
|
while (!sc.CheckString("}"))
|
|
{
|
|
sc.MustGetString();
|
|
switch(i = sc.MatchString(keywords_lock))
|
|
{
|
|
case 0: // Any
|
|
keygroup = ParseKeygroup(sc);
|
|
if (keygroup)
|
|
{
|
|
lock->keylist.Push(keygroup);
|
|
}
|
|
break;
|
|
|
|
case 1: // message
|
|
sc.MustGetString();
|
|
lock->message = copystring(sc.String);
|
|
break;
|
|
|
|
case 2: // remotemsg
|
|
sc.MustGetString();
|
|
lock->remotemsg = copystring(sc.String);
|
|
break;
|
|
|
|
case 3: // mapcolor
|
|
sc.MustGetNumber();
|
|
r = sc.Number;
|
|
sc.MustGetNumber();
|
|
g = sc.Number;
|
|
sc.MustGetNumber();
|
|
b = sc.Number;
|
|
lock->rgb = MAKERGB(r,g,b);
|
|
break;
|
|
|
|
case 4: // locksound
|
|
sc.MustGetString();
|
|
lock->locksound = S_FindSound(sc.String);
|
|
break;
|
|
|
|
default:
|
|
mi = PClass::FindClass(sc.String);
|
|
if (mi)
|
|
{
|
|
keygroup = new Keygroup;
|
|
AddOneKey(keygroup, mi, sc);
|
|
if (keygroup)
|
|
{
|
|
keygroup->anykeylist.ShrinkToFit();
|
|
lock->keylist.Push(keygroup);
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
// copy the messages if the other one does not exist
|
|
if (!lock->remotemsg && lock->message)
|
|
{
|
|
lock->remotemsg = copystring(lock->message);
|
|
}
|
|
if (!lock->message && lock->remotemsg)
|
|
{
|
|
lock->message = copystring(lock->remotemsg);
|
|
}
|
|
lock->keylist.ShrinkToFit();
|
|
}
|
|
|
|
//===========================================================================
|
|
//
|
|
// Clears all key numbers so the parser can assign its own ones
|
|
// This ensures that only valid keys are considered by the key cheats
|
|
//
|
|
//===========================================================================
|
|
|
|
static void ClearLocks()
|
|
{
|
|
unsigned int i;
|
|
for(i=0;i<PClass::m_Types.Size();i++)
|
|
{
|
|
if (PClass::m_Types[i]->IsDescendantOf(RUNTIME_CLASS(AKey)))
|
|
{
|
|
AKey *key = static_cast<AKey*>(GetDefaultByType(PClass::m_Types[i]));
|
|
if (key != NULL)
|
|
{
|
|
key->KeyNumber = 0;
|
|
}
|
|
}
|
|
}
|
|
for(i=0;i<256;i++)
|
|
{
|
|
if (locks[i]!=NULL)
|
|
{
|
|
delete locks[i];
|
|
locks[i]=NULL;
|
|
}
|
|
}
|
|
currentnumber=0;
|
|
keysdone=false;
|
|
}
|
|
|
|
//===========================================================================
|
|
//
|
|
// P_InitKeyMessages
|
|
//
|
|
//===========================================================================
|
|
|
|
void P_InitKeyMessages()
|
|
{
|
|
int lastlump, lump;
|
|
|
|
lastlump = 0;
|
|
|
|
ClearLocks();
|
|
while ((lump = Wads.FindLump ("LOCKDEFS", &lastlump)) != -1)
|
|
{
|
|
FScanner sc(lump, "LOCKDEFS");
|
|
while (sc.GetString ())
|
|
{
|
|
if (sc.Compare("LOCK"))
|
|
{
|
|
ParseLock(sc);
|
|
}
|
|
else if (sc.Compare("CLEARLOCKS"))
|
|
{
|
|
// clear all existing lock definitions and key numbers
|
|
ClearLocks();
|
|
}
|
|
else
|
|
{
|
|
sc.ScriptError("Unknown command %s in LockDef", sc.String);
|
|
}
|
|
}
|
|
sc.Close();
|
|
}
|
|
keysdone = true;
|
|
}
|
|
|
|
//===========================================================================
|
|
//
|
|
// P_DeinitKeyMessages
|
|
//
|
|
//===========================================================================
|
|
|
|
void P_DeinitKeyMessages()
|
|
{
|
|
ClearLocks();
|
|
}
|
|
|
|
//===========================================================================
|
|
//
|
|
// P_CheckKeys
|
|
//
|
|
// Returns true if the actor has the required key. If not, a message is
|
|
// shown if the actor is also the consoleplayer's camarea, and false is
|
|
// returned.
|
|
//
|
|
//===========================================================================
|
|
|
|
bool P_CheckKeys (AActor *owner, int keynum, bool remote)
|
|
{
|
|
const char *failtext = NULL;
|
|
int failsound = 0;
|
|
|
|
failtext = NULL;
|
|
failsound = 0;
|
|
|
|
if (keynum<=0 || keynum>255) return true;
|
|
// Just a safety precaution. The messages should have been initialized upon game start.
|
|
if (!keysdone) P_InitKeyMessages();
|
|
|
|
if (!locks[keynum])
|
|
{
|
|
if (keynum==103 && gameinfo.gametype == GAME_Strife)
|
|
failtext = "THIS AREA IS ONLY AVAILABLE IN THE RETAIL VERSION OF STRIFE";
|
|
else
|
|
failtext = "That doesn't seem to work";
|
|
|
|
failsound = S_FindSound("misc/keytry");
|
|
}
|
|
else
|
|
{
|
|
if (locks[keynum]->check(owner)) return true;
|
|
failtext = remote? locks[keynum]->remotemsg : locks[keynum]->message;
|
|
failsound = locks[keynum]->locksound;
|
|
}
|
|
|
|
// If we get here, that means the actor isn't holding an appropriate key.
|
|
|
|
if (owner == players[consoleplayer].camera)
|
|
{
|
|
PrintMessage(failtext);
|
|
S_SoundID (owner, CHAN_VOICE, failsound, 1, ATTN_NORM);
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
//==========================================================================
|
|
//
|
|
// AKey implementation
|
|
//
|
|
//==========================================================================
|
|
|
|
IMPLEMENT_STATELESS_ACTOR (AKey, Any, -1, 0)
|
|
PROP_Inventory_FlagsSet (IF_INTERHUBSTRIP)
|
|
PROP_Inventory_PickupSound ("misc/k_pkup")
|
|
END_DEFAULTS
|
|
|
|
bool AKey::HandlePickup (AInventory *item)
|
|
{
|
|
// In single player, you can pick up an infinite number of keys
|
|
// even though you can only hold one of each.
|
|
if (multiplayer)
|
|
{
|
|
return Super::HandlePickup (item);
|
|
}
|
|
if (GetClass() == item->GetClass())
|
|
{
|
|
item->ItemFlags |= IF_PICKUPGOOD;
|
|
return true;
|
|
}
|
|
if (Inventory != NULL)
|
|
{
|
|
return Inventory->HandlePickup (item);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
bool AKey::ShouldStay ()
|
|
{
|
|
return !!multiplayer;
|
|
}
|
|
|
|
//==========================================================================
|
|
//
|
|
// These functions can be used to get color information for
|
|
// automap display of keys and locked doors
|
|
//
|
|
//==========================================================================
|
|
|
|
int P_GetMapColorForLock (int lock)
|
|
{
|
|
if (lock > 0 && lock < 256)
|
|
{
|
|
if (locks[lock]) return locks[lock]->rgb;
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
//==========================================================================
|
|
//
|
|
//
|
|
//
|
|
//==========================================================================
|
|
|
|
int P_GetMapColorForKey (AInventory * key)
|
|
{
|
|
int i;
|
|
|
|
for (i = 0; i < 256; i++)
|
|
{
|
|
if (locks[i] && locks[i]->check(key)) return locks[i]->rgb;
|
|
}
|
|
return 0;
|
|
}
|