- added a 'player.clearcolorset' property so that inherited color sets can be removed.

- fixed: Player color sets were not inheritable.


SVN r2202 (trunk)
This commit is contained in:
Christoph Oelckers 2010-03-07 09:13:41 +00:00
parent 5a72e8d20e
commit 0569d948df
7 changed files with 80 additions and 49 deletions

View file

@ -71,18 +71,6 @@ enum
APMETA_Slot9, APMETA_Slot9,
}; };
// Standard pre-defined skin colors
struct FPlayerColorSet
{
FName Name; // Name of this color
int Lump; // Lump to read the translation from, otherwise use next 2 fields
BYTE FirstColor, LastColor; // Describes the range of colors to use for the translation
BYTE RepresentativeColor; // A palette entry representative of this translation,
// for map arrows and status bar backgrounds and such
};
void P_AddPlayerColorSet(FName classname, int setnum, const FPlayerColorSet *colorset);
FPlayerColorSet *P_GetPlayerColorSet(FName classname, int setnum); FPlayerColorSet *P_GetPlayerColorSet(FName classname, int setnum);
void P_EnumPlayerColorSets(FName classname, TArray<int> *out); void P_EnumPlayerColorSets(FName classname, TArray<int> *out);

View file

@ -141,6 +141,11 @@ void PClass::StaticFreeData (PClass *type)
delete type->ActorInfo->PainChances; delete type->ActorInfo->PainChances;
type->ActorInfo->PainChances = NULL; type->ActorInfo->PainChances = NULL;
} }
if (type->ActorInfo->ColorSets != NULL)
{
delete type->ActorInfo->ColorSets;
type->ActorInfo->ColorSets = NULL;
}
delete type->ActorInfo; delete type->ActorInfo;
type->ActorInfo = NULL; type->ActorInfo = NULL;
} }
@ -311,6 +316,7 @@ PClass *PClass::CreateDerivedClass (FName name, unsigned int size)
info->StateList = NULL; info->StateList = NULL;
info->DamageFactors = NULL; info->DamageFactors = NULL;
info->PainChances = NULL; info->PainChances = NULL;
info->ColorSets = NULL;
m_RuntimeActors.Push (type); m_RuntimeActors.Push (type);
} }
return type; return type;

View file

@ -309,6 +309,25 @@ void FActorInfo::SetPainChance(FName type, int chance)
// //
//========================================================================== //==========================================================================
void FActorInfo::SetColorSet(int index, const FPlayerColorSet *set)
{
if (set != NULL)
{
if (ColorSets == NULL) ColorSets = new FPlayerColorSetMap;
ColorSets->Insert(index, *set);
}
else
{
if (ColorSets != NULL)
ColorSets->Remove(index);
}
}
//==========================================================================
//
//
//==========================================================================
FDoomEdMap DoomEdMap; FDoomEdMap DoomEdMap;
FDoomEdMap::FDoomEdEntry *FDoomEdMap::DoomEdHash[DOOMED_HASHSIZE]; FDoomEdMap::FDoomEdEntry *FDoomEdMap::DoomEdHash[DOOMED_HASHSIZE];

View file

@ -145,8 +145,21 @@ FArchive &operator<< (FArchive &arc, FState *&state);
#include "gametype.h" #include "gametype.h"
// Standard pre-defined skin colors
struct FPlayerColorSet
{
FName Name; // Name of this color
int Lump; // Lump to read the translation from, otherwise use next 2 fields
BYTE FirstColor, LastColor; // Describes the range of colors to use for the translation
BYTE RepresentativeColor; // A palette entry representative of this translation,
// for map arrows and status bar backgrounds and such
};
typedef TMap<FName, fixed_t> DmgFactors; typedef TMap<FName, fixed_t> DmgFactors;
typedef TMap<FName, BYTE> PainChanceList; typedef TMap<FName, BYTE> PainChanceList;
typedef TMap<int, FPlayerColorSet> FPlayerColorSetMap;
struct FActorInfo struct FActorInfo
{ {
@ -158,6 +171,7 @@ struct FActorInfo
void RegisterIDs (); void RegisterIDs ();
void SetDamageFactor(FName type, fixed_t factor); void SetDamageFactor(FName type, fixed_t factor);
void SetPainChance(FName type, int chance); void SetPainChance(FName type, int chance);
void SetColorSet(int index, const FPlayerColorSet *set);
FState *FindState (int numnames, FName *names, bool exact=false) const; FState *FindState (int numnames, FName *names, bool exact=false) const;
FState *FindStateByString(const char *name, bool exact=false); FState *FindStateByString(const char *name, bool exact=false);
@ -180,6 +194,7 @@ struct FActorInfo
FStateLabels *StateList; FStateLabels *StateList;
DmgFactors *DamageFactors; DmgFactors *DamageFactors;
PainChanceList *PainChances; PainChanceList *PainChances;
FPlayerColorSetMap *ColorSets;
}; };
class FDoomEdMap class FDoomEdMap

View file

