Adapt linedef type 540 to UDMF

This commit is contained in:
MascaraSnake 2021-12-30 15:32:28 +01:00
parent f30b97ba93
commit e3d41e0bda
5 changed files with 50 additions and 27 deletions

View file

@ -226,6 +226,12 @@ universalfields
type = 3;
default = false;
}
friction
{
type = 0;
default = 0;
}
}
linedef

View file

@ -50,6 +50,7 @@ enum sector_e {
sector_fslope,
sector_cslope,
sector_flags,
sector_friction,
};
static const char *const sector_opt[] = {
@ -74,6 +75,7 @@ static const char *const sector_opt[] = {
"f_slope",
"c_slope",
"flags",
"friction",
NULL};
enum subsector_e {
@ -654,6 +656,9 @@ static int sector_get(lua_State *L)
case sector_flags: // flags
lua_pushinteger(L, sector->flags);
return 1;
case sector_friction: // friction
lua_pushinteger(L, sector->friction);
return 1;
}
return 0;
}
@ -681,6 +686,7 @@ static int sector_set(lua_State *L)
case sector_ffloors: // ffloors
case sector_fslope: // f_slope
case sector_cslope: // c_slope
case sector_friction: // friction
default:
return luaL_error(L, "sector_t field " LUA_QS " cannot be set.", sector_opt[field]);
case sector_floorheight: { // floorheight

View file

@ -1674,6 +1674,8 @@ static void ParseTextmapSectorParameter(UINT32 i, char *param, char *val)
sectors[i].flags |= MSF_INVERTPRECIP;
else if (fastcmp(param, "heatwave") && fastcmp("true", val))
sectors[i].flags |= MSF_HEATWAVE;
else if (fastcmp(param, "friction"))
sectors[i].friction = atol(val);
}
static void ParseTextmapSidedefParameter(UINT32 i, char *param, char *val)
@ -4835,6 +4837,13 @@ static void P_ConvertBinaryMap(void)
lines[i].args[4] |= TMST_NONEXCLUSIVE;
lines[i].special = 510;
break;
case 540: //Floor friction
{
INT32 s;
TAG_ITER_SECTORS(tag, s)
sectors[s].friction = sides[lines[i].sidenum[0]].textureoffset >> FRACBITS;
break;
}
case 541: //Wind
case 542: //Upwards wind
case 543: //Downwards wind

View file

@ -8184,40 +8184,40 @@ void T_Friction(friction_t *f)
static void P_SpawnFriction(void)
{
size_t i;
line_t *l = lines;
mtag_t tag;
register INT32 s;
fixed_t strength; // frontside texture offset controls magnitude
sector_t *s = sectors;
fixed_t strength; // friction value of sector
fixed_t friction; // friction value to be applied during movement
INT32 movefactor; // applied to each player move to simulate inertia
for (i = 0; i < numlines; i++, l++)
if (l->special == 540)
{
tag = Tag_FGet(&l->tags);
strength = sides[l->sidenum[0]].textureoffset>>FRACBITS;
if (strength > 0) // sludge
strength = strength*2; // otherwise, the maximum sludginess value is +967...
for (i = 0; i < numsectors; i++, s++)
{
if (!s->friction)
continue;
// The following might seem odd. At the time of movement,
// the move distance is multiplied by 'friction/0x10000', so a
// higher friction value actually means 'less friction'.
friction = ORIG_FRICTION - (0x1EB8*strength)/0x80; // ORIG_FRICTION is 0xE800
strength = s->friction;
if (strength > 0) // sludge
strength = strength*2; // otherwise, the maximum sludginess value is +967...
if (friction > FRACUNIT)
friction = FRACUNIT;
if (friction < 0)
friction = 0;
// The following might seem odd. At the time of movement,
// the move distance is multiplied by 'friction/0x10000', so a
// higher friction value actually means 'less friction'.
friction = ORIG_FRICTION - (0x1EB8*strength)/0x80; // ORIG_FRICTION is 0xE800
movefactor = FixedDiv(ORIG_FRICTION, friction);
if (movefactor < FRACUNIT)
movefactor = 8*movefactor - 7*FRACUNIT;
else
movefactor = FRACUNIT;
if (friction > FRACUNIT)
friction = FRACUNIT;
if (friction < 0)
friction = 0;
TAG_ITER_SECTORS(tag, s)
Add_Friction(friction, movefactor, s, -1);
}
movefactor = FixedDiv(ORIG_FRICTION, friction);
if (movefactor < FRACUNIT)
movefactor = 8*movefactor - 7*FRACUNIT;
else
movefactor = FRACUNIT;
Add_Friction(friction, movefactor, (INT32)(s-sectors), -1);
}
}
/*

View file

@ -371,6 +371,8 @@ typedef struct sector_s
boolean verticalflip; // If gravity < 0, then allow flipped physics
sectorflags_t flags;
INT32 friction;
// Sprite culling feature
struct line_s *cullheight;