~flosoft/s25rttr/trunk

« back to all changes in this revision

Viewing changes to src/Ware.cpp

  • Committer: FloSoft
  • Date: 2014-04-25 15:35:50 UTC
  • Revision ID: flosoft@siedler25.org-20140425153550-9muu4vodhlqu58m0
committing subversion revision 9357 by FloSoft
astyle

modified:
s25client/trunk/
s25client/trunk/contrib/lua/lin32/include/
s25client/trunk/contrib/lua/lin64/include/
s25client/trunk/contrib/lua/mac/include/
s25client/trunk/contrib/lua/win32/include/
s25client/trunk/contrib/lua/win64/include/
s25client/trunk/driver/audio/SDL/src/
s25client/trunk/driver/src/
s25client/trunk/driver/video/GLFW/src/
s25client/trunk/driver/video/SDL/src/
s25client/trunk/driver/video/WinAPI/src/
s25client/trunk/src/
s25client/trunk/win32/
s25client/trunk/win32/prebuild-mutex/src/

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// $Id: Ware.cpp 8334 2012-09-28 23:12:07Z marcus $
 
1
// $Id: Ware.cpp 9357 2014-04-25 15:35:25Z FloSoft $
2
2
//
3
3
// Copyright (c) 2005 - 2011 Settlers Freaks (sf-team at siedler25.org)
4
4
//
34
34
///////////////////////////////////////////////////////////////////////////////
35
35
// Makros / Defines
36
36
#if defined _WIN32 && defined _DEBUG && defined _MSC_VER
37
 
        #define new new(_NORMAL_BLOCK, THIS_FILE, __LINE__)
38
 
        #undef THIS_FILE
39
 
        static char THIS_FILE[] = __FILE__;
 
37
#define new new(_NORMAL_BLOCK, THIS_FILE, __LINE__)
 
38
#undef THIS_FILE
 
39
static char THIS_FILE[] = __FILE__;
40
40
#endif
41
41
 
42
 
Ware::Ware(const GoodType type, noBaseBuilding * goal, noRoadNode * location) :
43
 
next_dir(255), state(STATE_WAITINWAREHOUSE), location(location),
44
 
type(type == GD_SHIELDROMANS ? SHIELD_TYPES[GameClient::inst().GetPlayer(location->GetPlayer())->nation] : type ),// Bin ich ein Schild? Dann evtl. Typ nach Nation anpassen
45
 
goal(goal)
 
42
Ware::Ware(const GoodType type, noBaseBuilding* goal, noRoadNode* location) :
 
43
    next_dir(255), state(STATE_WAITINWAREHOUSE), location(location),
 
44
    type(type == GD_SHIELDROMANS ? SHIELD_TYPES[GameClient::inst().GetPlayer(location->GetPlayer())->nation] : type ),// Bin ich ein Schild? Dann evtl. Typ nach Nation anpassen
 
45
    goal(goal)
46
46
{
47
 
        // Ware in den Index mit eintragen
48
 
        gwg->GetPlayer(location->GetPlayer())->RegisterWare(this);
49
 
        
50
 
        
51
 
        //assert(obj_id != 1197877);
 
47
    // Ware in den Index mit eintragen
 
48
    gwg->GetPlayer(location->GetPlayer())->RegisterWare(this);
 
49
 
 
50
 
 
51
    //assert(obj_id != 1197877);
52
52
}
53
53
 
54
54
Ware::~Ware()
55
55
{
56
 
        /*assert(!gwg->GetPlayer((location->GetPlayer()].IsWareRegistred(this));*/
57
 
        //if(location)
58
 
        //      assert(!gwg->GetPlayer((location->GetPlayer())->IsWareDependent(this));
 
56
    /*assert(!gwg->GetPlayer((location->GetPlayer()].IsWareRegistred(this));*/
 
57
    //if(location)
 
58
    //  assert(!gwg->GetPlayer((location->GetPlayer())->IsWareDependent(this));
59
59
}
60
60
 
61
61
void Ware::Destroy(void)
62
62
{
63
63
}
64
64
 
65
 
void Ware::Serialize_Ware(SerializedGameData * sgd) const
 
