Home » MODDING HQ 1.13 » Flugente's Magika Workshop » New feature: individual militia
Individual Militia Bug Fix (DEV - 8551)[message #353051 is a reply to message #345324]
|
Wed, 11 April 2018 07:53
|
|
RunAwayScientist |
|
Messages:84
Registered:September 2001 |
|
|
DEV BUILD - 8551
Hello everyone & Flugente,
I've tracked down the issue with mobile militia entering loaded sectors and will be submitting this to the BugFixes thread in addition to here. It took about 30 minutes of working through the MoveIndividualMilitia functions but it appears to be a missing MoveIndividualMilitiaProfiles(); func call in a if/elseif/else chain, that's all.
Corrected code below:
[[ Strategic Movement.cpp ]] { BUGGED CODE } :
Toggle Spoiler
// Flugente: if a militia group has reached its final destination, add them to the current sector
if ( pGroup && pGroup->usGroupTeam == MILITIA_TEAM )
{
// if they arrive in the sector we have currently loaded, let them join from the edge
// this will always remove them from the group - if you want them to continue moving, issue a new order
if ( pGroup->ubSectorX == gWorldSectorX && pGroup->ubSectorY == gWorldSectorY && pGroup->ubSectorZ == gbWorldSectorZ )
{
MilitiaGroupEntersCurrentSector( pGroup->ubGroupID, pGroup->ubSectorX, pGroup->ubSectorY );
if ( !fBattlePending && GroupAtFinalDestination( pGroup ) )
{
// once militia have arrived, move them from the group to the sector
DissolveMilitiaGroup( pGroup->ubGroupID );
}
}
[[ Strategic Movement.cpp ]] { CORRECTED CODE } :
Toggle Spoiler
// Flugente: if a militia group has reached its final destination, add them to the current sector
if ( pGroup && pGroup->usGroupTeam == MILITIA_TEAM )
{
// if they arrive in the sector we have currently loaded, let them join from the edge
// this will always remove them from the group - if you want them to continue moving, issue a new order
// RunAwayScientist fix on 4/10/2018: The below condition needs to have the other functions applied (MoveMilitiaEquipment, MoveMilitiaProfiles, reset)
// because the other if-else sections do NOT trigger if milita move into currently loaded sector.
// This should be done before dissolving the group.
// Currently only MoveMilitiaProfiles is needed, equipment is moved without being called from another func.
if ( pGroup->ubSectorX == gWorldSectorX && pGroup->ubSectorY == gWorldSectorY && pGroup->ubSectorZ == gbWorldSectorZ )
{
ScreenMsg( FONT_MCOLOR_LTYELLOW, MSG_INTERFACE, L"CONDITION CHECKING LOADED SECTOR ACTIVATED" );
MilitiaGroupEntersCurrentSector( pGroup->ubGroupID, pGroup->ubSectorX, pGroup->ubSectorY );
// Flugente: move along individual militia data
MoveIndividualMilitiaProfiles( SECTOR( pGroup->ubPrevX, pGroup->ubPrevY ), SECTOR( pGroup->ubSectorX, pGroup->ubSectorY ), pGroup->pEnemyGroup->ubNumAdmins, pGroup->pEnemyGroup->ubNumTroops, pGroup->pEnemyGroup->ubNumElites );
if ( !fBattlePending && GroupAtFinalDestination( pGroup ) )
{
// once militia have arrived, move them from the group to the sector
DissolveMilitiaGroup( pGroup->ubGroupID );
// for safety, reset if necessary
ResetMilitia( );
}
}
(( This is optional, but I commented out the redunant 'Catch-All' feature that creates new militia profiles if none are detected in the sector. This caused more problems than it solved, and most people start new games or have updated their old game already. I highly recommend disabling the redunant 'Catch-All'.
There's a second 'Catch-All' in the FOR loop, which has only a 'return;', which may cause problems if it's ever triggered. That has also been commented out. ))
[[ Militia Individual.cpp ]] { BUGGED CODE } :
Toggle Spoiler
// search for a individual militia that is alive and not currently in use in this sector, and return its id
// if none is found, create new and return that one
UINT32 GetIdOfUnusedIndividualMilitia( UINT8 aSoldierClass, UINT8 aSector )
{
if ( !gGameExternalOptions.fIndividualMilitia )
return 0;
UINT8 militialevel = SoldierClassToMilitiaRank( aSoldierClass );
std::vector<MILITIA>::iterator itend = gIndividualMilitiaVector.end();
for ( std::vector<MILITIA>::iterator it = gIndividualMilitiaVector.begin( ); it != itend; ++it )
{
if ( !((*it).flagmask & (MILITIAFLAG_DEAD | MILITIAFLAG_FIRED | MILITIAFLAG_DESERTION )) && (*it).sector == aSector && (*it).militiarank == militialevel )
{
// fitting data found - now we have to make sure this one isn't already in use
BOOLEAN found = FALSE;
SOLDIERTYPE* pSoldier;
INT32 cnt = gTacticalStatus.Team[MILITIA_TEAM].bFirstID;
INT32 lastid = gTacticalStatus.Team[MILITIA_TEAM].bLastID;
for (pSoldier = MercPtrs[cnt]; cnt < lastid; ++cnt, ++pSoldier)
{
if (pSoldier && pSoldier->bActive && (*it).id == pSoldier->usIndividualMilitiaID && IsLegalMilitiaId(pSoldier->usIndividualMilitiaID) )
{
found = TRUE;
break;
}
}
if ( !found && IndividualMilitiaInUse_AutoResolve((*it).id))
{
found = TRUE;
}
if (!found)
{
return (*it).id;
}
}
}
// if this feature is on and we get to this point, then there aren't enough individual militia. This is odd, the player should be informed
// if ( gGameExternalOptions.fIndividualMilitia )
ScreenMsg( FONT_MCOLOR_RED, MSG_INTERFACE, L"Possible error: Not enough individual militia found in GetIdOfUnusedindividualMilitia" );
// nobody found. That shouldn't really happen, as we are supposed to create data whenever new militia is created. Create new data and use that
return CreateNewIndividualMilitia( militialevel, MO_ARULCO, aSector );
}
--^--^--^--^--^--^--^--^--^--^--^--^--^--^--^--^--^--^--^--^--^--^--^--^--^--^--^--^--^--^--^--^--^--^--^--^
void MoveIndividualMilitiaProfiles( UINT8 aSourceSector, UINT8 aTargetSector, UINT8 usGreens, UINT8 usRegulars, UINT8 usElites )
{
std::vector<MILITIA>::iterator itend = gIndividualMilitiaVector.end( );
for ( std::vector<MILITIA>::iterator it = gIndividualMilitiaVector.begin( ); it != itend; ++it )
{
if ( !usGreens && !usRegulars && !usElites )
return;
if ( !((*it).flagmask & (MILITIAFLAG_DEAD | MILITIAFLAG_FIRED | MILITIAFLAG_DESERTION )) && (*it).sector == aSourceSector )
{
if ( usGreens && ( *it ).militiarank == GREEN_MILITIA)
{
(*it).sector = aTargetSector;
--usGreens;
}
else if ( usRegulars && (*it).militiarank == REGULAR_MILITIA)
{
(*it).sector = aTargetSector;
--usRegulars;
}
else if ( usElites && (*it).militiarank == ELITE_MILITIA)
{
(*it).sector = aTargetSector;
--usElites;
}
}
}
// if this feature is on and we get to this point, then there aren't enough individual militia. This is odd, the player should be informed
if ( (usGreens + usRegulars + usElites) && gGameExternalOptions.fIndividualMilitia )
ScreenMsg( FONT_MCOLOR_RED, MSG_INTERFACE, L"Possible error: Not enough individual militia found in MoveIndividualMilitiaProfiles" );
}
}
[[ Militia Individual.cpp ]] { CORRECTED CODE } :
Toggle Spoiler
// search for a individual militia that is alive and not currently in use in this sector, and return its id
// if none is found, create new and return that one
UINT32 GetIdOfUnusedIndividualMilitia( UINT8 aSoldierClass, UINT8 aSector )
{
if ( !gGameExternalOptions.fIndividualMilitia )
return 0;
UINT8 militialevel = SoldierClassToMilitiaRank( aSoldierClass );
std::vector<MILITIA>::iterator itend = gIndividualMilitiaVector.end();
for ( std::vector<MILITIA>::iterator it = gIndividualMilitiaVector.begin( ); it != itend; ++it )
{
if ( !((*it).flagmask & (MILITIAFLAG_DEAD | MILITIAFLAG_FIRED | MILITIAFLAG_DESERTION )) && (*it).sector == aSector && (*it).militiarank == militialevel )
{
// fitting data found - now we have to make sure this one isn't already in use
BOOLEAN found = FALSE;
SOLDIERTYPE* pSoldier;
INT32 cnt = gTacticalStatus.Team[MILITIA_TEAM].bFirstID;
INT32 lastid = gTacticalStatus.Team[MILITIA_TEAM].bLastID;
for (pSoldier = MercPtrs[cnt]; cnt < lastid; ++cnt, ++pSoldier)
{
if (pSoldier && pSoldier->bActive && (*it).id == pSoldier->usIndividualMilitiaID && IsLegalMilitiaId(pSoldier->usIndividualMilitiaID) )
{
found = TRUE;
break;
}
}
if ( !found && IndividualMilitiaInUse_AutoResolve((*it).id))
{
found = TRUE;
}
if (!found)
{
return (*it).id;
}
}
}
// if this feature is on and we get to this point, then there aren't enough individual militia. This is odd, the player should be informed
// if ( gGameExternalOptions.fIndividualMilitia )
ScreenMsg( FONT_MCOLOR_RED, MSG_INTERFACE, L"Possible error: Not enough individual militia found in GetIdOfUnusedindividualMilitia" );
// RunAwayScientist fix on 4/11/2018 - Creating new profiles when there's a bug duplicates orphaned militia that cannot be disbanded. We either need a clean-up method or the player can just move his militia back to the sector where they were orphaned to fix.
// nobody found. That shouldn't really happen, as we are supposed to create data whenever new militia is created. Create new data and use that
// return CreateNewIndividualMilitia( militialevel, MO_ARULCO, aSector );
}
--^--^--^--^--^--^--^--^--^--^--^--^--^--^--^--^--^--^--^--^--^--^--^--^--^--^--^--^--^--^--^--^--^--^--^--^
void MoveIndividualMilitiaProfiles( UINT8 aSourceSector, UINT8 aTargetSector, UINT8 usGreens, UINT8 usRegulars, UINT8 usElites )
{
std::vector<MILITIA>::iterator itend = gIndividualMilitiaVector.end( );
for ( std::vector<MILITIA>::iterator it = gIndividualMilitiaVector.begin( ); it != itend; ++it )
{
// RunAwayScientist on 4/11/2018 - Redundant, the FOR loop should already catch end of vector. This may also cause a premature termination of the loop if 0's are fed to this function.
// if ( !usGreens && !usRegulars && !usElites )
// return;
if ( !((*it).flagmask & (MILITIAFLAG_DEAD | MILITIAFLAG_FIRED | MILITIAFLAG_DESERTION )) && (*it).sector == aSourceSector )
{
if ( usGreens && ( *it ).militiarank == GREEN_MILITIA)
{
(*it).sector = aTargetSector;
--usGreens;
}
else if ( usRegulars && (*it).militiarank == REGULAR_MILITIA)
{
(*it).sector = aTargetSector;
--usRegulars;
}
else if ( usElites && (*it).militiarank == ELITE_MILITIA)
{
(*it).sector = aTargetSector;
--usElites;
}
}
}
// if this feature is on and we get to this point, then there aren't enough individual militia. This is odd, the player should be informed
if ( (usGreens + usRegulars + usElites) && gGameExternalOptions.fIndividualMilitia )
ScreenMsg( FONT_MCOLOR_RED, MSG_INTERFACE, L"Possible error: Not enough individual militia found in MoveIndividualMilitiaProfiles" );
}
Thank you Flug or whoever who corrected the scope issues relating to recruiting militia. This combined with the above bug fixes should effectively fix 90% of mobile milita issues.
Disbanding militia seems to work just fine. So far.
@GiantBasher: Your issue was related to the bug above. As some point you moved militia into a sector you had loaded and it duplicated the profiles and orphaned others. The only fix is to load a point BEFORE it happened or restart your game or hex your save file and remove them. You can also set 'Individual Militia' to FALSE in your JA2_Options.ini and then turn it back to TRUE, but they will still be there most likely.
There's some optional changes I'd like to recommend as well, such as disabling the 'Milita could not find gun to use, uses harsh language instead!' chat spam that happens whenever unarmed militia are moving around the map. This occurs in every sector movement, resulting in 180 messages for a stack of 60 unarmed militia over three sectors (for example).
[[ Militia Individual.cpp ]] { ORIGINAL CODE } :
Toggle Spoiler
ScreenMsg( FONT_MCOLOR_LTYELLOW, MSG_INTERFACE, L"Militia found no gun to equip, uses harsh langugage instead!" );
}
}
// we didn't find any gun at all. Now what?
else
{
si[SI_GUN].done = TRUE;
ScreenMsg( FONT_MCOLOR_LTYELLOW, MSG_INTERFACE, L"Militia found no gun to equip, uses harsh langugage instead!" );
}
[[ Militia Individual.cpp ]] { CHANGED CODE } :
Toggle Spoiler
// RunAwayScientist on 4/11/2018 - Disabled no gun messages.
// ScreenMsg( FONT_MCOLOR_LTYELLOW, MSG_INTERFACE, L"Militia found no gun to equip, uses harsh langugage instead!" );
}
}
// we didn't find any gun at all. Now what?
else
{
si[SI_GUN].done = TRUE;
// ScreenMsg( FONT_MCOLOR_LTYELLOW, MSG_INTERFACE, L"Militia found no gun to equip, uses harsh langugage instead!" );
}
One more problem remains: There is one more bug to fix and it's related to militia in a group traveling into the same sector in which mercs arrived and the sector is occupied by enemies. If this occurs, the militia DO NOT equip any inventory they had with them and will be unarmed for combat when they arrive at the sector edge. I assume this is also a very easy fix, anyone who knows what function call or method directly affects this please check it out or submit to trunk. I'd love you long time.
.
Report message to a moderator
|
|
|
|
|
|
New feature: individual militia
|
|
|
Re: New feature: individual militia
|
|
|
Re: New feature: individual militia
|
|
|
Re: New feature: individual militia
|
|
|
Re: New feature: individual militia
By: Panzer on Fri, 06 May 2016 21:30
|
|
|
Re: New feature: individual militia
|
|
|
Re: New feature: individual militia
|
|
|
Re: New feature: individual militia
|
|
|
Re: New feature: individual militia
By: ratpaz on Fri, 20 May 2016 04:03
|
|
|
Re: New feature: individual militia
|
|
|
Re: New feature: individual militia
By: ratpaz on Sat, 21 May 2016 21:47
|
|
|
Re: New feature: individual militia
|
|
|
Re: New feature: individual militia
By: ratpaz on Sun, 22 May 2016 14:35
|
|
|
Re: New feature: individual militia
|
|
|
Re: New feature: individual militia
|
|
|
Re: New feature: individual militia
By: 3iff on Mon, 23 May 2016 10:06
|
|
|
Re: New feature: individual militia
By: ratpaz on Mon, 23 May 2016 14:51
|
|
|
Re: New feature: individual militia
By: 3iff on Wed, 25 May 2016 10:15
|
|
|
Re: New feature: individual militia
|
|
|
Re: New feature: individual militia
By: 3iff on Thu, 26 May 2016 11:49
|
|
|
Re: New feature: individual militia
By: Uriens on Fri, 03 June 2016 13:24
|
|
|
Re: New feature: individual militia
By: Elvis_A on Wed, 06 July 2016 20:03
|
|
|
Re: New feature: individual militia
|
|
|
Re: New feature: individual militia
By: Elvis_A on Wed, 06 July 2016 21:16
|
|
|
Re: New feature: individual militia
|
|
|
Re: New feature: individual militia
By: Elvis_A on Wed, 06 July 2016 22:45
|
|
|
Re: New feature: individual militia
|
|
|
Re: New feature: individual militia
By: ratpaz on Sun, 17 July 2016 00:30
|
|
|
Re: New feature: individual militia
|
|
|
Re: New feature: individual militia
By: ratpaz on Sun, 17 July 2016 10:13
|
|
|
Re: New feature: individual militia
|
|
|
Re: New feature: individual militia
|
|
|
Re: New feature: individual militia
|
|
|
Re: New feature: individual militia
By: ratpaz on Sun, 17 July 2016 17:45
|
|
|
Re: New feature: individual militia
|
|
|
Re: New feature: individual militia
|
|
|
Re: New feature: individual militia
By: ratpaz on Tue, 19 July 2016 14:33
|
|
|
Re: New feature: individual militia
|
|
|
Re: New feature: individual militia
|
|
|
Re: New feature: individual militia
By: ratpaz on Wed, 20 July 2016 07:46
|
|
|
Re: New feature: individual militia
By: Thor on Mon, 25 July 2016 20:25
|
|
|
Re: New feature: individual militia
|
|
|
Re: New feature: individual militia
By: Thor on Tue, 26 July 2016 02:00
|
|
|
Re: New feature: individual militia
By: ratpaz on Tue, 02 August 2016 09:05
|
|
|
Re: New feature: individual militia
By: Flugente on Tue, 02 August 2016 13:14
|
|
|
Re: New feature: individual militia
By: Inukshuk on Tue, 02 August 2016 16:38
|
|
|
Re: New feature: individual militia
By: ratpaz on Tue, 02 August 2016 21:07
|
|
|
Re: New feature: individual militia
By: Uriens on Sun, 07 August 2016 20:25
|
|
|
Re: New feature: individual militia
By: Boojum on Fri, 02 September 2016 06:30
|
|
|
Re: New feature: individual militia
|
|
|
Re: New feature: individual militia
By: Boojum on Fri, 02 September 2016 19:19
|
|
|
Re: New feature: individual militia
|
|
|
Re: New feature: individual militia
By: Boojum on Sat, 03 September 2016 09:52
|
|
|
Re: New feature: individual militia
|
|
|
Re: New feature: individual militia
By: Enneagon on Sat, 03 September 2016 13:47
|
|
|
Re: New feature: individual militia
By: Boojum on Sat, 03 September 2016 19:48
|
|
|
Re: New feature: individual militia
|
|
|
Re: New feature: individual militia
By: Elvis_A on Mon, 05 February 2018 08:35
|
|
|
Re: New feature: individual militia
By: Flugente on Sun, 04 March 2018 23:16
|
|
|
Re: New feature: individual militia
|
|
|
Re: New feature: individual militia
By: Flugente on Mon, 14 November 2016 01:04
|
|
|
Re: New feature: individual militia
|
|
|
Re: New feature: individual militia
|
|
|
Re: New feature: individual militia
By: Flugente on Fri, 13 January 2017 20:42
|
|
|
Re: New feature: individual militia
|
|
|
Re: New feature: individual militia
By: Flugente on Fri, 13 January 2017 21:46
|
|
|
Re: New feature: individual militia
|
|
|
Re: New feature: individual militia
By: Flugente on Fri, 13 January 2017 22:23
|
|
|
Re: New feature: individual militia
|
|
|
Re: New feature: individual militia
By: Flugente on Sat, 14 January 2017 02:22
|
|
|
Re: New feature: individual militia
|
|
|
Re: New feature: individual militia
By: Flugente on Sat, 14 January 2017 02:34
|
|
|
Re: New feature: individual militia
|
|
|
Re: New feature: individual militia
By: Flugente on Sat, 14 January 2017 02:53
|
|
|
Re: New feature: individual militia
By: Hawkeye on Sun, 15 January 2017 04:08
|
|
|
Re: New feature: individual militia
|
|
|
Re: New feature: individual militia
By: Flugente on Wed, 25 January 2017 21:19
|
|
|
Re: New feature: individual militia
|
|
|
Re: New feature: individual militia
By: Hawkeye on Sat, 14 January 2017 02:59
|
|
|
Re: New feature: individual militia
|
|
|
Re: New feature: individual militia
|
|
|
Re: New feature: individual militia
|
|
|
Re: New feature: individual militia
|
|
|
Re: New feature: individual militia
By: Flugente on Thu, 21 September 2017 21:40
|
|
|
Re: New feature: individual militia
|
|
|
Re: New feature: individual militia
By: Flugente on Thu, 05 October 2017 23:01
|
|
|
Re: New feature: individual militia
|
|
|
Re: New feature: individual militia
|
|
|
Re: New feature: individual militia
By: Shadow on Fri, 12 January 2018 23:59
|
|
|
Re: New feature: individual militia
By: LatZee on Thu, 22 March 2018 10:41
|
|
|
Re: New feature: individual militia
|
|
|
Re: New feature: individual militia
By: Flugente on Thu, 12 April 2018 21:44
|
|
|
Re: New feature: individual militia
By: LatZee on Fri, 13 April 2018 02:50
|
|
|
Re: New feature: individual militia
|
|
|
Re: New feature: individual militia
By: Flugente on Fri, 13 April 2018 03:39
|
|
|
Re: New feature: individual militia
By: Flugente on Sat, 14 April 2018 17:32
|
|
|
Re: New feature: individual militia
|
|
|
Re: New feature: individual militia
By: Flugente on Thu, 19 April 2018 22:27
|
|
|
Re: New feature: individual militia
|
|
|
Re: New feature: individual militia
|
|
|
Individual Militia Bug Fix (DEV - 8551)
|
Goto Forum:
Current Time: Mon Dec 02 15:40:18 GMT+2 2024
Total time taken to generate the page: 0.02338 seconds
|