~widelands-dev/widelands/trunk

« back to all changes in this revision

Viewing changes to src/logic/playercommand.h

  • Committer: sigra
  • Date: 2010-01-04 03:32:50 UTC
  • Revision ID: git-v1:82d9f24adcbde7d19f90434aac5f96c7df58aa10
Fix bug #2924988 (crash when initialization removed between game preload and game start) reported by qcs - Qcumber-some.

Before the game is set up, the tribes are preloaded, which means that it is checked which tribes exist and which initializations each tribe has, so that each player can select a tribe and an initialization. The selected initialization is saved as an index. When the game is finally started, the tribes are fully read. Then a player is initialized with the initialization with the stored index.

But if for example a player has selected the initialization with index 1, then the tribe is edited so that there is no initialization with that index (such as only the initialization with index 0 remains), then the game i started, the tribe fully read, the player initialized with initialization 1, an assertion will fail in debug builds (and an out-of-range access will be done in release builds.

Now throw game_data_error when this happens. Of course it may still behave a bit unexpected if a player selects initialization a with index 0 and then initializaion a is removed and initialization b has index 0, but at least a crash is fixed.

Also make donkey breeding less broken.

git-svn-id: https://widelands.svn.sourceforge.net/svnroot/widelands/trunk@4870 37b2a8de-5219-0410-9f54-a31bc463ab9c

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright (C) 2004, 2006-2009 by the Widelands Development Team
 
2
 * Copyright (C) 2004, 2006-2010 by the Widelands Development Team
3
3
 *
4
4
 * This program is free software; you can redistribute it and/or
5
5
 * modify it under the terms of the GNU General Public License
267
267
};
268
268
 
269
269
 
270
 
struct Cmd_SetTargetQuantity : public Cmd_ChangeTargetQuantity {
271
 
        Cmd_SetTargetQuantity() : Cmd_ChangeTargetQuantity() {}
272
 
        Cmd_SetTargetQuantity
273
 
                (int32_t duetime, Player_Number sender,
274
 
                 uint32_t economy, Ware_Index index,
275
 
                 uint32_t permanent, uint32_t temporary);
276
 
 
277
 
        //  Write/Read these commands to/from a file (for savegames).
278
 
        void Write(FileWrite &, Editor_Game_Base &, Map_Map_Object_Saver  &);
279
 
        void Read (FileRead  &, Editor_Game_Base &, Map_Map_Object_Loader &);
280
 
 
281
 
        virtual uint8_t id() const {return QUEUE_CMD_SETTARGETQUANTITY;}
282
 
 
283
 
        Cmd_SetTargetQuantity(StreamRead &);
284
 
 
285
 
        virtual void execute (Game &);
286
 
        virtual void serialize (StreamWrite &);
287
 
 
288
 
private:
289
 
        uint32_t m_permanent, m_temporary;
290
 
};
291
 
 
292
 
struct Cmd_ResetTargetQuantity : public Cmd_ChangeTargetQuantity {
293
 
        Cmd_ResetTargetQuantity() : Cmd_ChangeTargetQuantity() {}
294
 
        Cmd_ResetTargetQuantity
295
 
                (int32_t duetime, Player_Number sender,
296
 
                 uint32_t economy, Ware_Index index);
297
 
 
298
 
        //  Write/Read these commands to/from a file (for savegames).
299
 
        void Write(FileWrite &, Editor_Game_Base &, Map_Map_Object_Saver  &);
300
 
        void Read (FileRead  &, Editor_Game_Base &, Map_Map_Object_Loader &);
301
 
 
302
 
        virtual uint8_t id() const {return QUEUE_CMD_RESETTARGETQUANTITY;}
303
 
 
304
 