65
void Ware::Serialize_Ware(SerializedGameData* sgd) const
66
66
{
67
 
        Serialize_GameObject(sgd);
 
67
    Serialize_GameObject(sgd);
68
68
 
69
 
        sgd->PushUnsignedChar(next_dir);
70
 
        sgd->PushUnsignedChar(static_cast<unsigned char>(state));
71
 
        sgd->PushObject(location,false);
72
 
        sgd->PushUnsignedChar(static_cast<unsigned char>(type));
73
 
        sgd->PushObject(goal,false);
74
 
        sgd->PushUnsignedShort(next_harbor.x);
75
 
        sgd->PushUnsignedShort(next_harbor.y);
 
69
    sgd->PushUnsignedChar(next_dir);
 
70
    sgd->PushUnsignedChar(static_cast<unsigned char>(state));
 
71
    sgd->PushObject(location, false);
 
72
    sgd->PushUnsignedChar(static_cast<unsigned char>(type));
 
73
    sgd->PushObject(goal, false);
 
74
    sgd->PushUnsignedShort(next_harbor.x);
 
75
    sgd->PushUnsignedShort(next_harbor.y);
76
76
}
77
77
 
78
 
Ware::Ware(SerializedGameData * sgd, const unsigned obj_id) : GameObject(sgd,obj_id),
79
 
next_dir(sgd->PopUnsignedChar()),
80
 
state(State(sgd->PopUnsignedChar())),
81
 
location(sgd->PopObject<noRoadNode>(GOT_UNKNOWN)),
82
 
type(GoodType(sgd->PopUnsignedChar())),
83
 
goal(sgd->PopObject<noBaseBuilding>(GOT_UNKNOWN))
 
78
Ware::Ware(SerializedGameData* sgd, const unsigned obj_id) : GameObject(sgd, obj_id),
 
79
    next_dir(sgd->PopUnsignedChar()),
 
80
    state(State(sgd->PopUnsignedChar())),
 
81
    location(sgd->PopObject<noRoadNode>(GOT_UNKNOWN)),
 
82
    type(GoodType(sgd->PopUnsignedChar())),
 
83
    goal(sgd->PopObject<noBaseBuilding>(GOT_UNKNOWN))
84
84
 
85
85
{
86
 
        next_harbor.x = sgd->PopUnsignedShort();
87
 
        next_harbor.y = sgd->PopUnsignedShort();
88
 
        //assert(obj_id != 1197877);
 
86
    next_harbor.x = sgd->PopUnsignedShort();
 
87
    next_harbor.y = sgd->PopUnsignedShort();
 
88
    //assert(obj_id != 1197877);
89
89
}
90
90
 
91
91
 
