/* virtual */ void COrder_Move::UpdatePathFinderData(PathFinderInput &input) { const Vec2i tileSize(0, 0); input.SetGoal(this->goalPos, tileSize); int distance = this->Range; if (GameSettings.Inside) { CheckObstaclesBetweenTiles(input.GetUnitPos(), this->HasGoal() ? this->GetGoal()->tilePos : this->goalPos, MapFieldRocks | MapFieldForest, &distance); } input.SetMaxRange(distance); input.SetMinRange(0); }
bool COrder_Still::AutoAttackStand(CUnit &unit) { if (unit.Type->CanAttack == false) { return false; } // Removed units can only attack in AttackRange, from bunker CUnit *autoAttackUnit = AttackUnitsInRange(unit); if (autoAttackUnit == NULL) { return false; } // If unit is removed, use containers x and y const CUnit *firstContainer = unit.Container ? unit.Container : &unit; if (firstContainer->MapDistanceTo(*autoAttackUnit) > unit.Stats->Variables[ATTACKRANGE_INDEX].Max) { return false; } if (GameSettings.Inside && CheckObstaclesBetweenTiles(unit.tilePos, autoAttackUnit->tilePos, MapFieldRocks | MapFieldForest) == false) { return false; } this->State = SUB_STILL_ATTACK; // Mark attacking. this->SetGoal(autoAttackUnit); UnitHeadingFromDeltaXY(unit, autoAttackUnit->tilePos + autoAttackUnit->Type->GetHalfTileSize() - unit.tilePos); return true; }
//Wyrmgus start //void MapSight(const CPlayer &player, const Vec2i &pos, int w, int h, int range, MapMarkerFunc *marker) void MapSight(const CPlayer &player, const Vec2i &pos, int w, int h, int range, MapMarkerFunc *marker, int z) //Wyrmgus end { // Units under construction have no sight range. if (!range) { return; } // Up hemi-cyle const int miny = std::max(-range, 0 - pos.y); for (int offsety = miny; offsety != 0; ++offsety) { const int offsetx = isqrt(square(range + 1) - square(-offsety) - 1); const int minx = std::max(0, pos.x - offsetx); //Wyrmgus start // const int maxx = std::min(Map.Info.MapWidth, pos.x + w + offsetx); const int maxx = std::min(Map.Info.MapWidths[z], pos.x + w + offsetx); //Wyrmgus end Vec2i mpos(minx, pos.y + offsety); #ifdef MARKER_ON_INDEX //Wyrmgus start // const unsigned int index = mpos.y * Map.Info.MapWidth; const unsigned int index = mpos.y * Map.Info.MapWidths[z]; //Wyrmgus end #endif for (mpos.x = minx; mpos.x < maxx; ++mpos.x) { //Wyrmgus start if (Map.IsLayerUnderground(z) && CheckObstaclesBetweenTiles(pos, mpos, MapFieldAirUnpassable, z, 1) == false) { continue; } //Wyrmgus end #ifdef MARKER_ON_INDEX //Wyrmgus start // marker(player, mpos.x + index); marker(player, mpos.x + index, z); //Wyrmgus end #else //Wyrmgus start // marker(player, mpos); marker(player, mpos, z); //Wyrmgus end #endif } } for (int offsety = 0; offsety < h; ++offsety) { const int minx = std::max(0, pos.x - range); //Wyrmgus start // const int maxx = std::min(Map.Info.MapWidth, pos.x + w + range); const int maxx = std::min(Map.Info.MapWidths[z], pos.x + w + range); //Wyrmgus end Vec2i mpos(minx, pos.y + offsety); #ifdef MARKER_ON_INDEX //Wyrmgus start // const unsigned int index = mpos.y * Map.Info.MapWidth; const unsigned int index = mpos.y * Map.Info.MapWidths[z]; //Wyrmgus end #endif for (mpos.x = minx; mpos.x < maxx; ++mpos.x) { //Wyrmgus start if (Map.IsLayerUnderground(z) && CheckObstaclesBetweenTiles(pos, mpos, MapFieldAirUnpassable, z, 1) == false) { continue; } //Wyrmgus end #ifdef MARKER_ON_INDEX //Wyrmgus start // marker(player, mpos.x + index); marker(player, mpos.x + index, z); //Wyrmgus end #else //Wyrmgus start // marker(player, mpos); marker(player, mpos, z); //Wyrmgus end #endif } } // bottom hemi-cycle //Wyrmgus start // const int maxy = std::min(range, Map.Info.MapHeight - pos.y - h); const int maxy = std::min(range, Map.Info.MapHeights[z] - pos.y - h); //Wyrmgus end for (int offsety = 0; offsety < maxy; ++offsety) { const int offsetx = isqrt(square(range + 1) - square(offsety + 1) - 1); const int minx = std::max(0, pos.x - offsetx); //Wyrmgus start // const int maxx = std::min(Map.Info.MapWidth, pos.x + w + offsetx); const int maxx = std::min(Map.Info.MapWidths[z], pos.x + w + offsetx); //Wyrmgus end Vec2i mpos(minx, pos.y + h + offsety); #ifdef MARKER_ON_INDEX //Wyrmgus start // const unsigned int index = mpos.y * Map.Info.MapWidth; const unsigned int index = mpos.y * Map.Info.MapWidths[z]; //Wyrmgus end #endif for (mpos.x = minx; mpos.x < maxx; ++mpos.x) { //Wyrmgus start if (Map.IsLayerUnderground(z) && CheckObstaclesBetweenTiles(pos, mpos, MapFieldAirUnpassable, z, 1) == false) { continue; } //Wyrmgus end #ifdef MARKER_ON_INDEX //Wyrmgus start // marker(player, mpos.x + index); marker(player, mpos.x + index, z); //Wyrmgus end #else //Wyrmgus start // marker(player, mpos); marker(player, mpos, z); //Wyrmgus end #endif } } }
bool COrder_Still::AutoAttackStand(CUnit &unit) { //Wyrmgus start // if (unit.Type->CanAttack == false) { if (unit.CanAttack() == false) { //Wyrmgus end return false; } // Removed units can only attack in AttackRange, from bunker //Wyrmgus start //if unit is in a container which is attacking, and the container has a goal, use that goal (if possible) instead // CUnit *autoAttackUnit = AttackUnitsInRange(unit); CUnit *autoAttackUnit = unit.Container && unit.Container->CurrentAction() == UnitActionAttack && unit.Container->CurrentOrder()->HasGoal() ? unit.Container->CurrentOrder()->GetGoal() : AttackUnitsInRange(unit); //Wyrmgus end if (autoAttackUnit == nullptr) { return false; } // If unit is removed, use container's x and y const CUnit *firstContainer = unit.GetFirstContainer(); if (firstContainer->MapDistanceTo(*autoAttackUnit) > unit.GetModifiedVariable(ATTACKRANGE_INDEX)) { return false; } //Wyrmgus start // if (GameSettings.Inside && CheckObstaclesBetweenTiles(unit.tilePos, autoAttackUnit->tilePos, MapFieldRocks | MapFieldForest) == false) { if (Map.IsLayerUnderground(autoAttackUnit->MapLayer->ID) && unit.GetModifiedVariable(ATTACKRANGE_INDEX) > 1 && CheckObstaclesBetweenTiles(unit.tilePos, autoAttackUnit->tilePos, MapFieldAirUnpassable, autoAttackUnit->MapLayer->ID) == false) { //Wyrmgus end return false; } this->State = SUB_STILL_ATTACK; // Mark attacking. this->SetGoal(autoAttackUnit); //Wyrmgus start // UnitHeadingFromDeltaXY(unit, autoAttackUnit->tilePos + autoAttackUnit->Type->GetHalfTileSize() - unit.tilePos); UnitHeadingFromDeltaXY(unit, PixelSize(PixelSize(autoAttackUnit->tilePos) * Map.GetMapLayerPixelTileSize(autoAttackUnit->MapLayer->ID)) + autoAttackUnit->GetHalfTilePixelSize() - PixelSize(PixelSize(unit.tilePos) * Map.GetMapLayerPixelTileSize(autoAttackUnit->MapLayer->ID)) - unit.GetHalfTilePixelSize()); //Wyrmgus end return true; }