Advertisement
Guest User

C&CRemasteredDebuggedQueueJumping

a guest
Sep 21st, 2020
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.23 KB | None | 0 0
  1. case RADIO_HELLO:
  2.             //Refineries can't be interupted while they're processing a harvester - LLL April 22, 2020
  3.             if (Mission == MISSION_HARVEST) {
  4.                 return(RADIO_NEGATIVE);
  5.             }
  6.             else if (Class->Type == STRUCT_REFINERY && ActiveCFEPatchConfig.EnableHarvyQueueJump && In_Radio_Contact()) {
  7.                 if (from->What_Am_I() == RTTI_UNIT && *((UnitClass*)from) == UNIT_HARVESTER) {
  8.  
  9.                     UnitClass& currentHarvy = *static_cast<UnitClass*>(Contact_With_Whom());
  10.                     UnitClass& newHarvy     = *static_cast<UnitClass*>(from);
  11.  
  12.                     int currentHarvyDistance;
  13.                     int newHarvyDistance;
  14.                     int jumpcutoff;
  15.                     if (ActiveCFEPatchConfig.EnableASPathing){
  16.                         int currentHarvyDistanceAStar = currentHarvy.Find_Path_AStar(nullptr, Coord_Cell(currentHarvy.Coord),  Coord_Cell(this->Center_Coord()), 1, MOVE_NO, -1);
  17.                         if (currentHarvyDistanceAStar){
  18.                             currentHarvyDistance = currentHarvyDistanceAStar;
  19.                         }
  20.                         else{ //either harvy is right on top of refinery, or no path at all
  21.                             int currentHarvyDistanceCrowFlies = currentHarvy.Distance(Coord_Cell(this->Center_Coord()));
  22.                             if (currentHarvyDistanceCrowFlies <= 6){
  23.                                 currentHarvyDistance = currentHarvyDistanceCrowFlies;
  24.                             }
  25.                             else {
  26.                                 currentHarvyDistance = INT_MAX;
  27.                             }
  28.                         }
  29.                         int newHarvyDistanceAStar = newHarvy.Find_Path_AStar(nullptr, Coord_Cell(newHarvy.Coord),  Coord_Cell(this->Center_Coord()), 1, MOVE_NO, -1);
  30.                         if (newHarvyDistanceAStar){
  31.                             newHarvyDistance = newHarvyDistanceAStar;
  32.                         }
  33.                         else{ //either harvy is right on top of refinery, or no path at all
  34.                             int newHarvyDistanceCrowFlies = newHarvy.Distance(Coord_Cell(this->Center_Coord()));
  35.                             if (newHarvyDistanceCrowFlies <= 6){
  36.                                 newHarvyDistance = newHarvyDistanceCrowFlies;
  37.                             }
  38.                             else {
  39.                                 newHarvyDistance = INT_MAX;
  40.                             }
  41.                         }
  42.                         jumpcutoff = ActiveCFEPatchConfig.HarvyQueueJumpCutoff;
  43.                     }
  44.                     else{ // A-Star not enabled
  45.                         currentHarvyDistance = currentHarvy.Distance(this);
  46.                         newHarvyDistance = newHarvy.Distance(this);
  47.                         jumpcutoff = Cell_To_Lepton(ActiveCFEPatchConfig.HarvyQueueJumpCutoff); //distance to coords are in leptons, not cells, so need to convert
  48.                     }
  49.                    
  50.                     if (currentHarvyDistance > jumpcutoff && newHarvyDistance < currentHarvyDistance) {
  51.  
  52.                         //Kick the current harvester out
  53.                         Transmit_Message(RADIO_CANCEL, &currentHarvy);
  54.  
  55.                         //Accept the new one
  56.                         return(TechnoClass::Receive_Message(from, message, param));
  57.                     }
  58.                 }
  59.             }
  60.             break;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement