- Sync scriptbranch with trunk.

SVN r2269 (scripting)
This commit is contained in:
Randy Heit 2010-04-04 04:09:24 +00:00
commit 42ac75e894
127 changed files with 2532 additions and 958 deletions

View file

@ -109,6 +109,21 @@ struct spritetype
SWORD lotag, hitag, extra;
};
// I used to have all the Xobjects mapped out. Not anymore.
// (Thanks for the great firmware, Seagate!)
struct Xsprite
{
BYTE NotReallyPadding[16];
WORD Data1;
WORD Data2;
WORD Data3;
WORD ThisIsntPaddingEither;
DWORD NorThis:2;
DWORD Data4:16;
DWORD WhatIsThisIDontEven:14;
BYTE ThisNeedsToBe56Bytes[28];
};
struct SlopeWork
{
walltype *wal;
@ -128,7 +143,7 @@ void P_AdjustLine (line_t *line);
static bool P_LoadBloodMap (BYTE *data, size_t len, FMapThing **sprites, int *numsprites);
static void LoadSectors (sectortype *bsectors);
static void LoadWalls (walltype *walls, int numwalls, sectortype *bsectors);
static int LoadSprites (spritetype *sprites, int numsprites, sectortype *bsectors, FMapThing *mapthings);
static int LoadSprites (spritetype *sprites, Xsprite *xsprites, int numsprites, sectortype *bsectors, FMapThing *mapthings);
static vertex_t *FindVertex (fixed_t x, fixed_t y);
static void CreateStartSpot (fixed_t *pos, FMapThing *start);
static void CalcPlane (SlopeWork &slope, secplane_t &plane);
@ -145,8 +160,10 @@ static void Decrypt (void *to, const void *from, int len, int key);
bool P_IsBuildMap(MapData *map)
{
DWORD len = map->Size(ML_LABEL);
if (len < 4) return false;
if (len < 4)
{
return false;
}
BYTE *data = new BYTE[len];
map->Seek(ML_LABEL);
@ -215,7 +232,7 @@ bool P_LoadBuildMap (BYTE *data, size_t len, FMapThing **sprites, int *numspr)
*sprites = new FMapThing[numsprites + 1];
CreateStartSpot ((fixed_t *)(data + 4), *sprites);
*numspr = 1 + LoadSprites ((spritetype *)(data + 26 + numsectors*sizeof(sectortype) + numwalls*sizeof(walltype)),
numsprites, (sectortype *)(data + 22), *sprites + 1);
NULL, numsprites, (sectortype *)(data + 22), *sprites + 1);
return true;
}
@ -251,11 +268,11 @@ static bool P_LoadBloodMap (BYTE *data, size_t len, FMapThing **mapthings, int *
{
memcpy (infoBlock, data + 6, 37);
}
numRevisions = *(DWORD *)(infoBlock + 27);
numsectors = *(WORD *)(infoBlock + 31);
numWalls = *(WORD *)(infoBlock + 33);
numsprites = *(WORD *)(infoBlock + 35);
skyLen = 2 << *(WORD *)(infoBlock + 16);
numRevisions = LittleLong(*(DWORD *)(infoBlock + 27));
numsectors = LittleShort(*(WORD *)(infoBlock + 31));
numWalls = LittleShort(*(WORD *)(infoBlock + 33));
numsprites = LittleShort(*(WORD *)(infoBlock + 35));
skyLen = 2 << LittleShort(*(WORD *)(infoBlock + 16));
if (mapver == 7)
{
@ -275,6 +292,7 @@ static bool P_LoadBloodMap (BYTE *data, size_t len, FMapThing **mapthings, int *
sectortype *bsec = new sectortype[numsectors];
walltype *bwal = new walltype[numWalls];
spritetype *bspr = new spritetype[numsprites];
Xsprite *xspr = new Xsprite[numsprites];
// Read sectors
k = numRevisions * sizeof(sectortype);
@ -327,9 +345,15 @@ static bool P_LoadBloodMap (BYTE *data, size_t len, FMapThing **mapthings, int *
memcpy (&bspr[i], data, sizeof(spritetype));
}
data += sizeof(spritetype);
if (bspr[i].extra > 0) // skip Xsprite
if (bspr[i].extra > 0) // copy Xsprite
{
data += 56;
assert(sizeof(Xsprite) == 56);
memcpy(&xspr[i], data, sizeof(Xsprite));
data += sizeof(Xsprite);
}
else
{
memset(&xspr[i], 0, sizeof(Xsprite));
}
}
@ -339,11 +363,12 @@ static bool P_LoadBloodMap (BYTE *data, size_t len, FMapThing **mapthings, int *
LoadWalls (bwal, numWalls, bsec);
*mapthings = new FMapThing[numsprites + 1];
CreateStartSpot ((fixed_t *)infoBlock, *mapthings);
*numspr = 1 + LoadSprites (bspr, numsprites, bsec, *mapthings + 1);
*numspr = 1 + LoadSprites (bspr, xspr, numsprites, bsec, *mapthings + 1);
delete[] bsec;
delete[] bwal;
delete[] bspr;
delete[] xspr;
return true;
}
@ -363,6 +388,8 @@ static void LoadSectors (sectortype *bsec)
sec = sectors = new sector_t[numsectors];
memset (sectors, 0, sizeof(sector_t)*numsectors);
sectors[0].e = new extsector_t[numsectors];
for (int i = 0; i < numsectors; ++i, ++bsec, ++sec)
{
bsec->wallptr = WORD(bsec->wallptr);
@ -370,6 +397,7 @@ static void LoadSectors (sectortype *bsec)
bsec->ceilingstat = WORD(bsec->ceilingstat);
bsec->floorstat = WORD(bsec->floorstat);
sec->e = &sectors[0].e[i];
sec->SetPlaneTexZ(sector_t::floor, -(LittleLong(bsec->floorz) << 8));
sec->floorplane.d = -sec->GetPlaneTexZ(sector_t::floor);
sec->floorplane.c = FRACUNIT;
@ -512,6 +540,8 @@ static void LoadWalls (walltype *walls, int numwalls, sectortype *bsec)
}
sides[i].TexelLength = walls[i].xrepeat * 8;
sides[i].SetTextureYScale(walls[i].yrepeat << (FRACBITS - 3));
sides[i].SetTextureXScale(FRACUNIT);
sides[i].SetLight(SHADE2LIGHT(walls[i].shade));
sides[i].Flags = WALLF_ABSLIGHTING;
sides[i].RightSide = walls[i].point2;
@ -631,14 +661,17 @@ static void LoadWalls (walltype *walls, int numwalls, sectortype *bsec)
R_AlignFlat (linenum, sidenum == bsec->wallptr, 0);
}
}
for(i = 0; i < numsides; i++)
for (i = 0; i < numlines; i++)
{
sides[i].linedef = &lines[intptr_t(sides[i].linedef)];
intptr_t front = intptr_t(lines[i].sidedef[0]);
intptr_t back = intptr_t(lines[i].sidedef[1]);
lines[i].sidedef[0] = front >= 0 ? &sides[front] : NULL;
lines[i].sidedef[1] = back >= 0 ? &sides[back] : NULL;
}
for(i = 0; i < numlines; i++)
for (i = 0; i < numsides; i++)
{
lines[i].sidedef[0] = &sides[intptr_t(lines[i].sidedef[0])];
lines[i].sidedef[1] = &sides[intptr_t(lines[i].sidedef[1])];
assert(sides[i].sector != NULL);
sides[i].linedef = &lines[intptr_t(sides[i].linedef)];
}
}
@ -648,32 +681,46 @@ static void LoadWalls (walltype *walls, int numwalls, sectortype *bsec)
//
//==========================================================================
static int LoadSprites (spritetype *sprites, int numsprites, sectortype *bsectors,
FMapThing *mapthings)
static int LoadSprites (spritetype *sprites, Xsprite *xsprites, int numsprites,
sectortype *bsectors, FMapThing *mapthings)
{
int count = 0;
for (int i = 0; i < numsprites; ++i)
{
if (sprites[i].cstat & (16|32|32768)) continue;
if (sprites[i].xrepeat == 0 || sprites[i].yrepeat == 0) continue;
mapthings[count].thingid = 0;
mapthings[count].x = (sprites[i].x << 12);
mapthings[count].y = -(sprites[i].y << 12);
mapthings[count].z = (bsectors[sprites[i].sectnum].floorz - sprites[i].z) << 8;
mapthings[count].angle = (((2048-sprites[i].ang) & 2047) * 360) >> 11;
mapthings[count].type = 9988;
mapthings[count].ClassFilter = 0xffff;
mapthings[count].SkillFilter = 0xffff;
mapthings[count].flags = MTF_SINGLE|MTF_COOPERATIVE|MTF_DEATHMATCH;
mapthings[count].special = 0;
mapthings[count].args[0] = sprites[i].picnum & 255;
mapthings[count].args[1] = sprites[i].picnum >> 8;
mapthings[count].args[2] = sprites[i].xrepeat;
mapthings[count].args[3] = sprites[i].yrepeat;
mapthings[count].args[4] = (sprites[i].cstat & 14) | ((sprites[i].cstat >> 9) & 1);
if (xsprites != NULL && sprites[i].lotag == 710)
{ // Blood ambient sound
mapthings[count].args[0] = xsprites[i].Data3;
// I am totally guessing abount the volume level. 50 seems to be a pretty
// typical value for Blood's standard maps, so I assume it's 100-based.
mapthings[count].args[1] = xsprites[i].Data4;
mapthings[count].args[2] = xsprites[i].Data1;
mapthings[count].args[3] = xsprites[i].Data2;
mapthings[count].args[4] = 0;
mapthings[count].type = 14065;
}
else
{
if (sprites[i].cstat & (16|32|32768)) continue;
if (sprites[i].xrepeat == 0 || sprites[i].yrepeat == 0) continue;
mapthings[count].type = 9988;
mapthings[count].args[0] = sprites[i].picnum & 255;
mapthings[count].args[1] = sprites[i].picnum >> 8;
mapthings[count].args[2] = sprites[i].xrepeat;
mapthings[count].args[3] = sprites[i].yrepeat;
mapthings[count].args[4] = (sprites[i].cstat & 14) | ((sprites[i].cstat >> 9) & 1);
}
count++;
}
return count;