~widelands-dev/widelands/trunk

« back to all changes in this revision

Viewing changes to src/logic/production_program.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) 2002-2004, 2006, 2008-2009 by the Widelands Development Team
 
2
 * Copyright (C) 2002-2004, 2006, 2008-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
91
91
        ///    economy_condition  ::= "economy" economy_needs
92
92
        ///    site_condition     ::= "site" site_has
93
93
        ///    workers_condition  ::= "workers" workers_need_experience
94
 
        ///    economy_needs      ::= "needs" ware_type
 
94
        ///    economy_needs      ::= "needs" (ware_type|worker_type)
95
95
        ///    site_has           ::= "has" group
96
96
        ///    group              ::= ware_type{,ware_type}[:count]
97
97
        ///    workers_need_experience ::= "need experience"
115
115
        ///       only appear once in the command.
116
116
        ///    economy_needs:
117
117
        ///       The result of this condition depends on whether the economy that
118
 
        ///       this productionsite belongs to needs a ware of the specified type.
119
 
        ///       How this is determined is defined by the economy.
 
118
        ///       this productionsite belongs to needs a ware/worker of the
 
119
        ///       specified type. How this is determined is defined by the economy.
120
120
        ///
121
121
        /// Aborts the execution of the program and sets a return value. Updates the
122
122
        /// productionsite's statistics depending on the return value.
162
162
                };
163
163
 
164
164
                /// Tests whether the economy needs a ware of type ware_type.
165
 
                struct Economy_Needs : public Condition {
166
 
                        Economy_Needs(char * & parameters, Tribe_Descr const &);
 
165
                struct Economy_Needs_Ware : public Condition {
 
166
                        Economy_Needs_Ware(Ware_Index const i) : ware_type(i) {}
167
167
                        virtual bool evaluate(ProductionSite const &) const;
168
168
                        std::string description(Tribe_Descr const &) const;
169
169
#ifdef WRITE_GAME_DATA_AS_HTML
174
174
                        Ware_Index ware_type;
175
175
                };
176
176
 
 
177
                /// Tests whether the economy needs a worker of type worker_type.
 
178
                struct Economy_Needs_Worker : public Condition {
 
179
                        Economy_Needs_Worker(Ware_Index const i) : worker_type(i) {}
 
180
                        virtual bool evaluate(ProductionSite const &) const;
 
181
                        std::string description(Tribe_Descr const &) const;
 
182
#ifdef WRITE_GAME_DATA_AS_HTML
 
183
                        virtual void writeHTML
 
184
                                (::FileWrite &, ProductionSite_Descr const &) const;
 
185
#endif
 
186
                private:
 
187
                        Ware_Index worker_type;
 
188
                };
 
189
 
177
190
                /// Tests whether the site has the specified (or implied) number of
178
191
                /// wares, combining from any of the types specified, in its input
179
192
                /// queues.
388
401
        ///    count:
389
402
        ///       A positive integer. If omitted, the value 1 is used.
390
403
        ///
391
 
        /// For each group, the number of wares specified in count is produced. The
 
404
        /// For each group, the number of wares specified in count are produced. The
392
405
        /// produced wares are of the type specified in the group. How the produced
393
406
        /// wares are handled is defined by the productionsite.
394
407
        struct ActProduce : public Action {
404
417
                Items m_items;
405
418
        };
406
419
 
 
420
        /// Recruits workers.
 
421
        ///
 
422
        /// Parameter syntax:
 
423
        ///    parameters ::= group {group}
 
424
        ///    group      ::= worker_type[:count]
 
425
        /// Parameter semantics:
 
426
        ///    ware_type:
 
427
        ///       The name of a worker type (defined in the tribe). A worker type
 
428
        ///       may only appear once in the command.
 
429
        ///    count:
 
430
        ///       A positive integer. If omitted, the value 1 is used.
 
431
        ///
 
432
        /// For each group, the number of workers specified in count are recruited.
 
433
        /// The recruited workers are of the type specified in the group. How the
 
434
        /// recruited workers are handled is defined by the productionsite.
 
435
        struct ActRecruit : public Action {
 
436
                ActRecruit(char * parameters, ProductionSite_Descr const &);
 
437
                virtual void execute(Game &, ProductionSite &) const;
 
438
#ifdef WRITE_GAME_DATA_AS_HTML
 
439
                virtual void writeHTML
 
440
                        (::FileWrite &, ProductionSite_Descr const &) const;
 
441
#endif
 
442
                typedef std::vector<std::pair<Ware_Index, uint8_t> > Items;
 
443
                Items const & items() const {return m_items;}
 
444
        private:
 
445
                Items m_items;
 
446
        };
 
447
 
407
448
        struct ActMine : public Action {
408
449
                ActMine
409
450
                        (char * parameters, ProductionSite_Descr &,