92
92
void Ware::RecalcRoute()
93
93
{
94
 
        // Nächste Richtung nehmen
95
 
        next_dir = gwg->FindPathForWareOnRoads(location,goal,NULL,&next_harbor);
96
 
 
97
 
        // Evtl gibts keinen Weg mehr? Dann wieder zurück ins Lagerhaus (wenns vorher überhaupt zu nem Ziel ging)
98
 
        if(next_dir == 0xFF && goal)
99
 
        {
100
 
                // meinem Ziel Becheid sagen
101
 
                goal->WareLost(this);
102
 
 
103
 
                nobBaseWarehouse * wh = gwg->GetPlayer(location->GetPlayer())->FindWarehouse(
104
 
                        location,FW::Condition_StoreWare,0,true,&type,true);
105
 
                if(wh)
106
 
                {
107
 
                        // Lagerhaus ist unser neues Ziel
108
 
                        goal = wh;
109
 
                        // Weg berechnen
110
 
                        next_dir = gwg->FindPathForWareOnRoads(location,goal,NULL,&next_harbor);
111
 
 
112
 
                        wh->TakeWare(this);
113
 
                }
114
 
                else
115
 
                {
116
 
 
117
 
 
118
 
                        // Es gibt auch kein Weg zu einem Lagerhaus, tja dann ist es wohl vorbei erstmal
119
 
                        goal = 0;
120
 
 
121
 
                        return;
122
 
                }
123
 
        }
124
 
        
125
 
                
126
 
        // If we waited in the harbor for the ship before and don't want to travel now
127
 
        // -> inform the harbor so that it can remove us from its list
128
 
        if(state == STATE_WAITFORSHIP && next_dir != SHIP_DIR)
129
 
        {
130
 
                assert(location);
131
 
                assert(location->GetGOT() == GOT_NOB_HARBORBUILDING);
132
 
                
133
 
                static_cast<nobHarborBuilding*>(location)->WareDontWantToTravelByShip(this);
134
 
 
135
 
                state = STATE_WAITINWAREHOUSE;
136
 
        }
137
 
 
138
 
        //// Es wurde ein gültiger Weg gefunden! Dann muss aber noch dem nächsten Träger Bescheid gesagt werden
139
 
        //location->routes[next_dir]->AddWareJob(location);
 
94
    // Nächste Richtung nehmen
 
95
    next_dir = gwg->FindPathForWareOnRoads(location, goal, NULL, &next_harbor);
 
96
 
 
97
    // Evtl gibts keinen Weg mehr? Dann wieder zurück ins Lagerhaus (wenns vorher überhaupt zu nem Ziel ging)
 
98
    if(next_dir == 0xFF && goal)
 
99
    {
 
100
        // meinem Ziel Becheid sagen
 
101
        goal->WareLost(this);
 
102
 
 
103
        nobBaseWarehouse* wh = gwg->GetPlayer(location->GetPlayer())->FindWarehouse(
 
104
                                   location, FW::Condition_StoreWare, 0, true, &type, true);
 
105
        if(wh)
 
106
        {
 
107
            // Lagerhaus ist unser neues Ziel
 
108
            goal = wh;
 
109
            // Weg berechnen
 
110
            next_dir = gwg->FindPathForWareOnRoads(location, goal, NULL, &next_harbor);
 
111
 
 
112
            wh->TakeWare(this);
 
113
        }
 
114
        else
 
115
        {
 
116
 
 
117
 
 
118
            // Es gibt auch kein Weg zu einem Lagerhaus, tja dann ist es wohl vorbei erstmal
 
119
            goal = 0;
 
120
 
 
121
            return;
 
122
        }
 
123
    }
 
124
 
 
125
 
 
126
    // If we waited in the harbor for the ship before and don't want to travel now
 
127
    // -> inform the harbor so that it can remove us from its list
 
128
    if(state == STATE_WAITFORSHIP && next_dir != SHIP_DIR)
 
129
    {
 
130
        assert(location);
 
131
        assert(location->GetGOT() == GOT_NOB_HARBORBUILDING);
 
132
 
 
133
        static_cast<nobHarborBuilding*>(location)->WareDontWantToTravelByShip(this);
 
134
 
 
135
        state = STATE_WAITINWAREHOUSE;
 
136
    }
 
137
 
 
138
    //// Es wurde ein gültiger Weg gefunden! Dann muss aber noch dem nächsten Träger Bescheid gesagt werden
 
139
    //location->routes[next_dir]->AddWareJob(location);
140
140
}
141
141
 
