Files
source/Utils/MapUtility.cpp
T
Wanne 7ca53fadc7 *** MERGED source code from development trunk revision 4890 up to latest current revision 5105 ***
Development Trunk (now obsolete): https://ja2svn.dyndns.org/source/ja2/branches/Wanne/JA2%201.13%20MP
A detailed list of all the features (changes) is visible in the history log of the development trunk:

INFO: There will be no further development in the development source trunk, so is obsolete from now on!

This commit contains the following features (bugfixes are not listed):

- New Feature: Show merc ranks in Strategy Screen before merc name
o Toggle on/off in the ingame options screen
o For each experience level (0-10) there are defined rank names in the language specific text files
o Additional language text that is not translated yet is marked with // TODO.Translate

- New Feature: Faster Bobby Ray Shipments
o This feature is selectable in the ja2_options.ini
o When activated Bobby Ray shipments will be really fast
-> Overnight Express: 5 - 7 hours
-> Air Service: 10, 12 or 14 hours
-> Standard Service: 15, 18 or 21 hours
o In a multiplayer game, this feature is disabled (because shipment arrive immediately in the destination sector)

- New Feature: AP cost for manipulating the merc inventory
o This feature is selectable in the start new game screen
o For example, putting a weapon from hand in the backpack costs APs
o The AP costs are defined in the APBPConstants.ini
o In a multiplayer game, this feature is disabled

- New Feature: Added possibility to set individual Gear Kit names
o Set individual names in the optional new tag <mGearKitName> inside the <GEARKIT> root element (File: TableData\MercStartingGear.xml)

- New Feature: Externalized the maximum purchase amount (JA2 vanilla: 10) for Bobby Rays purchases per shipment
o Define the max. amount in the ja2_options.ini: BOBBY_RAY_MAX_PURCHASE_AMOUNT, Range: 10 - 100)
o Nice scrolling bars to scroll through all the purchases

- New Feature: Now it is possible to walk on "water" tiles or handle those tiles like "normal" tiles 
o (instead of showing the swimming animation and counting the APs for swimming), when the soldier is located on the second level (level > 0)

- New Feature: Externalized AIM Veterans laptop site
o Add maximum of 4 pages
o Add  new AIM to veterans page, and remove AIM from veterans page.
o New XML file: OldAIMArchive.xml (language specific XML files: *.OldAIMArchive.xml)

- New Feature: Added possibility to choose from 254 IMP faces
o Modified IMPPortraits.xml
o Added new GameDir folder "IMPFaces" which contains the IMP face portraits
o Moved IMP faces in the new "IMPFaces" folder

- New Feature: ARSP - All Resolution Support Project
o See here: http://www.ja-galaxy-forum.com/board/ubbthreads.php?ubb=showflat&Number=298698&page=1
o Support any kind of screen resolution. This works by choosing the matching full supported resolution (640x480, 800x600, 1024x768) and then centering the graphics
o See ja2.ini for defining the screen resolution

- New Feature: AI Turn Speed Up (FF-MOD)
o see here: http://www.ja-galaxy-forum.com/board/ubbthreads.php?ubb=showflat&Number=298699#Post298699
o When this feature is activated it allows fast enemy turns
o New entry in ja2.ini to enable this feature: HIGHSPEED_TIMER = TRUE
o Turn on/off auto fast turns in ingame options
o New ja2_options.ini settings for fine tuning: [Clock Settings] ini block

- New Feature: "Lock" / "Release" mouse cursor in tactical windowed mode, so the mouse can stay within window boundary
o This is very helpful for doing scrolling with the mouse (by moving the mouse to the window edge) in windowed mode
o You can toggle on/off the feature by pressing CTRL + Z. It is also possible to press CTRL + Y. So the user can decide which fits better :)
o Whenever you toggle on/off a screen message appears on the tactical log to notify the player

- New Feature: Weapon overheating
o Basically, every shot fired from a gun increases its temperature. On higher temperatures, the gun jams more frequently
o On/off toggle in the ingame options
o Graphical thermometer indication on the weapon picture
o New ja2_options.ini section with a few options, Section: [Tactical Weapon Overheating Settings]
o XML changes (New Tags)
--> AmmoTypes.xml: <temperatureModificator>
--> Items.xml: <barrel>, <usOverheatingCooldownFactor>
--> Weapons.xml: <usOverheatingJamThreshold>, <usOverheatingDamageThreshold>, <usOverheatingSingleShotTemperature>
o Added a few barells to Items.xml (end of the file)
o more infos: http://www.ja-galaxy-forum.com/board/ubbthreads.php?ubb=showflat&Number=301059&page=1

