Brief: //dnl ch85

- Some fixing and adding position in overhead map to be in center of big map.
Details:
- Calculate overhead map cords from your current position on big maps.
- Fix incorrect placing room numbers in maps with cliffs.
- Fix CTD during deletion of sector items using CTRL+D or CTRL+Del.
- Remove light, door and item cursor and item tiles after coping building.


git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@6888 3b4a5df2-a311-0410-b5c6-a8a6f20db521
This commit is contained in:
Kriplo
2014-02-08 15:20:13 +00:00
parent 553171b717
commit ab5bfe2bf3
7 changed files with 125 additions and 15 deletions
+6
View File
@@ -410,6 +410,12 @@ void PasteBuilding( INT32 iMapIndex )
while( curr )
{
PasteMapElementToNewMapElement( curr->sGridNo, curr->sGridNo + iOffset );
//dnl ch85 070214
RemoveAllObjectsOfTypeRange(curr->sGridNo + iOffset, GOODRING, GOODRING);
RemoveAllTopmostsOfTypeRange(curr->sGridNo + iOffset, ROTATINGKEY, SELRING);
RemoveAllStructsOfTypeRange(curr->sGridNo + iOffset, GUNS, P2ITEMS);
RemoveAllStructsOfTypeRange(curr->sGridNo + iOffset, P3ITEMS, P3ITEMS);
RemoveAllStructsOfTypeRange(curr->sGridNo + iOffset, P4ITEMS, P20ITEMS);
curr = curr->next;
}
MarkWorldDirty();
@@ -285,7 +285,9 @@ void MapInventoryPoolFilterBtn( GUI_BUTTON *btn, INT32 reason );
void MapInventoryPoolFilterBtnMoveItemDisplay( GUI_BUTTON *btn, INT32 reason ); // Flugente
void DisplayCurrentSector( void );
void ResizeInventoryList( void );
#ifdef INVFIX_Moa//dnl ch85 050214
void ClearUpTempUnSeenList( void );
#endif
void SaveSeenAndUnseenItems( void );
void DrawTextOnMapInventoryBackground( void );
void DrawTextOnSectorInventory( void );
@@ -304,7 +306,9 @@ extern void MAPEndItemPointer( );
extern BOOLEAN GetCurrentBattleSectorXYZAndReturnTRUEIfThereIsABattle( INT16 *psSectorX, INT16 *psSectorY, INT16 *psSectorZ );
extern BOOLEAN MAPInternalInitItemDescriptionBox( OBJECTTYPE *pObject, UINT8 ubStatusIndex, SOLDIERTYPE *pSoldier );
#ifdef INVFIX_Moa//dnl ch85 050214
void DeleteAllItemsInInventoryPool();
#endif
void DeleteItemsOfType( UINT16 usItemType );
// HEADROCK HAM 5: flag to indicate that all items in the stack will be sold. This is primarily used to
// figure out the price of the top item in the stack rather than just all of them.
@@ -930,8 +934,7 @@ void CancelSectorInventoryDisplayIfOn( BOOLEAN fExitFromMapScreen )
}
}
#ifdef INVFIX_Moa//dnl ch85 050214
void ClearUpTempUnSeenList( void )//dnl ch75 271013
{
// save these items and all the others
@@ -941,6 +944,7 @@ void ClearUpTempUnSeenList( void )//dnl ch75 271013
pSaveList = pUnSeenItems;
pUnSeenItems.clear();
}
#endif
//////////////////////////////////////
//@brief Saves pSaveList and pInventoryPoolList either into file or into memmory.
@@ -2203,12 +2207,13 @@ void ReBuildWorldItemStashForLoadedSector( INT32 iNumberSeenItems, INT32 iNumber
SetNumberOfVisibleWorldItemsInSectorStructureForSector( gWorldSectorX, gWorldSectorY, gbWorldSectorZ , uiTotalNumberOfVisibleItems );
}
#ifdef INVFIX_Moa//dnl ch85 050214
void DestroyStash( void )
{
// clear out stash
pInventoryPoolList.clear();
}
#endif
void BeginInventoryPoolPtr( OBJECTTYPE *pInventorySlot )
{
@@ -3982,6 +3987,7 @@ BOOLEAN DisplaySectorItemsInfo(void)//dnl ch51 090913 //dnl ch75 021113
}
//dnl ch51 081009 finish
#ifdef INVFIX_Moa//dnl ch85 050214
void DeleteAllItemsInInventoryPool()
{
pInventoryPoolList.clear();
@@ -3997,7 +4003,7 @@ void DeleteAllItemsInInventoryPool()
DestroyStash();
BuildStashForSelectedSector( sSelMapX, sSelMapY, iCurrentMapSectorZ);
}
#endif
void DeleteItemsOfType( UINT16 usItemType )
{
+25 -2
View File
@@ -1014,8 +1014,9 @@ extern BOOLEAN CanRedistributeMilitiaInSector( INT16 sClickedSectorX, INT16 sCli
extern INT32 GetNumberOfMercsInUpdateList( void );
extern INT32 SellItem( OBJECTTYPE& object, BOOLEAN fAll, BOOLEAN useModifier = TRUE );
#ifdef INVFIX_Moa//dnl ch85 050214
void DeleteAllItemsInInventoryPool();
#endif
#ifdef JA2UB
void HandleWhenPlayerHasNoMercsAndNoLaptop();
#endif
@@ -1087,6 +1088,7 @@ void BeginDeleteAllCallBack( UINT8 bExitValue )
if( bExitValue == MSG_BOX_RETURN_YES )
{
fRestoreBackgroundForMessageBox = TRUE;
#ifdef INVFIX_Moa//dnl ch85 050214
if ( gpItemPointer != NULL || InSectorStackPopup( ) || InItemStackPopup( ) || InItemDescriptionBox( ) || InKeyRingPopup( ) )
{
return;
@@ -1107,6 +1109,12 @@ void BeginDeleteAllCallBack( UINT8 bExitValue )
}
}
}
#else
for(UINT32 i=0; i<pInventoryPoolList.size(); i++)
if(pInventoryPoolList[i].object.exists() && (pInventoryPoolList[i].usFlags & WORLD_ITEM_REACHABLE))
pInventoryPoolList[i].object.initialize();
}
#endif
}
// CHRISL: New functions to handle initialization of inventory coordinates
@@ -7026,13 +7034,20 @@ void GetMapKeyboardInput( UINT32 *puiNewEvent )
break;
case DEL:
#ifdef INVFIX_Moa//dnl ch85 050214
// show the inventory pool?
if( fShowMapInventoryPool && _KeyDown( CTRL ) )
{
DeleteAllItemsInInventoryPool();
break;
}
#else
if(fCtrl && fShowMapInventoryPool && !(gpItemPointer || InSectorStackPopup() || InItemStackPopup() || InItemDescriptionBox() || InKeyRingPopup()))
{
DoMessageBox(MSG_BOX_BASIC_STYLE, NewInvMessage[NIV_DELETE_ALL], guiCurrentScreen, (UINT8)MSG_BOX_FLAG_YESNO, BeginDeleteAllCallBack, NULL);
break;
}
#endif
// down one sublevel
GoDownOneLevelInMap( );
break;
@@ -7479,6 +7494,7 @@ void GetMapKeyboardInput( UINT32 *puiNewEvent )
break;
case 'D':
#ifdef INVFIX_Moa//dnl ch85 050214
if( fCtrl )
{
if ( !InSectorStackPopup( ) && !InItemStackPopup( ) && !InItemDescriptionBox( ) && !InKeyRingPopup( ) )
@@ -7496,6 +7512,13 @@ void GetMapKeyboardInput( UINT32 *puiNewEvent )
}
}
}
#else
if(fCtrl && fShowMapInventoryPool && !(gpItemPointer || InSectorStackPopup() || InItemStackPopup() || InItemDescriptionBox() || InKeyRingPopup()))
{
DoMessageBox(MSG_BOX_BASIC_STYLE, NewInvMessage[NIV_DELETE_ALL], guiCurrentScreen, (UINT8)MSG_BOX_FLAG_YESNO, BeginDeleteAllCallBack, NULL);
break;
}
#endif
break;
case 'e':
if( gfPreBattleInterfaceActive )
+4 -1
View File
@@ -4327,7 +4327,10 @@ void DebugSoldierPage2( )
SetFontColors(COLOR1);
mprintf( 0, LINE_HEIGHT * ubLine, L"GRIDNO:");
SetFontColors(COLOR2);
mprintf( 150, LINE_HEIGHT * ubLine, L"%d", usMapPos );
//dnl ch85 060214
INT16 sX, sY;
ConvertGridNoToXY(usMapPos, &sX, &sY);
mprintf( 150, LINE_HEIGHT * ubLine, L"%d (%d,%d)", usMapPos, sX, sY );
ubLine++;
if ( gpWorldLevelData[ usMapPos ].uiFlags & MAPELEMENT_MOVEMENT_RESERVED )
+77 -6
View File
@@ -118,6 +118,31 @@ void CopyOverheadDBShadetablesFromTileset( );
void RenderOverheadOverlays();
//dnl ch85 060214
#include <math.h>
#define PointToPointDist(X1, Y1, X2, Y2) (sqrtf((FLOAT)((X2-X1)*(X2-X1) + (Y2-Y1)*(Y2-Y1))))// Calculate distance between two points
#define PointToLineDist(Xt, Yt, k, l) (sqrtf((FLOAT)((k*Xt-Yt+l) * (k*Xt-Yt+l)) / (k*k + 1)))// Calculate distance between point and line
VOID PointFromDist(INT32 Xt, INT32 Yt, INT32 k, INT32 l, FLOAT d, INT32 *Xtnew, INT32 *Ytnew)// Calculate closest point to point (Xt,Yt) which lies at distance from line Y=kx+l and normal define by point (Xt,Yt)
{
FLOAT ret1 = sqrtf(d*d * (k*k + 1));
FLOAT ret2 = (FLOAT)(Yt + k*Xt);
FLOAT ret3 = (FLOAT)(2 * k);
FLOAT X1 = (ret1 + ret2 - l) / ret3;
FLOAT Y1 = -k*X1 + ret2;
FLOAT X2 = (-ret1 + ret2 - l) / ret3;
FLOAT Y2 = -k*X2 + ret2;
if(((Xt-X1)*(Xt-X1) + (Yt-Y1)*(Yt-Y1)) < ((Xt-X2)*(Xt-X2) + (Yt-Y2)*(Yt-Y2)))
{
*Xtnew = (INT32)(X1 + 0.5);
*Ytnew = (INT32)(Y1 + 0.5);
}
else
{
*Xtnew = (INT32)(X2 + 0.5);
*Ytnew = (INT32)(Y2 + 0.5);
}
}
void InitNewOverheadDB( UINT8 ubTilesetID )
{
UINT32 uiLoop;
@@ -582,7 +607,6 @@ void GoIntoOverheadMap( )
HVOBJECT hVObject;
gfInOverheadMap = TRUE;
//dnl??? ch45 021009 Add here moving overhead map cords to your current position on big map
//RestoreExternBackgroundRect( INTERFACE_START_X, INTERFACE_START_Y, SCREEN_WIDTH, INTERFACE_HEIGHT );
@@ -595,6 +619,53 @@ void GoIntoOverheadMap( )
}else{
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
//dnl ch85 060214 Calculate overhead map cords from your current position on big map
INT32 Xs, Ys, dX, dY, Xt, Yt, k, l, Xtnew, Ytnew;
FLOAT ddw = PointToPointDist(0, WORLD_ROWS/2, (0 + OLD_WORLD_COLS/2), (WORLD_ROWS/2 + OLD_WORLD_ROWS/2)) / 2;
FLOAT ddh = PointToPointDist(0, WORLD_ROWS/2, (0 + OLD_WORLD_COLS/2), (WORLD_ROWS/2 - OLD_WORLD_ROWS/2)) / 2;
Xt = gsRenderCenterX / CELL_X_SIZE;
Yt = gsRenderCenterY / CELL_Y_SIZE;
k = 1, l = (3*WORLD_ROWS-WORLD_COLS)/4;// p3
FLOAT dd = PointToLineDist(Xt, Yt, k, l);
if(dd < ddh)
{
PointFromDist(Xt, Yt, k, l, ddh, &Xtnew, &Ytnew);
Xt = Xtnew, Yt = Ytnew;
}
else
{
k = 1, l = (WORLD_ROWS-3*WORLD_COLS)/4;// p1
dd = PointToLineDist(Xt, Yt, k, l);
if(dd < ddh)
{
PointFromDist(Xt, Yt, k, l, ddh, &Xtnew, &Ytnew);
Xt = Xtnew, Yt = Ytnew;
}
}
k = -1, l = (WORLD_ROWS+WORLD_COLS)/4;// p4
dd = PointToLineDist(Xt, Yt, k, l);
if(dd < ddw)
{
PointFromDist(Xt, Yt, k, l, ddw, &Xtnew, &Ytnew);
Xt = Xtnew, Yt = Ytnew;
}
else
{
k = -1, l = 3*(WORLD_ROWS+WORLD_COLS)/4;// p1
dd = PointToLineDist(Xt, Yt, k, l);
if(dd < ddw)
{
PointFromDist(Xt, Yt, k, l, ddw, &Xtnew, &Ytnew);
Xt = Xtnew, Yt = Ytnew;
}
}
Xs = (giXB + giXC) / 2;
Ys = (giYB + giYC) / 2;
dX = Xt - Xs;
dY = Yt - Ys;
giXA += dX, giYA += dY;
giXB += dX, giYB += dY;
giXC += dX, giYC += dY;
}
if(WORLD_MAX == 129600){
if(NightTime()){
@@ -751,14 +822,14 @@ void ScrollOverheadMap(void)
gfValidLocationsChanged = TRUE;
gfTacticalPlacementGUIDirty = TRUE;
}
if(uiFlags & SCROLL_LEFT)// Scroll Left { Y = X + (3*WORLD_ROWS-WORLD_COLS)/4; --> p3 }
if(uiFlags & SCROLL_LEFT)// Scroll Left { Y = X + (3*WORLD_ROWS-WORLD_COLS)/4; --> p1 }
{
i = 1;
if(_KeyDown(SHIFT))
i = MAXSCROLL;
while(i--)
{
if(giYA == (giXA + (3*WORLD_ROWS-WORLD_COLS)/4))
if(giYA >= (giXA + (3*WORLD_ROWS-WORLD_COLS)/4))//dnl ch85 080214
break;
--giXA, ++giYA;
--giXB, ++giYB;
@@ -772,7 +843,7 @@ void ScrollOverheadMap(void)
i = MAXSCROLL;
while(i--)
{
if(giYC == (giXC + (WORLD_ROWS-3*WORLD_COLS)/4))
if(giYC <= (giXC + (WORLD_ROWS-3*WORLD_COLS)/4))//dnl ch85 080214
break;
++giXA, --giYA;
++giXB, --giYB;
@@ -786,7 +857,7 @@ void ScrollOverheadMap(void)
i = MAXSCROLL;
while(i--)
{
if(giYA == (-giXA + (WORLD_ROWS+WORLD_COLS)/4))
if(giYA <= (-giXA + (WORLD_ROWS+WORLD_COLS)/4))//dnl ch85 080214
break;
--giXA, --giYA;
--giXB, --giYB;
@@ -800,7 +871,7 @@ void ScrollOverheadMap(void)
i = MAXSCROLL;
while(i--)
{
if(giYB == (-giXB + 3*(WORLD_ROWS+WORLD_COLS)/4))
if(giYB >= (-giXB + 3*(WORLD_ROWS+WORLD_COLS)/4))//dnl ch85 080214
break;
++giXA, ++giYA;
++giXB, ++giYB;
+1 -1
View File
@@ -6486,7 +6486,7 @@ void RenderRoomInfo( INT16 sStartPointX_M, INT16 sStartPointY_M, INT16 sStartPoi
// THIS ROOM STUFF IS ONLY DONE IN THE EDITOR...
// ADJUST BY SHEIGHT
sY -= gpWorldLevelData[ usTileIndex ].sHeight;
//sY += gsRenderHeight;
sY += gsRenderHeight;//dnl ch85 030214
if ( gusWorldRoomInfo[ usTileIndex ] != NO_ROOM )
{
+2 -1
View File
@@ -2398,12 +2398,13 @@ void SetBlueFlagFlags( void )
void InitLoadedWorld( )
{
#ifndef JA2EDITOR//dnl ch85 030214 editor allows to load any map so rather skip this check
//if the current sector is not valid, dont init the world
if( gWorldSectorX == 0 || gWorldSectorY == 0 )
{
return;
}
#endif
// COMPILE MOVEMENT COSTS
CompileWorldMovementCosts( );