142
142
void Ware::GoalDestroyed()
143
143
{
144
144
 
145
 
        if(state == STATE_WAITINWAREHOUSE)
146
 
        {
147
 
                // Ware ist noch im Lagerhaus auf der Warteliste
148
 
        }
149
 
        // Ist sie evtl. gerade mit dem Schiff unterwegs?
150
 
        else if(state == STATE_ONSHIP)
151
 
        {
152
 
                // Ziel zunächst auf NULL setzen, was dann vom Zielhafen erkannt wird,
153
 
                // woraufhin dieser die Ware gleich in sein Inventar mit übernimmt
154
 
                goal = NULL;
155
 
        }
156
 
        // Oder wartet sie im Hafen noch auf ein Schiff
157
 
        else if(state == STATE_WAITFORSHIP)
158
 
        {
159
 
                // Dann dem Hafen Bescheid sagen
160
 
                dynamic_cast<nobHarborBuilding*>(location)->CancelWareForShip(this);
161
 
                GAMECLIENT.GetPlayer(location->GetPlayer())->RemoveWare(this);
162
 
                em->AddToKillList(this);
163
 
        }
164
 
        else
165
 
        {
166
 
                // Ware ist unterwegs, Lagerhaus finden und Ware dort einliefern
167
 
                assert(location);
168
 
                assert(location->GetPlayer() < MAX_PLAYERS);
169
 
 
170
 
                // Wird sie gerade aus einem Lagerhaus rausgetragen?
171
 
                if(location->GetGOT() == GOT_NOB_STOREHOUSE || 
172
 
                        /*location->GetGOT() == GOT_NOB_HARBOUR || */
173
 
                   location->GetGOT() == GOT_NOB_HQ)
174
 
                {
175
 
                        if(location != goal)
176
 
                        {
177
 
                                goal = static_cast<noBaseBuilding*>(location);
178
 
                                // Lagerhaus ggf. Bescheid sagen
179
 
                                goal->TakeWare(this);
180
 
                        }
181
 
                        else
182
 
                        {
183
 
                                goal = NULL;
184
 
                                next_dir = 0xFF;
185
 
                        }
186
 
                }
187
 
                // Wenn sie an einer Flagge liegt, muss der Weg neu berechnet werden und dem Träger Bescheid gesagt werden
188
 
                else if(state == STATE_WAITATFLAG)
189
 
                {
190
 
                        goal = gwg->GetPlayer(location->GetPlayer())->FindWarehouse(location,FW::Condition_StoreWare,0,true,&type,true);
191
 
 
192
 
                        unsigned char last_next_dir = next_dir;
193
 
                        next_dir = gwg->FindPathForWareOnRoads(location,goal,NULL,&next_harbor);
194
 
                        RemoveWareJobForCurrentDir(last_next_dir);
195
 
 
196
 
 
197
 
                        // Kein Lagerhaus gefunden bzw kein Weg dorthin?
198
 
                        if(!goal || next_dir == 0xFF)
199
 
                        {
200
 
                                //// Mich aus der globalen Warenliste rausnehmen und in die WareLost Liste einfügen
201
 
                                //gwg->GetPlayer((location->GetPlayer()].RemoveWare(this);
202
 
                                //gwg->GetPlayer((location->GetPlayer()].RegisterLostWare(this);
203
 
                                return;
204
 
                        }
205
 
 
206
 
                        // Es wurde ein gültiger Weg gefunden! Dann muss aber noch dem nächsten Träger Bescheid gesagt werden
207
 
                        location->routes[next_dir]->AddWareJob(location);
208
 
 
209
 
                        // Lagerhaus Bescheid sagen
210
 
                        goal->TakeWare(this);
211
 
                }
212
 
                else if(state == STATE_CARRIED)
213
 
                {
214
 
                        // Ziel = aktuelle Position, d.h. der Träger, der die Ware trägt, geht gerade in das Zielgebäude rein
215
 
                        // d.h. es ist sowieso zu spät
216
 
                        if(goal != location)
217
 
                        {
218
 
                                goal = gwg->GetPlayer(location->GetPlayer())->FindWarehouse(location,FW::Condition_StoreWare,0,true,&type,true);
219
 
 
220
 
                                if(goal)
221
 
                                        // Lagerhaus ggf. Bescheid sagen
222
 
                                        goal->TakeWare(this);
223
 
                        }
224
 
                }
225
 
        }
 
145
    if(state == STATE_WAITINWAREHOUSE)
 
146
    {
 
147
        // Ware ist noch im Lagerhaus auf der Warteliste
 
148
    }
 
149
    // Ist sie evtl. gerade mit dem Schiff unterwegs?
 
150
    else if(state == STATE_ONSHIP)
 
151
    {
 
152
        // Ziel zunächst auf NULL setzen, was dann vom Zielhafen erkannt wird,
 
153
        // woraufhin dieser die Ware gleich in sein Inventar mit übernimmt
 
154
        goal = NULL;
 
155
    }
 
156
    // Oder wartet sie im Hafen noch auf ein Schiff
 
157
    else if(state == STATE_WAITFORSHIP)
 
158
    {
 
159
        // Dann dem Hafen Bescheid sagen
 
160
        dynamic_cast<nobHarborBuilding*>(location)->CancelWareForShip(this);
 
161
        GAMECLIENT.GetPlayer(location->GetPlayer())->RemoveWare(this);
 
162
        em->AddToKillList(this);
 
163
    }
 
164
    else
 
165
    {
 
166
        // Ware ist unterwegs, Lagerhaus finden und Ware dort einliefern
 
167
        assert(location);
 
168
        assert(location->GetPlayer() < MAX_PLAYERS);
 
169
 
 
170
        // Wird sie gerade aus einem Lagerhaus rausgetragen?
 
171
        if(location->GetGOT() == GOT_NOB_STOREHOUSE ||
 
172
                /*location->GetGOT() == GOT_NOB_HARBOUR || */
 
173
                location->GetGOT() == GOT_NOB_HQ)
 
174
        {
 
175
            if(location != goal)
 
176
            {
 
177
                goal = static_cast<noBaseBuilding*>(location);
 
178
                // Lagerhaus ggf. Bescheid sagen
 
179
                goal->TakeWare(this);
 
180
            }
 
181
            else
 
182
            {
 
183
                goal = NULL;
 
184
                next_dir = 0xFF;
 
185
            }
 
186
        }
 
187
        // Wenn sie an einer Flagge liegt, muss der Weg neu berechnet werden und dem Träger Bescheid gesagt werden
 
188
        else if(state == STATE_WAITATFLAG)
 
189
        {
 
190
            goal = gwg->GetPlayer(location->GetPlayer())->FindWarehouse(location, FW::Condition_StoreWare, 0, true, &type, true);
 
191
 
 
192
            unsigned char last_next_dir = next_dir;
 
193
            next_dir = gwg->FindPathForWareOnRoads(location, goal, NULL, &next_harbor);
 
194
            RemoveWareJobForCurrentDir(last_next_dir);
 
195
 
 
196
 
 
197
            // Kein Lagerhaus gefunden bzw kein Weg dorthin?
 
198
            if(!goal || next_dir == 0xFF)
 
199
            {
 
200
                //// Mich aus der globalen Warenliste rausnehmen und in die WareLost Liste einfügen
 
201
                //gwg->GetPlayer((location->GetPlayer()].RemoveWare(this);
 
202
                //gwg->GetPlayer((location->GetPlayer()].RegisterLostWare(this);
 
203
                return;
 
204
            }
 
205
 
 
206
            // Es wurde ein gültiger Weg gefunden! Dann muss aber noch dem nächsten Träger Bescheid gesagt werden
 
207
            location->routes[next_dir]->AddWareJob(location);
 
208
 
 
209
            // Lagerhaus Bescheid sagen
 
210
            goal->TakeWare(this);
 
211
        }
 
212
        else if(state == STATE_CARRIED)
 
213
        {
 
214
            // Ziel = aktuelle Position, d.h. der Träger, der die Ware trägt, geht gerade in das Zielgebäude rein
 
215
            // d.h. es ist sowieso zu spät
 
216
            if(goal != location)
 
217
            {
 
218
                goal = gwg->GetPlayer(location->GetPlayer())->FindWarehouse(location, FW::Condition_StoreWare, 0, true, &type, true);
 
219
 
 
220
                if(goal)
 
221
                    // Lagerhaus ggf. Bescheid sagen
 
222
                    goal->TakeWare(this);
 
223
            }
 
224
        }
 
225
    }
226
226
}
227
227
 
