Skip to content

Commit

Permalink
Move omnivehicle turret tonnage check to pre-save tonnage validation
Browse files Browse the repository at this point in the history
Also improve validation error behavior a bit
  • Loading branch information
lbmaian committed Dec 11, 2023
1 parent 35a0523 commit 41d44a5
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 50 deletions.
49 changes: 34 additions & 15 deletions saw/src/main/java/saw/gui/frmVee.java
Original file line number Diff line number Diff line change
Expand Up @@ -5959,24 +5959,43 @@ private boolean VerifyVehicle( ActionEvent evt ) {
}

// ensure we're not overweight
ArrayList<ifCVLoadout> loadouts = new ArrayList<>();
if( CurVee.IsOmni() ) {
ArrayList v = CurVee.GetLoadouts();
for( int i = 0; i < v.size(); i++ ) {
CurVee.SetCurLoadout( ((ifCVLoadout) v.get( i )).GetName() );
if( CurVee.GetCurrentTons() > CurVee.GetTonnage() ) {
Media.Messager( this, ((ifCVLoadout) v.get( i )).GetName() +
" loadout is overweight. Reduce the weight\nto equal or below the Vehicle's tonnage." );
//cmbOmniVariant.setSelectedItem( ((ifCVLoadout) v.get( i )).GetName() );
//cmbOmniVariantActionPerformed( evt );
tbpMainTabPane.setSelectedComponent( pnlBasicSetup );
SetSource = true;
return false;
}
}
loadouts.addAll( CurVee.GetLoadouts() );
} else {
loadouts.add( null );
}
for( ifCVLoadout loadout : loadouts ) {
String name;
JPanel panel;
if( loadout == null ) {
name = "This Vehicle";
panel = pnlBasicSetup;
} else {
name = loadout.GetName() + " loadout";
CurVee.SetCurLoadout( loadout.GetName() );
panel = pnlEquipment;
}
if( CurVee.GetCurrentTons() > CurVee.GetTonnage() ) {
Media.Messager( this, "This Vehicle is overweight. Reduce the weight to\nequal or below the Vehicle's tonnage." );
tbpMainTabPane.setSelectedComponent( pnlBasicSetup );
Media.Messager( this, name + " is overweight.\n" +
"Reduce the weight to equal or below the Vehicle's tonnage." );
tbpMainTabPane.setSelectedComponent( panel );
SetSource = true;
return false;
}
Turret turret = CurVee.GetLoadout().GetTurret();
if( turret.isTonnageSet() && turret.GetTonnageFromItems() > turret.GetMaxTonnage() ) {
Media.Messager( this, name + "'s turret is overweight.\n" +
"Reduce the turret's weight to equal or below its max tonnage." );
tbpMainTabPane.setSelectedComponent( panel );
SetSource = true;
return false;
}
turret = CurVee.GetLoadout().GetRearTurret();
if( turret.isTonnageSet() && turret.GetTonnageFromItems() > turret.GetMaxTonnage() ) {
Media.Messager( this, name + "'s rear turret is overweight.\n" +
"Reduce the rear turret's weight to equal or below its max tonnage." );
tbpMainTabPane.setSelectedComponent( panel );
SetSource = true;
return false;
}
Expand Down
49 changes: 34 additions & 15 deletions saw/src/main/java/saw/gui/frmVeeWide.java
Original file line number Diff line number Diff line change
Expand Up @@ -3687,24 +3687,43 @@ private boolean VerifyVehicle( ActionEvent evt ) {
//}

// ensure we're not overweight
ArrayList<ifCVLoadout> loadouts = new ArrayList<>();
if( CurVee.IsOmni() ) {
ArrayList v = CurVee.GetLoadouts();
for (Object o : v) {
CurVee.SetCurLoadout(((ifCVLoadout) o).GetName());
if (CurVee.GetCurrentTons() > CurVee.GetTonnage()) {
Media.Messager(this, ((ifCVLoadout) o).GetName() +
" loadout is overweight. Reduce the weight\nto equal or below the Vehicle's tonnage.");
//cmbOmniVariant.setSelectedItem( ((ifCVLoadout) v.get( i )).GetName() );
//cmbOmniVariantActionPerformed( evt );
tbpMainTabPane.setSelectedComponent(pnlBasicSetup);
SetSource = true;
return false;
}
}
loadouts.addAll( CurVee.GetLoadouts() );
} else {
loadouts.add( null );
}
for( ifCVLoadout loadout : loadouts ) {
String name;
JPanel panel;
if( loadout == null ) {
name = "This Vehicle";
panel = pnlBasicSetup;
} else {
name = loadout.GetName() + " loadout";
CurVee.SetCurLoadout( loadout.GetName() );
panel = pnlEquipment;
}
if( CurVee.GetCurrentTons() > CurVee.GetTonnage() ) {
Media.Messager( this, "This Vehicle is overweight. Reduce the weight to\nequal or below the Vehicle's tonnage." );
tbpMainTabPane.setSelectedComponent( pnlBasicSetup );
Media.Messager( this, name + " is overweight.\n" +
"Reduce the weight to equal or below the Vehicle's tonnage." );
tbpMainTabPane.setSelectedComponent( panel );
SetSource = true;
return false;
}
Turret turret = CurVee.GetLoadout().GetTurret();
if( turret.isTonnageSet() && turret.GetTonnageFromItems() > turret.GetMaxTonnage() ) {
Media.Messager( this, name + "'s turret is overweight.\n" +
"Reduce the turret's weight to equal or below its max tonnage." );
tbpMainTabPane.setSelectedComponent( panel );
SetSource = true;
return false;
}
turret = CurVee.GetLoadout().GetRearTurret();
if( turret.isTonnageSet() && turret.GetTonnageFromItems() > turret.GetMaxTonnage() ) {
Media.Messager( this, name + "'s rear turret is overweight.\n" +
"Reduce the rear turret's weight to equal or below its max tonnage." );
tbpMainTabPane.setSelectedComponent( panel );
SetSource = true;
return false;
}
Expand Down
24 changes: 4 additions & 20 deletions sswlib/src/main/java/components/CVLoadout.java
Original file line number Diff line number Diff line change
Expand Up @@ -364,32 +364,16 @@ public void AddTo(abPlaceable p, int Loc) throws Exception {
throw new Exception(p.ActualName() + " cannot be allocated to the Side.");
break;
case LocationIndex.CV_LOC_TURRET1:
if ( p.CanAllocCVTurret() ) {
if ( p.CanAllocCVTurret() )
Turret1Items.add(p);
if ( Turret1.isTonnageSet() ) {
double tons = Turret1.GetTonnageFromItems();
if ( tons > Turret1.GetMaxTonnage() ) {
Turret1Items.remove(p);
throw new Exception( String.format( "Turret is out of space: %.1f/%.1f",
tons, Turret1.GetMaxTonnage()) );
}
}
} else
else
throw new Exception(p.ActualName() + " cannot be allocated to the Turret.");

break;
case LocationIndex.CV_LOC_TURRET2:
if ( p.CanAllocCVTurret() ) {
if ( p.CanAllocCVTurret() )
Turret2Items.add(p);
if ( Turret2.isTonnageSet() ) {
double tons = Turret2.GetTonnageFromItems();
if ( tons > Turret2.GetMaxTonnage() ) {
Turret2Items.remove(p);
throw new Exception( String.format( "Turret is out of space: %.1f/%.1f",
tons, Turret2.GetMaxTonnage()) );
}
}
} else
else
throw new Exception(p.ActualName() + " cannot be allocated to the Rear Turret.");
break;
case LocationIndex.CV_LOC_SPONSON_LEFT:
Expand Down

0 comments on commit 41d44a5

Please sign in to comment.