Enjoy the classic broodwar game with improved mechanics, new units, upgrades, abilities, and lot of changes that will improve the gameplay and open new strategies and compositions to fight with.

Forum Thread
  Posts  
Extended Pick-up Range Source (Games : StarCraft : Mods : SC Revolution Mod : Forum : Plugin Sources and implementations : Extended Pick-up Range Source) Locked
Thread Options
Apr 5 2016 Anchor


Shuttle extended pick up range - Mod DB

To make this implementation, there are two scenarios we want to analyze:
1 - A unit is ordered to enter a transport
2 - A transport is ordered to pick a unit

When some of the above happens we want to know if the unit is in the pick up range. When that happens we are ready to proceed with our code.

The shuttle will manage the operation, so when a unit its issued to enter a transport and is in the range, we will redirect the order to the transport.

What the trasport have to do is the following: Move the target unit to its current position and issue the unit to enter the transport, then we need to stop the trasnport as it want to go to the original position of the unit.

Problem is that we cannot use the function scbw::moveUnit() because it prevents units for overlapping positions (even a flying unit and a ground unit) so we need a new function that dont do that. So, i created a new one based on the original function, that dont manage units collisions. So it moves the unit exactly to the same position as the shuttle. Making the pick up order to happen even before we have time to see the unit

So first we define the pickup range in definitions.h

#define SHUTLE_PICK_RANGE 150

Then we add the new function in api.cpp

bool moveUnitIgnoreCollision(CUnit* unit, s16 x, s16 y) {
  prepareUnitMove(unit);
  setUnitPosition(unit, x, y);
  refreshUnitAfterMove(unit);
   return true;
}

and the declaration in api.h

bool moveUnitIgnoreCollision(CUnit* unit, s16 x, s16 y);

And finally we add the code in the nextFrame() function in hook.cpp

//Shutle Pick up range
		if (unit->hitPoints && unit->id==UnitId::shuttle){
			if (unit->mainOrderId==OrderId::Pickup2){
				target =unit->orderTarget.unit;
				if(target && !(target->status & UnitStatus::CanNotReceiveOrders) && !target->isFrozen() && scbw::canBeEnteredBy(unit,target)){
					dist=scbw::getDistanceFast(unit->getX(),unit->getY(),target->getX(),target->getY());
					if (dist < SHUTLE_PICK_RANGE && unit->playerId== target->playerId){	
						scbw::moveUnitIgnoreCollision(target,unit->getX(),unit->getY());
						target->orderTo(OrderId::EnterTransport, unit );
						unit->orderTo(OrderId::Stop);
					}
				}
			}				
		}
		if (unit->hitPoints && unit->mainOrderId==OrderId::EnterTransport && unit->orderTarget.unit && unit->orderTarget.unit->id==UnitId::shuttle){
			target=unit->orderTarget.unit;
			dist=scbw::getDistanceFast(unit->getX(),unit->getY(),target->getX(),target->getY());
			if (dist < SHUTLE_PICK_RANGE && unit->playerId== target->playerId)
				target->orderTo(OrderId::Pickup2, unit);				
		}

And we can also add a circle showing the extended range in hook.cpp in the selection block

//Selected Units
    for (int i = 0; i < *clientSelectionCount; ++i) {
       const CUnit *selUnit = clientSelectionGroup->unit[i];

	    if (selUnit->id == UnitId::shuttle && selUnit->playerId == *LOCAL_NATION_ID ) {//Show only for owner
			graphics::drawCircle(selUnit->getX(),selUnit->getY(),SHUTLE_PICK_RANGE,graphics::BLUE, graphics::ON_MAP);
		  }

		//..Other stuff..///
	}


Edited by: RavenWolf

Reply to thread
click to sign in and post

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.