228
228
/// Gibt dem Ziel der Ware bekannt, dass diese nicht mehr kommen kann
229
229
void Ware::NotifyGoalAboutLostWare()
230
230
{
231
 
        // Meinem Ziel Bescheid sagen, dass ich weg vom Fenster bin (falls ich ein Ziel habe!)
232
 
        if(goal)
233
 
                goal->WareLost(this);
 
231
    // Meinem Ziel Bescheid sagen, dass ich weg vom Fenster bin (falls ich ein Ziel habe!)
 
232
    if(goal)
 
233
        goal->WareLost(this);
234
234
}
235
235
 
236
236
/// Wenn die Ware vernichtet werden muss
237
237
void Ware::WareLost(const unsigned char player)
238
238
{
239
 
        // Inventur verringern
240
 
        gwg->GetPlayer(player)->DecreaseInventoryWare(type,1);
241
 
        // Ziel der Ware Bescheid sagen
242
 
        NotifyGoalAboutLostWare();
243
 
        // Zentrale Registrierung der Ware löschen
244
 
        gwg->GetPlayer(player)->RemoveWare(this);
 
239
    // Inventur verringern
 
240
    gwg->GetPlayer(player)->DecreaseInventoryWare(type, 1);
 
241
    // Ziel der Ware Bescheid sagen
 
242
    NotifyGoalAboutLostWare();
 
243
    // Zentrale Registrierung der Ware löschen
 
244
    gwg->GetPlayer(player)->RemoveWare(this);
245
245
}
246
246
 
