~flamefire/s25rttr/s25rttr

« back to all changes in this revision

Viewing changes to src/GameClientPlayer.h

  • Committer: Alex
  • Date: 2013-08-26 17:51:36 UTC
  • Revision ID: alex@flamefire-20130826175136-gc8kpxp7wk1zfhcu
Type safety for checkWareHouse

Show diffs side-by-side

added added

removed removed

Lines of Context:
207
207
        /*/// liefert das aktuelle (komplette) inventar.
208
208
        void GetInventory(unsigned int *wares, unsigned int *figures);*/
209
209
 
 
210
        template <class ParamType>
 
211
        struct IsWarehouseGood
 
212
        {
 
213
                typedef bool (*Check)(nobBaseWarehouse*,typename const ParamType*);
 
214
        };
210
215
 
211
216
        /// Sucht ein nächstgelegenes Warenhaus für den Punkt 'start', das die Bedingung der Ãœbergebenen Funktion
212
217
        /// IsWarehouseGood erfüllt, als letzen Parameter erhält jene Funktion param
213
218
        /// - forbidden ist ein optionales Straßenstück, das nicht betreten werden darf,
214
219
        /// - to_wh muss auf true gesetzt werden, wenn es zum Lagerhaus geht, ansonsten auf false, in length wird die Wegeslänge zurückgegeben
215
 
        nobBaseWarehouse * FindWarehouse(const noRoadNode * const start,bool (*IsWarehouseGood)(nobBaseWarehouse*,const void*),const RoadSegment * const forbidden,const bool to_wh,const void * param,const bool use_boat_roads,unsigned * const length = 0);
 
220
        template< typename ParamType, typename Check >
 
221
        nobBaseWarehouse * FindWarehouse(const noRoadNode * const start,Check isWarehouseGood,const RoadSegment * const forbidden,const bool to_wh,const ParamType &param,const bool use_boat_roads,unsigned * const length = NULL)
 
222
        {
 
223
                nobBaseWarehouse * best = 0;
 
224
 
 
225
                //      unsigned char path = 0xFF, tpath = 0xFF;
 
226
                unsigned tlength = 0xFFFFFFFF,best_length = 0xFFFFFFFF;
 
227
 
 
228
                for(std::list<nobBaseWarehouse*>::iterator w = warehouses.begin(); w!=warehouses.end(); ++w)
 
229
                {
 
230
                        // Lagerhaus geeignet?
 
231
                        if(isWarehouseGood(*w,param))
 
232
                        {
 
233
                                // Bei der erlaubten Benutzung von Bootsstraßen Waren-Pathfinding benutzen
 
234
                                if(gwg->FindPathOnRoads(to_wh ? start : *w, to_wh ? *w : start,use_boat_roads,&tlength,NULL, NULL,forbidden))
 
235
                                {
 
236
                                        if(tlength < best_length || !best)
 
237
                                        {
 
238
                                                //                                      path = tpath;
 
239
                                                best_length = tlength;
 
240
                                                best = (*w);
 
241
                                        }
 
242
                                }
 
243
                        }
 
244
                }
 
245
 
 
246
                if(length)
 
247
                        *length = best_length;
 
248
 
 
249
                return best;
 
250
        }
216
251
        /// Gibt dem Spieler bekannt, das eine neue Straße gebaut wurde
217
252
        void NewRoad(RoadSegment * const rs);
218
253
        /// Neue Straße hinzufügen