        Cmd_ResetTargetQuantity(StreamRead &);
 
270
struct Cmd_SetWareTargetQuantity : public Cmd_ChangeTargetQuantity {
 
271
        Cmd_SetWareTargetQuantity() : Cmd_ChangeTargetQuantity() {}
 
272
        Cmd_SetWareTargetQuantity
 
273
                (int32_t duetime, Player_Number sender,
 
274
                 uint32_t economy, Ware_Index index,
 
275
                 uint32_t permanent, uint32_t temporary);
 
276
 
 
277
        //  Write/Read these commands to/from a file (for savegames).
 
278
        void Write(FileWrite &, Editor_Game_Base &, Map_Map_Object_Saver  &);
 
279
        void Read (FileRead  &, Editor_Game_Base &, Map_Map_Object_Loader &);
 
280
 
 
281
        virtual uint8_t id() const {return QUEUE_CMD_SETWARETARGETQUANTITY;}
 
282
 
 
283
        Cmd_SetWareTargetQuantity(StreamRead &);
 
284
 
 
285
        virtual void execute (Game &);
 
286
        virtual void serialize (StreamWrite &);
 
287
 
 
288
private:
 
289
        uint32_t m_permanent, m_temporary;
 
290
};
 
291
 
 
292
struct Cmd_ResetWareTargetQuantity : public Cmd_ChangeTargetQuantity {
 
293
        Cmd_ResetWareTargetQuantity() : Cmd_ChangeTargetQuantity() {}
 
294
        Cmd_ResetWareTargetQuantity
 
295
                (int32_t duetime, Player_Number sender,
 
296
                 uint32_t economy, Ware_Index index);
 
297
 
 
298
        //  Write/Read these commands to/from a file (for savegames).
 
299
        void Write(FileWrite &, Editor_Game_Base &, Map_Map_Object_Saver  &);
 
300
        void Read (FileRead  &, Editor_Game_Base &, Map_Map_Object_Loader &);
 
301
 
 
302
        virtual uint8_t id() const {return QUEUE_CMD_RESETWARETARGETQUANTITY;}
 
303
 
 
304
        Cmd_ResetWareTargetQuantity(StreamRead &);
 
305
 
 
306
        virtual void execute (Game &);
 
307
        virtual void serialize (StreamWrite &);
 
308
 
 
309
private:
 
310
        uint32_t m_economy;
 
311
        Ware_Index m_ware_type;
 
312
};
 
313
 
 
314
struct Cmd_SetWorkerTargetQuantity : public Cmd_ChangeTargetQuantity {
 
315
        Cmd_SetWorkerTargetQuantity() : Cmd_ChangeTargetQuantity() {}
 
316
        Cmd_SetWorkerTargetQuantity
 
317
                (int32_t duetime, Player_Number sender,
 
318
                 uint32_t economy, Ware_Index index,
 
319
                 uint32_t permanent, uint32_t temporary);
 
320
 
 
321
        //  Write/Read these commands to/from a file (for savegames).
 
322
        void Write(FileWrite &, Editor_Game_Base &, Map_Map_Object_Saver  &);
 
323
        void Read (FileRead  &, Editor_Game_Base &, Map_Map_Object_Loader &);
 
324
 
 
325
        virtual uint8_t id() const {return QUEUE_CMD_SETWORKERTARGETQUANTITY;}
 
326
 
 
327
        Cmd_SetWorkerTargetQuantity(StreamRead &);
 
328
 
 
329
        virtual void execute (Game &);
 
330
        virtual void serialize (StreamWrite &);
 
331
 
 
332
private:
 
333
        uint32_t m_permanent, m_temporary;
 
334
};
 
335
 
 
336
struct Cmd_ResetWorkerTargetQuantity : public Cmd_ChangeTargetQuantity {
 
337
        Cmd_ResetWorkerTargetQuantity() : Cmd_ChangeTargetQuantity() {}
 
338
        Cmd_ResetWorkerTargetQuantity
 
339
                (int32_t duetime, Player_Number sender,
 
340
                 uint32_t economy, Ware_Index index);
 
341
 
 
342
        //  Write/Read these commands to/from a file (for savegames).
 
343
        void Write(FileWrite &, Editor_Game_Base &, Map_Map_Object_Saver  &);
 
344
        void Read (FileRead  &, Editor_Game_Base &, Map_Map_Object_Loader &);
 
345
 
 
346
        virtual uint8_t id() const {return QUEUE_CMD_RESETWORKERTARGETQUANTITY;}
 
347
 
 
348
        Cmd_ResetWorkerTargetQuantity(StreamRead &);
305
349
 
306
350
        virtual void execute (Game &);
307
351
        virtual void serialize (StreamWrite &);