247
247
 
248
248
void Ware::RemoveWareJobForCurrentDir(const unsigned char last_next_dir)
249
249
{
250
 
        // last_next_dir war die letzte Richtung, in die die Ware eigentlich wollte,
251
 
        // aber nun nicht mehr will, deshalb muss dem Träger Bescheid gesagt werden
252
 
 
253
 
        // War's überhaupt ne richtige Richtung?
254
 
        if(last_next_dir < 6)
255
 
        {
256
 
                // Existiert da noch ne Straße?
257
 
                if(location->routes[last_next_dir])
258
 
                {
259
 
                        // Den Trägern Bescheid sagen
260
 
                        location->routes[last_next_dir]->WareJobRemoved(0);
261
 
                        // Wenn nicht, könntes ja sein, dass die Straße in ein Lagerhaus führt, dann muss dort Bescheid gesagt werden
262
 
                        if(location->routes[last_next_dir]->GetF2()->GetType() == NOP_BUILDING)
263
 
                        {
264
 
                                if(static_cast<noBuilding*>(location->routes[1]->GetF2())->GetBuildingType() == BLD_HEADQUARTERS ||
265
 
                                   static_cast<noBuilding*>(location->routes[1]->GetF2())->GetBuildingType() == BLD_STOREHOUSE ||
266
 
                                   static_cast<noBuilding*>(location->routes[1]->GetF2())->GetBuildingType() == BLD_HARBORBUILDING)
267
 
                                   static_cast<nobBaseWarehouse*>(location->routes[1]->GetF2())->DontFetchNextWare();
268
 
                        }
269
 
                }
270
 
 
271
 
                
272
 
                        //// Und stand ein Träger drauf?
273
 
                        //if(location->routes[last_next_dir]->carrier)
274
 
                        //      location->routes[last_next_dir]->carrier->RemoveWareJob();
275
 
                        //// Wenn nicht, könntes ja sein, dass die Straße in ein Lagerhaus führt, dann muss dort Bescheid gesagt werden
276
 
                        //else if(location->routes[1])
277
 
                        //{
278
 
                        //      if(location->routes[1]->f2->GetType() == NOP_BUILDING)
279
 
                        //      {
280
 
                        //              if(static_cast<noBuilding*>(location->routes[1]->f2)->GetBuildingType() == BLD_HEADQUARTERS ||
281
 
                        //                 static_cast<noBuilding*>(location->routes[1]->f2)->GetBuildingType() == BLD_STOREHOUSE ||
282
 
                        //                 static_cast<noBuilding*>(location->routes[1]->f2)->GetBuildingType() == BLD_HARBORBUILDING)
283
 
                        //                 static_cast<nobBaseWarehouse*>(location->routes[1]->f2)->DontFetchNextWare();
284
 
                        //              else
285
 
                        //                      LOG.lprintf("Ware::RemoveWareJobForCurrentDi: WARNING: Ware in front of building!\n");
286
 
                        //      }
287
 
                        //      else
288
 
                        //              LOG.lprintf("Ware::RemoveWareJobForCurrentDir: WARNING: Ware in front of building site (gf: %lu)!\n",GAMECLIENT.GetGFNumber());
289
 
                        //}
290
 
        }
 
250
    // last_next_dir war die letzte Richtung, in die die Ware eigentlich wollte,
 
251
    // aber nun nicht mehr will, deshalb muss dem Träger Bescheid gesagt werden
 
252
 
 
253
    // War's überhaupt ne richtige Richtung?
 
254
    if(last_next_dir < 6)
 
255
    {
 
256
        // Existiert da noch ne Straße?
 
257
        if(location->routes[last_next_dir])
 
258
        {
 
259
            // Den Trägern Bescheid sagen
 
260
            location->routes[last_next_dir]->WareJobRemoved(0);
 
261
            // Wenn nicht, könntes ja sein, dass die Straße in ein Lagerhaus führt, dann muss dort Bescheid gesagt werden
 
262
            if(location->routes[last_next_dir]->GetF2()->GetType() == NOP_BUILDING)
 
263
            {
 
264
                if(static_cast<noBuilding*>(location->routes[1]->GetF2())->GetBuildingType() == BLD_HEADQUARTERS ||
 
265
                        static_cast<noBuilding*>(location->routes[1]->GetF2())->GetBuildingType() == BLD_STOREHOUSE ||
 
266
                        static_cast<noBuilding*>(location->routes[1]->GetF2())->GetBuildingType() == BLD_HARBORBUILDING)
 
267
                    static_cast<nobBaseWarehouse*>(location->routes[1]->GetF2())->DontFetchNextWare();
 
268
            }
 
269
        }
 
270
 
 
271
 
 
272
        //// Und stand ein Träger drauf?
 
273
        //if(location->routes[last_next_dir]->carrier)
 
274
        //  location->routes[last_next_dir]->carrier->RemoveWareJob();
 
275
        //// Wenn nicht, könntes ja sein, dass die Straße in ein Lagerhaus führt, dann muss dort Bescheid gesagt werden
 
276
        //else if(location->routes[1])
 
277
        //{
 
278
        //  if(location->routes[1]->f2->GetType() == NOP_BUILDING)
 
279
        //  {
 
280
        //      if(static_cast<noBuilding*>(location->routes[1]->f2)->GetBuildingType() == BLD_HEADQUARTERS ||
 
281
        //         static_cast<noBuilding*>(location->routes[1]->f2)->GetBuildingType() == BLD_STOREHOUSE ||
 
282
        //         static_cast<noBuilding*>(location->routes[1]->f2)->GetBuildingType() == BLD_HARBORBUILDING)
 
283
        //         static_cast<nobBaseWarehouse*>(location->routes[1]->f2)->DontFetchNextWare();
 
284
        //      else
 
285
        //          LOG.lprintf("Ware::RemoveWareJobForCurrentDi: WARNING: Ware in front of building!\n");
 
286
        //  }
 
287
        //  else
 
288
        //      LOG.lprintf("Ware::RemoveWareJobForCurrentDir: WARNING: Ware in front of building site (gf: %lu)!\n",GAMECLIENT.GetGFNumber());
 
289
        //}
 
290
    }
291
291
}
292
292
 