@ -55,10 +55,6 @@
static FRandom pr_skullpop ("SkullPop"); static FRandom pr_skullpop ("SkullPop");
// Color set class name -> mapping table
typedef TMap<int, FPlayerColorSet> FPlayerColorSetMap;
TMap<FName, FPlayerColorSetMap *> PlayerToColorsMap;
// [RH] # of ticks to complete a turn180 // [RH] # of ticks to complete a turn180
#define TURN180_TICKS ((TICRATE / 4) + 1) #define TURN180_TICKS ((TICRATE / 4) + 1)
@ -2635,39 +2631,25 @@ void player_t::Serialize (FArchive &arc)
} }
static FPlayerColorSetMap *GetPlayerColors(FName classname, bool create) static FPlayerColorSetMap *GetPlayerColors(FName classname)
{ {
FPlayerColorSetMap *map, **value; const PClass *cls = PClass::FindClass(classname);
value = PlayerToColorsMap.CheckKey(classname); if (cls != NULL)
if (value == NULL)
{ {
if (create) FActorInfo *inf = cls->ActorInfo;
{
map = new FPlayerColorSetMap;
PlayerToColorsMap.Insert(classname, map);
}
else
{
map = NULL;
}
}
else
{
map = *value;
}
return map;
}
void P_AddPlayerColorSet(FName classname, int setnum, const FPlayerColorSet *colorset) if (inf != NULL)
{ {
FPlayerColorSetMap *map = GetPlayerColors(classname, true); return inf->ColorSets;
(*map)[setnum] = *colorset; }
}
return NULL;
} }
FPlayerColorSet *P_GetPlayerColorSet(FName classname, int setnum) FPlayerColorSet *P_GetPlayerColorSet(FName classname, int setnum)
{ {
FPlayerColorSetMap *map = GetPlayerColors(classname, false); FPlayerColorSetMap *map = GetPlayerColors(classname);
if (map == NULL) if (map == NULL)
{ {
return NULL; return NULL;
@ -2683,7 +2665,7 @@ static int STACK_ARGS intcmp(const void *a, const void *b)
void P_EnumPlayerColorSets(FName classname, TArray<int> *out) void P_EnumPlayerColorSets(FName classname, TArray<int> *out)
{ {
out->Clear(); out->Clear();
FPlayerColorSetMap *map = GetPlayerColors(classname, false); FPlayerColorSetMap *map = GetPlayerColors(classname);
if (map != NULL) if (map != NULL)
{ {
FPlayerColorSetMap::Iterator it(*map); FPlayerColorSetMap::Iterator it(*map);

View file

@ -159,6 +159,12 @@ FActorInfo *CreateNewActor(const FScriptPosition &sc, FName typeName, FName pare
info->PainChances = new PainChanceList; info->PainChances = new PainChanceList;
*info->PainChances = *parent->ActorInfo->PainChances; *info->PainChances = *parent->ActorInfo->PainChances;
} }
if (parent->ActorInfo->ColorSets != NULL)
{
// copy color sets from parent
info->ColorSets = new FPlayerColorSetMap;
*info->ColorSets = *parent->ActorInfo->ColorSets;
}
info->Replacee = info->Replacement = NULL; info->Replacee = info->Replacement = NULL;
info->DoomEdNum = -1; info->DoomEdNum = -1;
return info; return info;

View file

@ -358,8 +358,7 @@ DEFINE_PROPERTY(painchance, ZI, Actor)
if (!stricmp(str, "Normal")) painType = NAME_None; if (!stricmp(str, "Normal")) painType = NAME_None;
else painType=str; else painType=str;
if (info->PainChances == NULL) info->PainChances=new PainChanceList; info->SetPainChance(painType, id);
(*info->PainChances)[painType] = (BYTE)id;
} }
} }
@ -953,13 +952,11 @@ DEFINE_PROPERTY(damagefactor, ZF, Actor)
} }
else else
{ {
if (info->DamageFactors == NULL) info->DamageFactors=new DmgFactors;
FName dmgType; FName dmgType;
if (!stricmp(str, "Normal")) dmgType = NAME_None; if (!stricmp(str, "Normal")) dmgType = NAME_None;
else dmgType=str; else dmgType=str;
(*info->DamageFactors)[dmgType]=id; info->SetDamageFactor(dmgType, id);
} }
} }
@ -1884,7 +1881,7 @@ DEFINE_CLASS_PROPERTY_PREFIX(player, colorset, ISIII, PlayerPawn)
} }
else else
{ {
P_AddPlayerColorSet(info->Class->TypeName, setnum, &color); info->SetColorSet(setnum, &color);
} }
} }
@ -1908,9 +1905,27 @@ DEFINE_CLASS_PROPERTY_PREFIX(player, colorsetfile, ISSI, PlayerPawn)
} }
else if (color.Lump >= 0) else if (color.Lump >= 0)
{ {
P_AddPlayerColorSet(info->Class->TypeName, setnum, &color); info->SetColorSet(setnum, &color);
} }
} }
//==========================================================================
//
//==========================================================================
DEFINE_CLASS_PROPERTY_PREFIX(player, clearcolorset, I, PlayerPawn)
{
PROP_INT_PARM(setnum, 0);
if (setnum < 0)
{
bag.ScriptPosition.Message(MSG_WARNING, "Color set number must not be negative.\n");
}
else
{
info->SetColorSet(setnum, NULL);
}
}
//========================================================================== //==========================================================================
// //
//========================================================================== //==========================================================================