Example #1
0
void noShip::HandleState_SeaAttackReturn()
{
    Result res = DriveToHarbour();
    switch(res)
    {
        default: return;
        case GOAL_REACHED:
        {
            // Entladen
            state = STATE_SEAATTACK_UNLOADING;
            this->current_ev = em->AddEvent(this, UNLOADING_TIME, 1);
        } break;
        case HARBOR_DOESNT_EXIST:
        {
            // Kein Hafen mehr?
            // Dann müssen alle Angreifer ihren Heimatgebäuden Bescheid geben, dass sie
            // nun nicht mehr kommen
            // Das Schiff muss einen Notlandeplatz ansteuern
            for(std::list<noFigure*>::iterator it = figures.begin(); it != figures.end(); ++it)
                static_cast<nofAttacker*>(*it)->CancelAtHomeMilitaryBuilding();

            state = STATE_TRANSPORT_DRIVING;
            HandleState_TransportDriving();

        } break;
        case NO_ROUTE_FOUND:
        {
            MapPoint goal(gwg->GetHarborPoint(goal_harbor_id));
            // Nichts machen und idlen
            StartIdling();
        } break;
    }
}
Example #2
0
void noShip::HandleState_ExpeditionDriving()
{
    Result res;
    // Zum Heimathafen fahren?
    if(home_harbor == goal_harbor_id)
        res = DriveToHarbour();
    else
        res = DriveToHarbourPlace();

    switch(res)
    {
        default: return;
        case GOAL_REACHED:
        {
            // Haben wir unsere Expedition beendet?
            if(home_harbor == goal_harbor_id)
            {
                // Sachen wieder in den Hafen verladen
                state = STATE_EXPEDITION_UNLOADING;
                current_ev = em->AddEvent(this, UNLOADING_TIME, 1);
            }
            else
            {
                // Warten auf weitere Anweisungen
                state = STATE_EXPEDITION_WAITING;

                // Spieler benachrichtigen
                if(GAMECLIENT.GetPlayerID() == this->player)
                    GAMECLIENT.SendPostMessage(new ShipPostMsg(_("A ship has reached the destination of its expedition."), PMC_GENERAL, GAMECLIENT.GetPlayer(player).nation, pos));

                // KI Event senden
                GAMECLIENT.SendAIEvent(new AIEvent::Location(AIEvent::ExpeditionWaiting, pos), player);
            }
        } break;
        case NO_ROUTE_FOUND:
        {
            MapPoint goal(gwg->GetHarborPoint(goal_harbor_id));
            // Nichts machen und idlen
            StartIdling();
        } break;
        case HARBOR_DOESNT_EXIST: //should only happen when an expedition is cancelled and the home harbor no longer exists
        {
            // Kein Heimathafen mehr?
            // Das Schiff muss einen Notlandeplatz ansteuern
            if(players->getElement(player)->FindHarborForUnloading(this, pos, &goal_harbor_id, &route_, NULL))
            {
                curRouteIdx = 0;
                home_harbor = goal_harbor_id; //set new home=goal so we will actually unload once we reach the goal
                HandleState_ExpeditionDriving();
            }
            else
            {
                // Ansonsten als verloren markieren, damit uns später Bescheid gesagt wird
                // wenn es einen neuen Hafen gibt
                lost = true;
            }
        } break;
    }
}
Example #3
0
void noShip::HandleState_TransportDriving()
{
    Result res = DriveToHarbour();
    switch(res)
    {
        default: return;
        case GOAL_REACHED:
        {
            // Waren abladen, dafür wieder kurze Zeit hier ankern
            state = STATE_TRANSPORT_UNLOADING;
            current_ev = em->AddEvent(this, UNLOADING_TIME, 1);

        } break;
        case NO_ROUTE_FOUND:
        {
            // Nichts machen und idlen
            StartIdling();
        } break;
        case HARBOR_DOESNT_EXIST:
        {
            // Kein Hafen mehr?
            // Dann müssen alle Leute ihren Heimatgebäuden Bescheid geben, dass sie
            // nun nicht mehr kommen
            // Das Schiff muss einen Notlandeplatz ansteuern
            //LOG.lprintf("transport goal harbor doesnt exist player %i state %i pos %u,%u \n",player,state,x,y);
            for(std::list<noFigure*>::iterator it = figures.begin(); it != figures.end(); ++it)
            {
                (*it)->Abrogate();
                (*it)->SetGoalToNULL();
            }

            if(remaining_sea_attackers)
            {
                remaining_sea_attackers = 0;
                for(std::list<noFigure*>::iterator it = figures.begin(); it != figures.end(); ++it)
                    static_cast<nofAttacker*>(*it)->HomeHarborLost();
            }
            for(std::list<Ware*>::iterator it = wares.begin(); it != wares.end(); ++it)
            {
                (*it)->NotifyGoalAboutLostWare();
                (*it)->goal = NULL;
            }

            // Neuen Hafen suchen
            if(players->getElement(player)->FindHarborForUnloading(this, pos, &goal_harbor_id, &route_, NULL))
            {
                curRouteIdx = 0;
                HandleState_TransportDriving();
            }
            else
            {
                // Ansonsten als verloren markieren, damit uns später Bescheid gesagt wird
                // wenn es einen neuen Hafen gibt
                lost = true;
            }
        } break;
    }
}
Example #4
0
void noShip::HandleState_ExplorationExpeditionDriving()
{
    Result res;
    // Zum Heimathafen fahren?
    if(home_harbor == goal_harbor_id && covered_distance >= MAX_EXPLORATION_EXPEDITION_DISTANCE)
        res = DriveToHarbour();
    else
        res = DriveToHarbourPlace();

    switch(res)
    {
        default: return;
        case GOAL_REACHED:
        {
            // Haben wir unsere Expedition beendet?
            if(home_harbor == goal_harbor_id && covered_distance >= MAX_EXPLORATION_EXPEDITION_DISTANCE)
            {
                // Dann sind wir fertig -> wieder entladen
                state = STATE_EXPLORATIONEXPEDITION_UNLOADING;
                current_ev = em->AddEvent(this, UNLOADING_TIME, 1);
            }
            else
            {
                // Strecke, die wir gefahren sind, draufaddieren
                covered_distance += route_.size();
                // Erstmal kurz ausruhen an diesem Punkt und das Rohr ausfahren, um ein bisschen
                // auf der Insel zu gucken
                state = STATE_EXPLORATIONEXPEDITION_WAITING;
                current_ev = em->AddEvent(this, EXPLORATION_EXPEDITION_WAITING_TIME, 1);
            }

        } break;
        case NO_ROUTE_FOUND:
        {
            MapPoint goal(gwg->GetHarborPoint(goal_harbor_id));
            unsigned old_visual_range = GetVisualRange();
            // Nichts machen und idlen
            StartIdling();
            // Sichtbarkeiten neu berechnen
            gwg->RecalcVisibilitiesAroundPoint(pos, old_visual_range, player, NULL);
        } break;
        case HARBOR_DOESNT_EXIST:
        {
            // Neuen Hafen suchen
            if(players->getElement(player)->FindHarborForUnloading
                    (this, pos, &goal_harbor_id, &route_, NULL))
                HandleState_TransportDriving();
            else
                // Ansonsten als verloren markieren, damit uns später Bescheid gesagt wird
                // wenn es einen neuen Hafen gibt
                lost = true;

        } break;
    }
}
Example #5
0
void noShip::HandleState_SeaAttackReturn()
{
    Result res = DriveToHarbour();
    switch(res)
    {
    case DRIVING: return;
    case GOAL_REACHED:
        // Entladen
        state = STATE_SEAATTACK_UNLOADING;
        this->current_ev = GetEvMgr().AddEvent(this, UNLOADING_TIME, 1);
        break;
    case HARBOR_DOESNT_EXIST:
    case NO_ROUTE_FOUND:
        AbortSeaAttack();
        break;
    }
}
Example #6
0
void noShip::HandleState_ExpeditionDriving()
{
    Result res;
    // Zum Heimathafen fahren?
    if(home_harbor == goal_harborId)
        res = DriveToHarbour();
    else
        res = DriveToHarbourPlace();

    switch(res)
    {
        case DRIVING: return;
        case GOAL_REACHED:
        {
            // Haben wir unsere Expedition beendet?
            if(home_harbor == goal_harborId)
            {
                // Sachen wieder in den Hafen verladen
                state = STATE_EXPEDITION_UNLOADING;
                current_ev = GetEvMgr().AddEvent(this, UNLOADING_TIME, 1);
            }
            else
            {
                // Warten auf weitere Anweisungen
                state = STATE_EXPEDITION_WAITING;

                // Spieler benachrichtigen
                SendPostMessage(player, new ShipPostMsg(GetEvMgr().GetCurrentGF(), _("A ship has reached the destination of its expedition."), PostCategory::Economy, *this));
                gwg->GetNotifications().publish(ExpeditionNote(ExpeditionNote::Waiting, player, pos));
            }
        } break;
        case NO_ROUTE_FOUND:
        case HARBOR_DOESNT_EXIST: //should only happen when an expedition is cancelled and the home harbor no longer exists
        {
            if(home_harbor != goal_harborId && home_harbor != 0)
            {
                // Try to go back
                goal_harborId = home_harbor;
                HandleState_ExpeditionDriving();
            }else
                FindUnloadGoal(STATE_EXPEDITION_DRIVING); // Unload anywhere!
        } break;
    }
}
Example #7
0
void noShip::HandleState_GoToHarbor()
{
    // Hafen schon zerstört?
    if(goal_harbor_id == 0)
    {
        StartIdling();
    }
    else
    {
        Result res = DriveToHarbour();
        switch(res)
        {
            default: return;
            case GOAL_REACHED:
            {

                MapPoint goal(gwg->GetHarborPoint(goal_harbor_id));
                // Erstmal nichts machen und idlen
                StartIdling();
                // Hafen Bescheid sagen, dass wir da sind (falls er überhaupt noch existiert)
                noBase* nb = gwg->GetNO(goal);
                if(nb->GetGOT() == GOT_NOB_HARBORBUILDING)
                    static_cast<nobHarborBuilding*>(nb)->ShipArrived(this);
            } break;
            case NO_ROUTE_FOUND:
            {
                MapPoint goal(gwg->GetHarborPoint(goal_harbor_id));
                // Dem Hafen Bescheid sagen
                gwg->GetSpecObj<nobHarborBuilding>(goal)->ShipLost(this);
                // Ziel aktualisieren
                goal_harbor_id = 0;
                // Nichts machen und idlen
                StartIdling();
            } break;
            case HARBOR_DOESNT_EXIST:
            {
                // Nichts machen und idlen
                StartIdling();
            } break;
        }
    }
}
Example #8
0
void noShip::HandleState_ExplorationExpeditionDriving()
{
    Result res;
    // Zum Heimathafen fahren?
    if(home_harbor == goal_harborId && covered_distance >= MAX_EXPLORATION_EXPEDITION_DISTANCE)
        res = DriveToHarbour();
    else
        res = DriveToHarbourPlace();

    switch(res)
    {
        case DRIVING: return;
        case GOAL_REACHED:
        {
            // Haben wir unsere Expedition beendet?
            if(home_harbor == goal_harborId && covered_distance >= MAX_EXPLORATION_EXPEDITION_DISTANCE)
            {
                // Dann sind wir fertig -> wieder entladen
                state = STATE_EXPLORATIONEXPEDITION_UNLOADING;
                current_ev = GetEvMgr().AddEvent(this, UNLOADING_TIME, 1);
            }
            else
            {
                // Strecke, die wir gefahren sind, draufaddieren
                covered_distance += route_.size();
                // Erstmal kurz ausruhen an diesem Punkt und das Rohr ausfahren, um ein bisschen
                // auf der Insel zu gucken
                state = STATE_EXPLORATIONEXPEDITION_WAITING;
                current_ev = GetEvMgr().AddEvent(this, EXPLORATION_EXPEDITION_WAITING_TIME, 1);
            }

        } break;
        case NO_ROUTE_FOUND:
        case HARBOR_DOESNT_EXIST:
            gwg->RecalcVisibilitiesAroundPoint(pos, GetVisualRange(), player, NULL);
            StartIdling();
            break;
    }
}
Example #9
0
void noShip::HandleState_GoToHarbor()
{
    // Hafen schon zerstört?
    if(goal_harborId == 0)
    {
        StartIdling();
        return;
    }

    Result res = DriveToHarbour();
    switch(res)
    {
    case DRIVING:
        return; // Continue
    case GOAL_REACHED:
        {
            MapPoint goal(gwg->GetHarborPoint(goal_harborId));
            RTTR_Assert(goal.isValid());
            // Go idle here (if harbor does not need it)
            StartIdling();
            // Hafen Bescheid sagen, dass wir da sind (falls er überhaupt noch existiert)
            noBase* hb = goal.isValid() ? gwg->GetNO(goal) : NULL;
            if(hb && hb->GetGOT() == GOT_NOB_HARBORBUILDING)
                static_cast<nobHarborBuilding*>(hb)->ShipArrived(this);
        } break;
    case NO_ROUTE_FOUND:
        {
            MapPoint goal(gwg->GetHarborPoint(goal_harborId));
            RTTR_Assert(goal.isValid());
            // Dem Hafen Bescheid sagen
            gwg->GetSpecObj<nobHarborBuilding>(goal)->ShipLost(this);
            StartIdling();
        } break;
    case HARBOR_DOESNT_EXIST:
        StartIdling();
        break;
    }
}
Example #10
0
void noShip::HandleState_TransportDriving()
{
    Result res = DriveToHarbour();
    switch(res)
    {
        case DRIVING: return;
        case GOAL_REACHED:
        {
            // Waren abladen, dafür wieder kurze Zeit hier ankern
            state = STATE_TRANSPORT_UNLOADING;
            current_ev = GetEvMgr().AddEvent(this, UNLOADING_TIME, 1);
        } break;
        case NO_ROUTE_FOUND:
        case HARBOR_DOESNT_EXIST:
        {
            RTTR_Assert(!remaining_sea_attackers);
            // Kein Hafen mehr?
            // Dann müssen alle Leute ihren Heimatgebäuden Bescheid geben, dass sie
            // nun nicht mehr kommen
            // Das Schiff muss einen Notlandeplatz ansteuern
            //LOG.write(("transport goal harbor doesnt exist player %i state %i pos %u,%u \n",player,state,x,y);
            for(std::list<noFigure*>::iterator it = figures.begin(); it != figures.end(); ++it)
            {
                (*it)->Abrogate();
                (*it)->SetGoalToNULL();
            }

            for(std::list<Ware*>::iterator it = wares.begin(); it != wares.end(); ++it)
            {
                (*it)->NotifyGoalAboutLostWare();
            }

            FindUnloadGoal(STATE_TRANSPORT_DRIVING);
        } break;
    }
}