293
293
void Ware::FindRouteToWarehouse()
294
294
{
295
 
        goal = gwg->GetPlayer(location->GetPlayer())->FindWarehouse(location,FW::Condition_StoreWare,0,true,&type,true);
296
 
 
297
 
        if(goal && state == STATE_WAITATFLAG)
298
 
        {
299
 
                //// Bin nun keine LostWare mehr, sondern steige in die Liste der richtigen Waren auf, da ich nun in ein Lagerhaus komme
300
 
                //gwg->GetPlayer(location->GetPlayer()].RemoveLostWare(this);
301
 
                //gwg->GetPlayer(location->GetPlayer()].RegisterWare(this);
302
 
 
303
 
                // Weg suchen
304
 
                next_dir = gwg->FindPathForWareOnRoads(location,goal);
305
 
 
306
 
                // Es wurde ein gültiger Weg gefunden! Dann muss aber noch dem nächsten Träger Bescheid gesagt werden
307
 
                location->routes[next_dir]->AddWareJob(location);
308
 
 
309
 
                // Lagerhaus auch Bescheid sagen
310
 
                static_cast<nobBaseWarehouse*>(goal)->TakeWare(this);
311
 
        }
 
295
    goal = gwg->GetPlayer(location->GetPlayer())->FindWarehouse(location, FW::Condition_StoreWare, 0, true, &type, true);
 
296
 
 
297
    if(goal && state == STATE_WAITATFLAG)
 
298
    {
 
299
        //// Bin nun keine LostWare mehr, sondern steige in die Liste der richtigen Waren auf, da ich nun in ein Lagerhaus komme
 
300
        //gwg->GetPlayer(location->GetPlayer()].RemoveLostWare(this);
 
301
        //gwg->GetPlayer(location->GetPlayer()].RegisterWare(this);
 
302
 
 
303
        // Weg suchen
 
304
        next_dir = gwg->FindPathForWareOnRoads(location, goal);
 
305
 
 
306
        // Es wurde ein gültiger Weg gefunden! Dann muss aber noch dem nächsten Träger Bescheid gesagt werden
 
307
        location->routes[next_dir]->AddWareJob(location);
 
308
 
 
309
        // Lagerhaus auch Bescheid sagen
 
310
        static_cast<nobBaseWarehouse*>(goal)->TakeWare(this);
 
311
    }
312
312
}
313
313
 
