2019-09-19 22:42:45 +00:00
//-------------------------------------------------------------------------
/*
Copyright ( C ) 2010 - 2019 EDuke32 developers and contributors
Copyright ( C ) 2019 Nuke . YKT
This file is part of NBlood .
NBlood is free software ; you can redistribute it and / or
modify it under the terms of the GNU General Public License version 2
as published by the Free Software Foundation .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE .
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 . , 51 Franklin Street , Fifth Floor , Boston , MA 02110 - 1301 , USA .
*/
//-------------------------------------------------------------------------
2019-09-21 18:59:54 +00:00
# include "ns.h" // Must come before everything else!
2019-09-19 22:42:45 +00:00
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
# include "build.h"
# include "blood.h"
2022-12-07 16:10:27 +00:00
# include "hw_voxels.h"
# include "tilesetbuilder.h"
2019-09-19 22:42:45 +00:00
2019-09-22 06:39:22 +00:00
BEGIN_BLD_NS
2019-09-19 22:42:45 +00:00
int nTileFiles = 0 ;
2022-12-06 11:07:24 +00:00
// these arrays get partially filled by .def, so they need to remain global.
static uint8_t surfType [ kMaxTiles ] ;
static int8_t tileShade [ kMaxTiles ] ;
2019-09-19 22:42:45 +00:00
short voxelIndex [ kMaxTiles ] ;
2022-11-25 15:52:08 +00:00
# define x(a, b) registerName(#a, b);
2022-12-07 16:10:27 +00:00
static void SetTileNames ( TilesetBuildInfo & info )
2022-11-25 15:52:08 +00:00
{
2022-12-07 16:10:27 +00:00
auto registerName = [ & ] ( const char * name , int index )
2022-11-25 15:52:08 +00:00
{
2022-12-07 16:10:27 +00:00
info . addName ( name , index ) ;
2022-11-25 15:52:08 +00:00
} ;
# include "namelist.h"
2022-12-07 16:10:27 +00:00
// Oh Joy! Plasma Pak changes the tile number of the title screen, but we preferably want mods that use the original one to display it, e.g. Cryptic Passage
2022-11-25 15:52:08 +00:00
// So let's make this remapping depend on the CRC.
2022-12-07 16:10:27 +00:00
const int OTITLE = 2046 , PTITLE = 2518 ;
auto & orgtitle = info . tile [ OTITLE ] ;
auto & pptile = info . tile [ PTITLE ] ;
if ( tileGetCRC32 ( pptile . tileimage ) = = 1170870757 & & ( tileGetCRC32 ( orgtitle . tileimage ) ! = 290208654 | | pptile . tileimage - > GetWidth ( ) = = 0 ) ) registerName ( " titlescreen " , 2046 ) ;
2022-11-25 15:52:08 +00:00
else registerName ( " titlescreen " , 2518 ) ;
}
# undef x
2021-12-29 21:56:21 +00:00
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
2022-12-07 16:10:27 +00:00
void GameInterface : : LoadTextureInfo ( TilesetBuildInfo & info )
2019-09-19 22:42:45 +00:00
{
2020-04-11 21:54:33 +00:00
auto hFile = fileSystem . OpenFileReader ( " SURFACE.DAT " ) ;
2019-10-20 22:13:17 +00:00
if ( hFile . isOpen ( ) )
2019-09-19 22:42:45 +00:00
{
2019-10-20 22:13:17 +00:00
hFile . Read ( surfType , sizeof ( surfType ) ) ;
2019-09-19 22:42:45 +00:00
}
2020-04-11 21:54:33 +00:00
hFile = fileSystem . OpenFileReader ( " VOXEL.DAT " ) ;
2019-10-20 22:13:17 +00:00
if ( hFile . isOpen ( ) )
2019-09-19 22:42:45 +00:00
{
2019-10-20 22:13:17 +00:00
hFile . Read ( voxelIndex , sizeof ( voxelIndex ) ) ;
2021-12-14 11:08:48 +00:00
# if WORDS_BIGENDIAN
2019-09-19 22:42:45 +00:00
for ( int i = 0 ; i < kMaxTiles ; i + + )
2020-08-03 17:09:57 +00:00
voxelIndex [ i ] = LittleShort ( voxelIndex [ i ] ) ;
2019-09-19 22:42:45 +00:00
# endif
}
2020-04-11 21:54:33 +00:00
hFile = fileSystem . OpenFileReader ( " SHADE.DAT " ) ;
2019-10-20 22:13:17 +00:00
if ( hFile . isOpen ( ) )
2019-09-19 22:42:45 +00:00
{
2019-10-20 22:13:17 +00:00
hFile . Read ( tileShade , sizeof ( tileShade ) ) ;
2019-09-19 22:42:45 +00:00
}
for ( int i = 0 ; i < kMaxTiles ; i + + )
{
2022-09-30 14:25:21 +00:00
if ( voxelIndex [ i ] > = 0 & & voxelIndex [ i ] < MAXVOXELS )
2021-04-11 16:37:11 +00:00
voxreserve . Set ( voxelIndex [ i ] ) ;
2019-09-19 22:42:45 +00:00
}
}
2022-12-07 16:10:27 +00:00
void GameInterface : : SetupSpecialTextures ( TilesetBuildInfo & info )
2022-12-05 16:14:01 +00:00
{
2022-12-07 16:10:27 +00:00
SetTileNames ( info ) ;
2022-12-05 16:14:01 +00:00
// set up all special tiles here, before we fully hook up with the texture manager.
2022-12-07 16:10:27 +00:00
info . Delete ( 504 ) ;
info . MakeWritable ( 2342 ) ;
}
void tileInitProps ( )
{
2022-12-06 11:07:24 +00:00
for ( int i = 0 ; i < MAXTILES ; i + + )
{
auto tex = tileGetTexture ( i ) ;
if ( tex )
{
TextureAttr a = { surfType [ i ] , tileShade [ i ] , voxelIndex [ i ] } ;
tprops . Set ( tex - > GetID ( ) . GetIndex ( ) , a ) ;
}
}
2022-12-05 16:14:01 +00:00
}
2021-12-29 21:56:21 +00:00
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
2021-12-05 19:55:19 +00:00
int tileGetSurfType ( CollisionBase & hit )
2021-08-27 19:49:18 +00:00
{
switch ( hit . type )
2019-09-19 22:42:45 +00:00
{
2021-08-27 19:49:18 +00:00
default :
return 0 ;
case kHitSector :
2022-12-06 11:07:24 +00:00
return tprops [ hit . hitSector - > floortexture ( ) ] . surfType ;
2021-08-27 19:49:18 +00:00
case kHitWall :
2022-12-06 11:07:24 +00:00
return tprops [ hit . hitWall - > walltexture ( ) ] . surfType ;
2021-08-27 19:49:18 +00:00
case kHitSprite :
2022-12-06 11:07:24 +00:00
return tprops [ hit . hitActor - > spr . spritetexture ( ) ] . surfType ;
2019-09-19 22:42:45 +00:00
}
}
2019-09-22 06:39:22 +00:00
2021-12-29 21:56:21 +00:00
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
2020-09-14 23:27:24 +00:00
void GameInterface : : SetTileProps ( int tile , int surf , int vox , int shade )
{
if ( surf ! = INT_MAX ) surfType [ tile ] = surf ;
if ( vox ! = INT_MAX ) voxelIndex [ tile ] = vox ;
if ( shade ! = INT_MAX ) tileShade [ tile ] = shade ;
2022-12-06 10:20:01 +00:00
mirrortile = tileGetTextureID ( 504 ) ;
2020-09-14 23:27:24 +00:00
}
2019-09-22 06:39:22 +00:00
END_BLD_NS