Added Materials_FixName() for preparing materials.txt lookups

This commit is contained in:
Marco Cawthorne 2021-01-22 15:50:47 +01:00
parent 21bd18b5d7
commit 93728d283c
4 changed files with 35 additions and 4 deletions

View file

@ -351,6 +351,8 @@ void initents(void)
while ((sTemp = fgets(fileMaterial))) {
/* tokenize and just parse this stuff in */
if (tokenize_console(sTemp) == 2) {
string tex_name;
tex_name = Materials_FixName(strtolower(argv(1)));
hash_add(hashMaterials, strtolower(argv(1)), str2chr(argv(0), 0));
}
}

View file

@ -76,7 +76,9 @@ Footsteps_HLBSP(base_player target)
tex_name = getsurfacetexture(trace_ent, getsurfacenearpoint(trace_ent, trace_endpos));
if (target.flags & FL_ONGROUND) {
switch((float)hash_get(hashMaterials, tex_name)) {
tex_name = Materials_FixName(tex_name);
switch((float)hash_get(hashMaterials, tex_name)) {
case MATID_ALIEN:
mat_name = "step_alien";
break;

View file

@ -18,7 +18,7 @@
void
TraceAttack_FireSingle(vector vecPos, vector vAngle, int iDamage, int iWeapon)
{
string tex;
string tex_name;
vector range;
float surf;
@ -68,10 +68,10 @@ TraceAttack_FireSingle(vector vecPos, vector vAngle, int iDamage, int iWeapon)
switch (serverkeyfloat("*bspversion")) {
case BSPVER_HL:
surf = getsurfacenearpoint(trace_ent, trace_endpos);
tex = getsurfacetexture(trace_ent, surf);
tex_name = Materials_FixName(getsurfacetexture(trace_ent, surf));
/* our hashtable is the key to all this */
switch ((float)hash_get(hashMaterials, tex)) {
switch ((float)hash_get(hashMaterials, tex_name)) {
case MATID_ALIEN:
FX_Impact(IMPACT_ALIEN, trace_endpos, trace_plane_normal);
break;

View file

@ -88,3 +88,30 @@ enum
#define SURF_TILE 0xD0000000i
#define SURF_WOOD 0xE0000000i
#define SURF_CONCRETE 0xF0000000i
/* this is used for material-lookups using the external materials.txt file
* method used in Half-Life. In that environment we have to strip any
* prefixes and limit our material-name to 12 chars for everything to be
* identified correctly */
string
Materials_FixName(string tex_name)
{
dprint(sprintf("^3material_fixname^7: %s > ", tex_name));
/* strip the first 2 chars when they're frame/random indicators */
if (str2chr(tex_name, 0) == '-')
tex_name = substring(tex_name, 2, -1);
else if (str2chr(tex_name, 0) == '+')
tex_name = substring(tex_name, 2, -1);
/* also not allowed */
if (str2chr(tex_name, 0) == '~')
tex_name = substring(tex_name, 1, -1);
/* limit to 12 chars! */
tex_name = substring(tex_name, 0, 11);
dprint(sprintf("%s\n", tex_name));
return tex_name;
}