Skip to content

Commit

Permalink
Reallocated equipment retains turreted status
Browse files Browse the repository at this point in the history
Comment out non-functioning crit loc snapshot code
  • Loading branch information
lbmaian committed Dec 7, 2023
1 parent 0fbb9c0 commit 0e8d8a4
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 243 deletions.
117 changes: 36 additions & 81 deletions sswlib/src/main/java/components/BipedLoadout.java
Original file line number Diff line number Diff line change
Expand Up @@ -3163,21 +3163,42 @@ public boolean IsAllocated( abPlaceable p ) {

// Private Methods
private void Allocate( abPlaceable p, int SIndex, abPlaceable[] Loc ) throws Exception {
class RemoveEntry {
abPlaceable p;
boolean rear;
ifTurret turret;

RemoveEntry( int AddInLoc, int i ) {
// we've already ensured that it is not location locked
// above, so put the item back into the queue.
p = Loc[i];
rear = p.IsMountedRear();
turret = p.GetTurret();
if( p.CanSplit() && p.Contiguous() ) {
UnallocateAll( Loc[i], false );
} else {
UnallocateByIndex( AddInLoc, Loc );
}
}
}

// Adds the specified placeable to the given location at the specified
// stating index. Throws Exceptions with error messages if things went
// wrong.

if (p instanceof Equipment) {
((Equipment) p).ValidateMaxPerLocation(Loc);
}

// TODO: this snapshot thing doesn't work (see its usage below), commented out for now
// Let's get a snapshot of the location so we can reset it if we have to.
abPlaceable SnapShot[] = Loc.clone();
//abPlaceable SnapShot[] = Loc.clone();

// we have to accomodate for Artemis IV systems
boolean AddIn = false;
boolean ArrayGood = false;
int AddInSize = 1;
ArrayList removed = new ArrayList(), rears = new ArrayList();
ArrayList<RemoveEntry> removed = new ArrayList<>();

// check for generic placement
if( SIndex == -1 ) {
Expand Down Expand Up @@ -3290,17 +3311,7 @@ private void Allocate( abPlaceable p, int SIndex, abPlaceable[] Loc ) throws Exc
for( i = SIndex; i < ( p.NumCrits() + SIndex ); i++ ) {
// is there a non-location locked item there?
if( Loc[i] != NoItem ) {
// we've already ensured that it is not location locked
// above, so put the item back into the queue.
if( Loc[i].CanSplit() && Loc[i].Contiguous() ) {
removed.add( Loc[i] );
rears.add( new Boolean( Loc[i].IsMountedRear() ) );
UnallocateAll( Loc[i], false );
} else {
removed.add( Loc[i] );
rears.add( new Boolean( Loc[i].IsMountedRear() ) );
UnallocateByIndex( i, Loc );
}
removed.add( new RemoveEntry( i, i ) );
}
// finally, allocate the item slot
Loc[i] = p;
Expand All @@ -3311,67 +3322,27 @@ private void Allocate( abPlaceable p, int SIndex, abPlaceable[] Loc ) throws Exc
if( p instanceof RangedWeapon ) {
if( ((RangedWeapon) p).IsUsingFCS() ) {
if( Loc[AddInLoc] != NoItem ) {
// we've already ensured that it is not location locked
// above, so put the item back into the queue.
if( Loc[i].CanSplit() && Loc[i].Contiguous() ) {
removed.add( Loc[i] );
rears.add( new Boolean( Loc[i].IsMountedRear() ) );
UnallocateAll( Loc[i], false );
} else {
removed.add( Loc[i] );
rears.add( new Boolean( Loc[i].IsMountedRear() ) );
UnallocateByIndex( AddInLoc, Loc );
}
removed.add( new RemoveEntry( AddInLoc, i ) );
}
for( int j = AddInLoc; j < AddInSize + AddInLoc; j++ ) {
Loc[j] = (abPlaceable) ((RangedWeapon) p).GetFCS();
}
}
if( ((RangedWeapon) p).IsUsingCapacitor() ) {
if( Loc[AddInLoc] != NoItem ) {
// we've already ensured that it is not location locked
// above, so put the item back into the queue.
if( Loc[i].CanSplit() && Loc[i].Contiguous() ) {
removed.add( Loc[i] );
rears.add( new Boolean( Loc[i].IsMountedRear() ) );
UnallocateAll( Loc[i], false );
} else {
removed.add( Loc[i] );
rears.add( new Boolean( Loc[i].IsMountedRear() ) );
UnallocateByIndex( AddInLoc, Loc );
}
removed.add( new RemoveEntry( AddInLoc, i ) );
}
Loc[AddInLoc] = ((RangedWeapon) p).GetCapacitor();
}
if( ((RangedWeapon) p).IsUsingInsulator() ) {
if( Loc[AddInLoc] != NoItem ) {
// we've already ensured that it is not location locked
// above, so put the item back into the queue.
if( Loc[i].CanSplit() && Loc[i].Contiguous() ) {
removed.add( Loc[i] );
rears.add( new Boolean( Loc[i].IsMountedRear() ) );
UnallocateAll( Loc[i], false );
} else {
removed.add( Loc[i] );
rears.add( new Boolean( Loc[i].IsMountedRear() ) );
UnallocateByIndex( AddInLoc, Loc );
}
removed.add( new RemoveEntry( AddInLoc, i ) );
}
Loc[AddInLoc] = ((RangedWeapon) p).GetInsulator();
}
if( ((RangedWeapon) p).IsUsingPulseModule() ) {
if( Loc[AddInLoc] != NoItem ) {
// we've already ensured that it is not location locked
// above, so put the item back into the queue.
if( Loc[i].CanSplit() && Loc[i].Contiguous() ) {
removed.add( Loc[i] );
rears.add( new Boolean( Loc[i].IsMountedRear() ) );
UnallocateAll( Loc[i], false );
} else {
removed.add( Loc[i] );
rears.add( new Boolean( Loc[i].IsMountedRear() ) );
UnallocateByIndex( AddInLoc, Loc );
}
removed.add( new RemoveEntry( AddInLoc, i ) );
}
Loc[AddInLoc] = ((RangedWeapon) p).GetPulseModule();
}
Expand All @@ -3381,16 +3352,7 @@ private void Allocate( abPlaceable p, int SIndex, abPlaceable[] Loc ) throws Exc
if( p instanceof MGArray ) {
for( i = 0; i < ((MGArray) p).GetNumMGs(); i++ ) {
if( Loc[MGLocs[i]] != NoItem ) {
// we know it's not location locked, so kick it out
if( Loc[MGLocs[i]].CanSplit() && Loc[MGLocs[i]].Contiguous() ) {
removed.add( Loc[i] );
rears.add( new Boolean( Loc[i].IsMountedRear() ) );
UnallocateAll( Loc[MGLocs[i]], false );
} else {
removed.add( Loc[i] );
rears.add( new Boolean( Loc[i].IsMountedRear() ) );
UnallocateByIndex( MGLocs[i], Loc );
}
removed.add( new RemoveEntry( MGLocs[i], i ) );
}
Loc[MGLocs[i]] = ((MGArray) p).GetMGs()[i];
}
Expand All @@ -3408,16 +3370,7 @@ private void Allocate( abPlaceable p, int SIndex, abPlaceable[] Loc ) throws Exc

// if there is an item there, put it back in the queue
if( Loc[SIndex] != NoItem ) {
// put the item back into the queue
if( Loc[SIndex].CanSplit() && Loc[SIndex].Contiguous() ) {
removed.add( Loc[SIndex] );
rears.add( new Boolean( Loc[SIndex].IsMountedRear() ) );
UnallocateAll( Loc[SIndex], false );
} else {
removed.add( Loc[SIndex] );
rears.add( new Boolean( Loc[SIndex].IsMountedRear() ) );
UnallocateByIndex( SIndex, Loc );
}
removed.add( new RemoveEntry( SIndex, SIndex ) );
}

// now allocate the item.
Expand All @@ -3432,16 +3385,18 @@ private void Allocate( abPlaceable p, int SIndex, abPlaceable[] Loc ) throws Exc
}

// now that allocation is finished, add in the removed items if possible
for( int i = 0; i < removed.size(); i++ ) {
for( RemoveEntry remove : removed ) {
// no error handling here since the items are already in the queue
try {
Allocate( (abPlaceable) removed.get( i ), -1, Loc );
((abPlaceable) removed.get( i )).MountRear( ((Boolean) rears.get( i )));
Allocate( remove.p, -1, Loc );
remove.p.MountRear( remove.rear );
remove.p.MountTurret( remove.turret );
} catch( Exception e1 ) { }
}
} catch ( ArrayIndexOutOfBoundsException e ) {
// TODO: Following snapshot thing actually does nothing
// reset the location
Loc = SnapShot;
//Loc = SnapShot;

// tell the user what happened.
if( p instanceof RangedWeapon ) {
Expand Down
Loading

0 comments on commit 0e8d8a4

Please sign in to comment.