Пример #1
0
void updatePsiFieldProviders() {
  for (CUnit *unit = *firstVisibleUnit; unit; unit = unit->link.next) {
    if (hooks::canMakePsiField(unit->id)) {
      assert(isValidPsiProviderType(unit->id));

      if (unit->status & UnitStatus::Completed) {
        if (hooks::isReadyToMakePsiField(unit)) {
          addPsiField(unit);
          updatePsiFieldPosition(unit);
        }
        else
          removePsiField(unit);
      }
    }
  }

  if (!(*IS_PLACING_BUILDING)) {
    for (int i = 0; i < 12 && i < *clientSelectionCount; ++i) {
      CUnit *selUnit = clientSelectionGroup->unit[i];
      if (hooks::isReadyToMakePsiField(selUnit))
        return;
    }

    hideAllPsiFields();
  }
}
void unitDestructorSpecialHook(CUnit *unit) {
	//Destroy interceptors and scarabs
	if (unit->id == UnitId::carrier || unit->id == UnitId::gantrithor
		|| unit->id == UnitId::reaver || unit->id == UnitId::warbringer
		) {
		killAllHangarUnits(unit);
		return;
	}

	//Destroy nuclear missiles mid-launch
	if (unit->id == UnitId::ghost
		|| unit->id == UnitId::sarah_kerrigan
		|| unit->id == UnitId::Hero_AlexeiStukov
		|| unit->id == UnitId::Hero_SamirDuran
		|| unit->id == UnitId::Hero_InfestedDuran
		) {
		if (unit->building.ghostNukeMissile) {
			unit->building.ghostNukeMissile->playIscriptAnim(IscriptAnimation::Death);
			unit->building.ghostNukeMissile = nullptr;
		}
		return;
	}

	//Is a harvestable mineral patch or gas building
	if (UnitId::mineral_field_1 <= unit->id && unit->id <= UnitId::mineral_field_3
		|| (unit->id == UnitId::refinery || unit->id == UnitId::assimilator || unit->id == UnitId::extractor)
		&& unit->status & UnitStatus::Completed
		) {
		freeResourceContainer(unit);
		return;
	}

	//Is a scarab or interceptor
	if (unit->id == UnitId::scarab || unit->id == UnitId::interceptor) {
		if (unit->status & UnitStatus::Completed) {
			if (unit->interceptor.parent) {
				if (unit->interceptor.hangar_link.next)
					unit->interceptor.hangar_link.next->interceptor.hangar_link.prev = unit->interceptor.hangar_link.prev;
				else {
					if (unit->interceptor.isOutsideHangar)
						unit->interceptor.parent->carrier.outHangarChild = unit->interceptor.hangar_link.prev;
					else
						unit->interceptor.parent->carrier.inHangarChild = unit->interceptor.hangar_link.prev;
				}

				if (unit->interceptor.isOutsideHangar)
					unit->interceptor.parent->carrier.outHangarCount--;
				else
					unit->interceptor.parent->carrier.inHangarCount--;

				if (unit->interceptor.hangar_link.prev)
					unit->interceptor.hangar_link.prev->interceptor.hangar_link.next = unit->interceptor.hangar_link.next;
			}
			else {
				unit->interceptor.hangar_link.prev = nullptr;
				unit->interceptor.hangar_link.next = nullptr;
			}
		}
		return;
	}

	//Is a Nuclear Silo
	if (unit->id == UnitId::nuclear_silo) {
		if (unit->building.silo.nuke) {
			unit->building.silo.nuke->remove();
			unit->building.silo.nuke = nullptr;
		}
		return;
	}

	//Is a Nuclear Missile
	if (unit->id == UnitId::nuclear_missile) {
		if (unit->connectedUnit && unit->connectedUnit->id == UnitId::nuclear_silo) {
			unit->connectedUnit->building.silo.nuke = nullptr;
			unit->connectedUnit->building.silo.isReady = false;
		}
		return;
	}

	if (hooks::canMakePsiField(unit->id)) {
		removePsiField(unit);
		return;
	}

	if (unit->id == UnitId::nydus_canal) {
		CUnit *nydusExit = unit->building.nydusExit;
		if (nydusExit) {
			unit->building.nydusExit = nullptr;
			nydusExit->building.nydusExit = nullptr;
			nydusExit->remove();
		}
		return;
	}

}