- New Feature: Resting weapons on a surfaces
o You can now rest your weapon on crates, low walls, rocks, debris, open windows etc. while you are crouched. Resting will give yu the superior gun handling modifiers from PRONE position.
o A little 'A' on your gun indicates if you are resting it or not.
o Both settings can be turned on and off in Ja2_Options.ini under 'Tactical Gameplay Settings'

- New Feature: Externalized option on whether mercs can exit sector using grid exit in turn based mode
o new ja2_options.ini property: GRID_EXIT_IN_TURNBASED
o This ini setting does not affect leaving sectors on map edges

- Rework/Update: Ammo boxes and Ammo crates
o Ammo crate items added for remaining calibers.  Tweaked prices to correspond to magazines, tweaked capacities and weights to be reasonable (~800 or less).
o Shift-R reload now looks at both boxes and crates in sector items and merc's inventory to reload, and tops off magazines in inventory as well.  Only possible outside of combat.
o Ctrl-Shift-A still creates crates as per usual, with some fixes to ensure all ammo is caught on the first press.
o Shift-A now creates ammo boxes in the same loop.  They mostly behave like crates, but fit in mercs inventories.
o Ammo boxes are available to purchase at BR and tony, sam, etc.  Individual magazines/drums/etc are no longer available.
o Removed ammo crate xml tag.  Added ubMagType tag to Magazines array.  This allows us to differentiate between magazines, bullets, boxes and crates.
o Changed ammo filtering in BR's to display boxes appropriately.  Added back the "Mag:" display (changed text to "Size:")
o Added ja2set.dat.xml file (WF map version in WF maps folder) to be used instead of ja2set.dat file (ja2.ini setting added) For now, if you want to play vanilla instead, just change the setting in the ini (see comments in file).
o Added P4-P9Items image files (up to 5k images each) and tileslots.  1.13 core items will continue to use Guns and P1-P3Items for the foreseeable future.  P4-P9 can be used by customizers/modders to avoid conflicts with Guns/P1-P3 items.  TODO: Need to discuss a strategy for this in the forums.
o Added in Ambient/0.bad and 32.bad to avoid an exception in the code.
o Updated the XML Editor
o Standardized the text on all the ammo items.

- New Multiplayer Feature: Sharing same FOV (field of view) in a coop/team-dm (for friendly teams) game
o You will also see enemies, that your teammate sees

git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@5108 3b4a5df2-a311-0410-b5c6-a8a6f20db521
2012-03-23 18:46:54 +00:00

307 lines
9.5 KiB
C++

