@@ -23,7 +23,9 @@ public class GameWorld {
2323 * Whether we're running.
2424 */
2525 protected boolean running = true ;
26- protected boolean isCooperation = true ;
26+ private boolean isCooperation = true ;
27+ private int backstabRound = -1 ;
28+ private Team backstabber = null ;
2729
2830 protected final IDGenerator idGenerator ;
2931 protected final GameStats gameStats ;
@@ -401,6 +403,25 @@ public boolean isCooperation() {
401403 return this .isCooperation ;
402404 }
403405
406+ public int getRoundsSinceBackstab () {
407+ if (this .isCooperation ) {
408+ return 0 ;
409+ } else {
410+ return this .currentRound - this .backstabRound ;
411+ }
412+ }
413+
414+ public boolean catTrapsAllowed (Team team ) {
415+ return this .isCooperation || (this .getRoundsSinceBackstab () <=
416+ GameConstants .CAT_TRAP_ROUNDS_AFTER_BACKSTAB && this .backstabber != team );
417+ }
418+
419+ public void backstab (Team backstabber ) {
420+ this .isCooperation = false ;
421+ this .backstabRound = this .currentRound ;
422+ this .backstabber = backstabber ;
423+ }
424+
404425 public boolean getWall (MapLocation loc ) {
405426 return this .walls [locationToIndex (loc )];
406427 }
@@ -601,13 +622,14 @@ public void triggerTrap(Trap trap, InternalRobot robot) {
601622 TrapType type = trap .getType ();
602623
603624 robot .setMovementCooldownTurns (type .stunTime );
625+
604626 if (type == TrapType .CAT_TRAP && robot .getType ().isCatType ()) {
605627 this .teamInfo .addDamageToCats (trap .getTeam (), Math .min (type .damage , robot .getHealth ()));
606628 }
607629
608630 if (trap .getType () != TrapType .CAT_TRAP ) {
609631 // initiate backstab
610- this . isCooperation = false ;
632+ backstab ( robot . getTeam (). opponent ()) ;
611633 }
612634
613635 matchMaker .addTrapTriggerAction (trap .getId (), loc , triggeringTeam , type );
@@ -807,7 +829,7 @@ public boolean setWinnerIfKilledAllRatKings() {
807829 * @return whether all cats dead
808830 */
809831 public boolean setWinnerifAllCatsDead () {
810- if (this .getNumCats () == 0 && this .isCooperation ) { // only end game if no more cats in cooperation mode
832+ if (this .getNumCats () == 0 && this .isCooperation () ) { // only end game if no more cats in cooperation mode
811833 // find out which team won via points
812834 if (setWinnerIfMorePoints ())
813835 return true ;
@@ -1134,7 +1156,7 @@ public void destroyRobot(int id, boolean fromException, boolean fromDamage) {
11341156 // check win
11351157 if (robot .getType () == UnitType .RAT_KING && this .getTeamInfo ().getNumRatKings (robot .getTeam ()) == 0 ) {
11361158 checkWin (robotTeam );
1137- } else if (this .isCooperation && robot .getType () == UnitType .CAT && this .getNumCats () == 0 ) {
1159+ } else if (this .isCooperation () && robot .getType () == UnitType .CAT && this .getNumCats () == 0 ) {
11381160 checkWin (robotTeam );
11391161 }
11401162 }
0 commit comments