314
314
bool Ware::FindRouteFromWarehouse()
315
315
{
316
 
        if(type < 0) 
317
 
                return 0;
318
 
        return (gwg->FindPathForWareOnRoads(location,goal) != 0xFF);
 
316
    if(type < 0)
 
317
        return 0;
 
318
    return (gwg->FindPathForWareOnRoads(location, goal) != 0xFF);
319
319
}
320
320
 
321
321
/// Informiert Ware, dass eine Schiffsreise beginnt
322
322
void Ware::StartShipJourney()
323
323
{
324
 
        state = STATE_ONSHIP;
325
 
        location=0;
 
324
    state = STATE_ONSHIP;
 
325
    location = 0;
326
326
}
327
327
 
328
328
/// Informiert Ware, dass Schiffsreise beendet ist und die Ware nun in einem Hafengebäude liegt
329
 
bool Ware::ShipJorneyEnded(nobHarborBuilding * hb)
 
329
bool Ware::ShipJorneyEnded(nobHarborBuilding* hb)
330
330
{
331
 
        state = STATE_WAITINWAREHOUSE;
332
 
        location = hb;
333
 
 
334
 
        if (goal == NULL)
335
 
        {
336
 
                return(false);
337
 
        }
338
 
 
339
 
        next_dir = gwg->FindPathForWareOnRoads(location,goal,NULL,&next_harbor);
 
331
    state = STATE_WAITINWAREHOUSE;
 
332
    location = hb;
 
333
 
 
334
    if (goal == NULL)
 
335
    {
 
336
        return(false);
 
337
    }
 
338
 
 
339
    next_dir = gwg->FindPathForWareOnRoads(location, goal, NULL, &next_harbor);
340
340
 
341
341
// TODO: SHIP_DIR? order ship etc.
342
 
        if ((next_dir == 0xFF) || (next_dir == SHIP_DIR))
343
 
        {
344
 
                goal->WareLost(this);
345
 
                goal = NULL;
346
 
                return(false);
347
 
        }
 
342
    if ((next_dir == 0xFF) || (next_dir == SHIP_DIR))
 
343
    {
 
344
        goal->WareLost(this);
 
345
        goal = NULL;
 
346
        return(false);
 
347
    }
348
348
 
349
 
        return(true);
 
349
    return(true);
350
350
}
351
351
 
352
352
/// Beginnt damit auf ein Schiff im Hafen zu warten
353
 
void Ware::WaitForShip(nobHarborBuilding * hb)
 
353
void Ware::WaitForShip(nobHarborBuilding* hb)
354
354
{
355
 
        state = STATE_WAITFORSHIP;
356
 
        location = hb;
 
355
    state = STATE_WAITFORSHIP;
 
356
    location = hb;
357
357
}