1999-12-25 05:22:39 +00:00
|
|
|
/*
|
2000-03-04 16:43:53 +00:00
|
|
|
skin.c - player skins
|
2000-01-06 13:48:07 +00:00
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
Copyright (C) 1999,2000 contributors of the QuakeForge project
|
2000-01-08 04:50:26 +00:00
|
|
|
Portions Copyright (C) 1999,2000 Nelson Rush.
|
2000-01-06 13:48:07 +00:00
|
|
|
Please see the file "AUTHORS" for a list of contributors
|
1999-12-25 05:22:39 +00:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2000-03-19 15:59:51 +00:00
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
1999-12-25 05:22:39 +00:00
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2000-01-27 17:06:02 +00:00
|
|
|
#include "qtypes.h"
|
1999-12-25 05:22:39 +00:00
|
|
|
#include "quakedef.h"
|
2000-01-27 17:06:02 +00:00
|
|
|
#include "cvar.h"
|
|
|
|
#include "client.h"
|
|
|
|
#include "console.h"
|
2000-02-20 21:19:50 +00:00
|
|
|
#include "client.h"
|
1999-12-25 05:22:39 +00:00
|
|
|
|
2000-02-27 07:13:32 +00:00
|
|
|
//cvar_t baseskin = {"baseskin", "base"};
|
|
|
|
cvar_t *baseskin;
|
|
|
|
//cvar_t noskins = {"noskins", "0"};
|
|
|
|
cvar_t *noskins;
|
1999-12-25 05:22:39 +00:00
|
|
|
|
|
|
|
char allskins[128];
|
|
|
|
#define MAX_CACHED_SKINS 128
|
|
|
|
skin_t skins[MAX_CACHED_SKINS];
|
|
|
|
int numskins;
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
Skin_Find
|
|
|
|
|
|
|
|
Determines the best skin for the given scoreboard
|
|
|
|
slot, and sets scoreboard->skin
|
|
|
|
|
|
|
|
================
|
|
|
|
*/
|
|
|
|
void Skin_Find (player_info_t *sc)
|
|
|
|
{
|
|
|
|
skin_t *skin;
|
|
|
|
int i;
|
|
|
|
char name[128], *s;
|
|
|
|
|
|
|
|
if (allskins[0])
|
|
|
|
strcpy (name, allskins);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
s = Info_ValueForKey (sc->userinfo, "skin");
|
|
|
|
if (s && s[0])
|
|
|
|
strcpy (name, s);
|
|
|
|
else
|
2000-02-27 07:13:32 +00:00
|
|
|
strcpy (name, baseskin->string);
|
1999-12-25 05:22:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (strstr (name, "..") || *name == '.')
|
|
|
|
strcpy (name, "base");
|
|
|
|
|
|
|
|
COM_StripExtension (name, name);
|
|
|
|
|
|
|
|
for (i=0 ; i<numskins ; i++)
|
|
|
|
{
|
|
|
|
if (!strcmp (name, skins[i].name))
|
|
|
|
{
|
|
|
|
sc->skin = &skins[i];
|
|
|
|
Skin_Cache (sc->skin);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (numskins == MAX_CACHED_SKINS)
|
|
|
|
{ // ran out of spots, so flush everything
|
|
|
|
Skin_Skins_f ();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
skin = &skins[numskins];
|
|
|
|
sc->skin = skin;
|
|
|
|
numskins++;
|
|
|
|
|
|
|
|
memset (skin, 0, sizeof(*skin));
|
|
|
|
strncpy(skin->name, name, sizeof(skin->name) - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
==========
|
|
|
|
Skin_Cache
|
|
|
|
|
|
|
|
Returns a pointer to the skin bitmap, or NULL to use the default
|
|
|
|
==========
|
|
|
|
*/
|
|
|
|
byte *Skin_Cache (skin_t *skin)
|
|
|
|
{
|
|
|
|
char name[1024];
|
2000-03-04 16:43:53 +00:00
|
|
|
// byte *raw;
|
|
|
|
byte *out;//, *pix;
|
|
|
|
// pcx_t *pcx;
|
|
|
|
// int x, y;
|
|
|
|
// int dataByte;
|
|
|
|
// int runLength;
|
1999-12-25 05:22:39 +00:00
|
|
|
|
|
|
|
if (cls.downloadtype == dl_skin)
|
|
|
|
return NULL; // use base until downloaded
|
|
|
|
|
2000-02-27 07:13:32 +00:00
|
|
|
if (noskins->value==1) // JACK: So NOSKINS > 1 will show skins, but
|
1999-12-25 05:22:39 +00:00
|
|
|
return NULL; // not download new ones.
|
|
|
|
|
|
|
|
if (skin->failedload)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
out = Cache_Check (&skin->cache);
|
|
|
|
if (out)
|
|
|
|
return out;
|
|
|
|
|
|
|
|
//
|
|
|
|
// load the pic from disk
|
|
|
|
//
|
2000-01-05 00:05:48 +00:00
|
|
|
snprintf(name, sizeof(name), "skins/%s.pcx", skin->name);
|
2000-03-04 20:32:38 +00:00
|
|
|
out = LoadPCX (name, &skin->cache, 320, 200);
|
|
|
|
if (out == NULL) {
|
1999-12-25 05:22:39 +00:00
|
|
|
Con_Printf ("Couldn't load skin %s\n", name);
|
2000-02-27 07:13:32 +00:00
|
|
|
snprintf(name, sizeof(name), "skins/%s.pcx", baseskin->string);
|
2000-03-04 20:32:38 +00:00
|
|
|
out = LoadPCX (name, &skin->cache, 320, 200);
|
|
|
|
if (out == NULL) {
|
1999-12-25 05:22:39 +00:00
|
|
|
skin->failedload = true;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
skin->failedload = false;
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
Skin_NextDownload
|
|
|
|
=================
|
|
|
|
*/
|
|
|
|
void Skin_NextDownload (void)
|
|
|
|
{
|
|
|
|
player_info_t *sc;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (cls.downloadnumber == 0)
|
|
|
|
Con_Printf ("Checking skins...\n");
|
|
|
|
cls.downloadtype = dl_skin;
|
|
|
|
|
2000-03-19 15:59:51 +00:00
|
|
|
for (
|
1999-12-25 05:22:39 +00:00
|
|
|
; cls.downloadnumber != MAX_CLIENTS
|
|
|
|
; cls.downloadnumber++)
|
|
|
|
{
|
|
|
|
sc = &cl.players[cls.downloadnumber];
|
|
|
|
if (!sc->name[0])
|
|
|
|
continue;
|
|
|
|
Skin_Find (sc);
|
2000-02-27 07:13:32 +00:00
|
|
|
if (noskins->value)
|
1999-12-25 05:22:39 +00:00
|
|
|
continue;
|
2000-02-20 21:19:50 +00:00
|
|
|
#ifndef UQUAKE
|
1999-12-25 05:22:39 +00:00
|
|
|
if (!CL_CheckOrDownloadFile(va("skins/%s.pcx", sc->skin->name)))
|
|
|
|
return; // started a download
|
2000-02-20 21:19:50 +00:00
|
|
|
#endif
|
1999-12-25 05:22:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cls.downloadtype = dl_none;
|
|
|
|
|
|
|
|
// now load them in for real
|
|
|
|
for (i=0 ; i<MAX_CLIENTS ; i++)
|
|
|
|
{
|
|
|
|
sc = &cl.players[i];
|
|
|
|
if (!sc->name[0])
|
|
|
|
continue;
|
|
|
|
Skin_Cache (sc->skin);
|
|
|
|
sc->skin = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cls.state != ca_active)
|
|
|
|
{ // get next signon phase
|
|
|
|
MSG_WriteByte (&cls.netchan.message, clc_stringcmd);
|
|
|
|
MSG_WriteString (&cls.netchan.message,
|
|
|
|
va("begin %i", cl.servercount));
|
|
|
|
Cache_Report (); // print remaining memory
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
==========
|
|
|
|
Skin_Skins_f
|
|
|
|
|
|
|
|
Refind all skins, downloading if needed.
|
|
|
|
==========
|
|
|
|
*/
|
|
|
|
void Skin_Skins_f (void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i=0 ; i<numskins ; i++)
|
|
|
|
{
|
|
|
|
if (skins[i].cache.data)
|
|
|
|
Cache_Free (&skins[i].cache);
|
|
|
|
}
|
|
|
|
numskins = 0;
|
|
|
|
|
|
|
|
cls.downloadnumber = 0;
|
|
|
|
cls.downloadtype = dl_skin;
|
|
|
|
Skin_NextDownload ();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
==========
|
|
|
|
Skin_AllSkins_f
|
|
|
|
|
|
|
|
Sets all skins to one specific one
|
|
|
|
==========
|
|
|
|
*/
|
|
|
|
void Skin_AllSkins_f (void)
|
|
|
|
{
|
|
|
|
strcpy (allskins, Cmd_Argv(1));
|
|
|
|
Skin_Skins_f ();
|
|
|
|
}
|