#ifdef PRECOMPILEDHEADERS
#include "Utils All.h"
#else
#include "sgp.h"
#endif
#ifdef JA2EDITOR
#include "Screens.h"
#include "Maputility.h"
#include "worlddef.h"
#include "overhead.h"
#include "fileman.h"
#include "loadscreen.h"
#include "overhead map.h"
#include "radar screen.h"
#include "vobject_blitters.h"
#include "sticonvert.h"
#include "font control.h"
#include "worlddat.h"
#include "english.h"
#include "map information.h"
#include "line.h"
#include "quantize wrap.h"
#define MINIMAP_X_SIZE 88//RADAR_WINDOW_WIDTH
#define MINIMAP_Y_SIZE 44//RADAR_WINDOW_HEIGHT
#define WINDOW_SIZE 2
extern BOOLEAN fEditModeFirstTime;
extern BOOLEAN gfOverheadMapDirty;
extern UINT16 iOffsetHorizontal;
extern UINT16 iOffsetVertical;
extern FDLG_LIST* FileList;
typedef struct
{
INT8 r;
INT8 g;
INT8 b;
}RGBValues;
FLOAT gdXStep, gdYStep;
INT32 giMiniMap, gi8BitMiniMap;
HVSURFACE ghVSurface = NULL;
RGBValues* p24BitValues = NULL;
FDLG_LIST* FListNode = NULL;
void GenerateAllMapsInit(void)
{
GETFILESTRUCT FileInfo;
TrashFDlgList(FileList);
if(GetFileFirst("MAPS\\*.dat", &FileInfo))
{
FileList = AddToFDlgList(FileList, &FileInfo);
while(GetFileNext(&FileInfo))
FileList = AddToFDlgList(FileList, &FileInfo);
GetFileClose(&FileInfo);
}
FListNode = FileList;
}
// Utililty file for sub-sampling/creating our radar screen maps.
// Loops through our maps directory and reads all *.map files, subsamples an area, color quantizes into an 8-bit image and writes to sti file in radarmaps.
// From editor will create radar map for you current map.
UINT32 MapUtilScreenInit(void)
{
UINT8 ubBitDepth;
UINT16 usWidth, usHeight;
VSURFACE_DESC vs_desc;
// Create render buffer
GetCurrentVideoSettings(&usWidth, &usHeight, &ubBitDepth);
vs_desc.fCreateFlags = VSURFACE_CREATE_DEFAULT | VSURFACE_SYSTEM_MEM_USAGE;
vs_desc.usWidth = MINIMAP_X_SIZE;
vs_desc.usHeight = MINIMAP_Y_SIZE;
vs_desc.ubBitDepth = ubBitDepth;
if(AddVideoSurface(&vs_desc, (UINT32*)&giMiniMap) == FALSE)
return(ERROR_SCREEN);
// Allocate 24 bit Surface
p24BitValues = (RGBValues*)MemAlloc(MINIMAP_X_SIZE * MINIMAP_Y_SIZE * sizeof(RGBValues));
//Allocate 8-bit surface
vs_desc.fCreateFlags = VSURFACE_CREATE_DEFAULT | VSURFACE_SYSTEM_MEM_USAGE;
vs_desc.usWidth = MINIMAP_X_SIZE;
vs_desc.usHeight = MINIMAP_Y_SIZE;
vs_desc.ubBitDepth = 8;
if(AddVideoSurface(&vs_desc, (UINT32*)&gi8BitMiniMap) == FALSE)
return(ERROR_SCREEN);
GetVideoSurface(&ghVSurface, gi8BitMiniMap);
return(TRUE);
}
UINT32 MapUtilScreenHandle(void)
{
InputAtom InputEvent;
SGPPaletteEntry pPalette[256];
CHAR8 zFilename[260], zFilename2[260];
UINT8 *pDataPtr;
UINT16 *pDestBuf, *pSrcBuf;
UINT32 uiDestPitchBYTES, uiSrcPitchBYTES, uiRGBColor, bR, bG, bB, bAvR, bAvG, bAvB;
INT16 s16BPPSrc, sDest16BPPColor, sX1, sX2, sY1, sY2, sTop, sBottom, sLeft, sRight;
INT32 cnt, iX, iY, iSubX1, iSubY1, iSubX2, iSubY2, iWindowX, iWindowY, iCount;
FLOAT dX, dY, dStartX, dStartY;
while(DequeueSpecificEvent(&InputEvent, KEY_DOWN|KEY_UP) == TRUE)
{
if(InputEvent.usParam == ESC)
{
// Exit the program
if(fEditModeFirstTime == FALSE)
{
TrashFDlgList(FileList);
FileList = FListNode = NULL;
return(EDIT_SCREEN);
}
else
{
gfProgramIsRunning = FALSE;
return(MAPUTILITY_SCREEN);
}
}
}
sDest16BPPColor = -1;
bAvR = bAvG = bAvB = 0;
// Zero out area!
ColorFillVideoSurfaceArea(FRAME_BUFFER, 0, 0, (INT16)(SCREEN_WIDTH), (INT16)(SCREEN_HEIGHT), Get16BPPColor(FROMRGB(0, 0, 0)));
if(fEditModeFirstTime == FALSE && gfWorldLoaded && FListNode == NULL)// Just create radarmap for current loaded world
sprintf(zFilename, "%s", gubFilename);
else
{
// OK, we are here, now loop through files
if(FListNode == NULL)
{
gfProgramIsRunning = FALSE;
return(MAPUTILITY_SCREEN);
}
sprintf(zFilename, "%s", FListNode->FileInfo.zFileName);
// OK, load maps and do overhead shrinkage of them...
if(!LoadWorld(zFilename))
return(ERROR_SCREEN);
}
// Render small map
iOffsetHorizontal = (SCREEN_WIDTH / 2) - (640 / 2);// Horizontal start postion of the overview map
iOffsetVertical = (SCREEN_HEIGHT - 160) / 2 - 160;// Vertical start position of the overview map
InitNewOverheadDB((UINT8)giCurrentTilesetID);
gfOverheadMapDirty = TRUE;
RenderOverheadMap(0, (WORLD_COLS/2), iOffsetHorizontal, iOffsetVertical, iOffsetHorizontal+640, iOffsetVertical+320, TRUE);
TrashOverheadMap();
// OK, NOW PROCESS OVERHEAD MAP ( SHOUIDL BE ON THE FRAMEBUFFER )
gdXStep = (FLOAT)640 / (FLOAT)MINIMAP_X_SIZE;
gdYStep = (FLOAT)320 / (FLOAT)MINIMAP_Y_SIZE;
dStartX = iOffsetHorizontal;
dStartY = iOffsetVertical;
// Adjust if we are using a restricted map...
if(gMapInformation.ubRestrictedScrollID != 0)
{
CalculateRestrictedMapCoords(NORTH, &sX1, &sY1, &sX2, &sTop, iOffsetHorizontal+640, iOffsetVertical+320);
CalculateRestrictedMapCoords(SOUTH, &sX1, &sBottom, &sX2, &sY2, iOffsetHorizontal+640, iOffsetVertical+320);
CalculateRestrictedMapCoords(WEST, &sX1, &sY1, &sLeft, &sY2, iOffsetHorizontal+640, iOffsetVertical+320);
CalculateRestrictedMapCoords(EAST, &sRight, &sY1, &sX2, &sY2, iOffsetHorizontal+640, iOffsetVertical+320);
gdXStep = (FLOAT)(sRight - sLeft) / (FLOAT)MINIMAP_X_SIZE;
gdYStep = (FLOAT)(sBottom - sTop) / (FLOAT)MINIMAP_Y_SIZE;
dStartX = sLeft;
dStartY = sTop;
}
//LOCK BUFFERS
dX = dStartX;
dY = dStartY;
pDestBuf = (UINT16*)LockVideoSurface(giMiniMap, &uiDestPitchBYTES);
pSrcBuf = (UINT16*)LockVideoSurface(FRAME_BUFFER, &uiSrcPitchBYTES);
for ( iX = 0; iX < MINIMAP_X_SIZE; iX++ )
{
dY = dStartY;
for ( iY = 0; iY < MINIMAP_Y_SIZE; iY++ )
{
//OK, AVERAGE PIXELS
iSubX1 = (INT32)dX - WINDOW_SIZE;
iSubX2 = (INT32)dX + WINDOW_SIZE;
iSubY1 = (INT32)dY - WINDOW_SIZE;
iSubY2 = (INT32)dY + WINDOW_SIZE;
iCount = 0;
bR = bG = bB = 0;
for ( iWindowX = iSubX1; iWindowX < iSubX2; iWindowX++ )
{
for ( iWindowY = iSubY1; iWindowY < iSubY2; iWindowY++ )
{
if ( iWindowX >= iOffsetHorizontal && iWindowX < (iOffsetHorizontal+640) && iWindowY >= iOffsetVertical && iWindowY < (iOffsetVertical+320) )
{
s16BPPSrc = pSrcBuf[ ( iWindowY * (uiSrcPitchBYTES/2) ) + iWindowX ];
uiRGBColor = GetRGBColor( s16BPPSrc );
bR += SGPGetRValue( uiRGBColor );
bG += SGPGetGValue( uiRGBColor );
bB += SGPGetBValue( uiRGBColor );
// Average!
iCount++;
}
}
}
if ( iCount > 0 )
{
bAvR = bR / (UINT8)iCount;
bAvG = bG / (UINT8)iCount;
bAvB = bB / (UINT8)iCount;
sDest16BPPColor = Get16BPPColor( FROMRGB( bAvR, bAvG, bAvB ) );
}
//Write into dest!
pDestBuf[ ( iY * (uiDestPitchBYTES/2) ) + iX ] = sDest16BPPColor;
p24BitValues[ ( iY * (uiDestPitchBYTES/2) ) + iX ].r = (UINT8)bAvR;
p24BitValues[ ( iY * (uiDestPitchBYTES/2) ) + iX ].g = (UINT8)bAvG;
p24BitValues[ ( iY * (uiDestPitchBYTES/2) ) + iX ].b = (UINT8)bAvB;
//Increment
dY += gdYStep;
}
//Increment
dX += gdXStep;
}
UnLockVideoSurface(giMiniMap);
UnLockVideoSurface(FRAME_BUFFER);
// RENDER!
BltVideoSurface(FRAME_BUFFER, giMiniMap, 0, iOffsetHorizontal+10, iOffsetVertical+360, VS_BLT_FAST|VS_BLT_USECOLORKEY, NULL);
//QUantize!
pDataPtr = (UINT8*)LockVideoSurface(gi8BitMiniMap, &uiSrcPitchBYTES);
pDestBuf = (UINT16*)LockVideoSurface(FRAME_BUFFER, &uiDestPitchBYTES);
QuantizeImage(pDataPtr, (UINT8*)p24BitValues, MINIMAP_X_SIZE, MINIMAP_Y_SIZE, pPalette);
SetVideoSurfacePalette(ghVSurface, pPalette);
// Blit!
Blt8BPPDataTo16BPPBuffer(pDestBuf, uiDestPitchBYTES, ghVSurface, pDataPtr, iOffsetHorizontal+10+MINIMAP_X_SIZE+20, iOffsetVertical+360);
// Write palette!
iX = iOffsetHorizontal + 10;
iY = iOffsetVertical + 420;
SetClippingRegionAndImageWidth(uiDestPitchBYTES, 0, 0, iOffsetHorizontal+640, iOffsetVertical+480);
for(cnt=0; cnt<256; cnt++)
{
UINT16 usLineColor = Get16BPPColor(FROMRGB(pPalette[cnt].peRed, pPalette[cnt].peGreen, pPalette[cnt].peBlue));
RectangleDraw(TRUE, iX, iY, iX, (INT16)(iY+10), usLineColor, (UINT8*)pDestBuf);
iX++;
RectangleDraw(TRUE, iX, iY, iX, (INT16)(iY+10), usLineColor, (UINT8*)pDestBuf);
iX++;
}
UnLockVideoSurface(FRAME_BUFFER);
// Remove extension
for(cnt=strlen(zFilename)-1; cnt>=0; cnt--)
if(zFilename[cnt] == '.')
zFilename[cnt] = '\0';
sprintf(zFilename2, "RADARMAPS\\%s.STI", zFilename);
WriteSTIFile((INT8*)pDataPtr, pPalette, MINIMAP_X_SIZE, MINIMAP_Y_SIZE, (STR)zFilename2, CONVERT_ETRLE_COMPRESS, 0);
UnLockVideoSurface(gi8BitMiniMap);
SetFont(TINYFONT1);
SetFontBackground(FONT_MCOLOR_BLACK);
SetFontForeground(FONT_MCOLOR_DKGRAY);
mprintf(iOffsetHorizontal+10, iOffsetVertical+330, L"Writing radar image %S", zFilename2);
mprintf(iOffsetHorizontal+10, iOffsetVertical+340, L"Using tileset %s", gTilesets[giCurrentTilesetID].zName);
InvalidateScreen();
// Set next
if(FListNode)
FListNode = FListNode->pNext;
if(fEditModeFirstTime == FALSE && FListNode == NULL)
return(EDIT_SCREEN);
return(MAPUTILITY_SCREEN);
}
UINT32 MapUtilScreenShutdown(void)
{
TrashFDlgList(FileList);
MemFree(p24BitValues);
return(TRUE);
}
#else //non-editor version
#include "types.h"
#include "screenids.h"
UINT32 MapUtilScreenInit( )
{
return( TRUE );
}
UINT32 MapUtilScreenHandle( )
{
//If this screen ever gets set, then this is a bad thing -- endless loop
return( ERROR_SCREEN );
}
UINT32 MapUtilScreenShutdown( )
{
return( TRUE );
}
#endif