/[hegemonie]/hegemonie/GameEngine/HgShip.m
ViewVC logotype

Diff of /hegemonie/GameEngine/HgShip.m

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.8 by nicov, Mon Aug 18 10:37:50 2003 UTC revision 1.9 by nicov, Tue Aug 19 15:51:46 2003 UTC
# Line 34  Line 34 
34    
35  /**  /**
36   * HgShip stores all caracteristic of ship.   * HgShip stores all caracteristic of ship.
37   * Weapons are mobileObject with fuel, fireRate, a list of weapons   * Ships are mobileObject with fuel, a list of weapons
38   * a list of bonus, and to list of capacities.   * a list of bonus, and to list of weapons which can be use.
39   * This class is abstract and must be redefined by a subclass to make   * This class is abstract and must be redefined by a subclass to make
40   * a "real" ship.   * a "real" ship.
41   */   */
42  @implementation HgShip  @implementation HgShip
43    
44  /*  /*
45   * The contructeur is the same as HgMobile.   * The contructor is the same as HgMobile.
46   */   */
47    
48  /**  /**
# Line 58  Line 58 
58   * Post an notification named "updateObject" containing the current game and   * Post an notification named "updateObject" containing the current game and
59   * the current object.   * the current object.
60   */   */
61  - (void) setFuel: (unsigned)fuel  - (void) setFuel: (int)fuel
62  {  {
63      NSParameterAssert (fuel >= 0);
64    
65    _fuel = fuel;    _fuel = fuel;
66    
67    [[NSNotificationCenter defaultCenter] postNotificationName: @"updateObject"    [[NSNotificationCenter defaultCenter] postNotificationName: @"updateObject"
# Line 73  Line 75 
75    /* FIXME - update fuel */    /* FIXME - update fuel */
76  }  }
77    
 /**  
  * Return the ship fireRate.  
  */  
 - (unsigned) fireRate  
 {  
   return _fireRate;  
 }  
78    
79  /**  /**
80   * Change the ship fireRate.   * Return the ship weaponsCapacities. It contains the weapons which can be
81   * Post an notification named "updateObject" containing the current game and   * use by the current ship.
  * the current object.  
82   */   */
83  - (void) setFireRate: (unsigned)fireRate  - (NSArray *) weaponsCapacities
84  {  {
85    _fireRate = fireRate;    return _weaponsCapacities;
   
   [[NSNotificationCenter defaultCenter] postNotificationName: @"updateObject"  
                                                       object: [self game]  
                 userInfo: [NSDictionary dictionaryWithObject: self  
                                                       forKey: @"HgObject"]];  
86  }  }
87    
88  /**  /**
# Line 104  Line 93 
93    return _weapons;    return _weapons;
94  }  }
95    
96  /**  /**
97   * Return the ship weaponsCapacities.   * Add a weapon to the current ship.
  */  
 - (NSArray *) weaponsCapacities  
 {  
   return _weaponsCapacities;  
 }  
   
 /**  
  * Return the current ship's bonus.  
  */  
 - (HgBonus *) bonus  
 {  
   
   /*  
    * FIXME: pointeur incompatible  
    */  
   // return _bonus;  
   return nil;  
 }  
   
 /**  
  * Add a bonus to the ship.  
98   * Post an notification named "updateObject" containing the current game and   * Post an notification named "updateObject" containing the current game and
99   * the current object.   * the current object.
100   */   */
101  - (void) addBonus: (NSMutableArray *)bonus  - (void) addWeapon: (HgWeapon *)weapon
102  {  {
103    NSParameterAssert (bonus);    NSParameterAssert (weapon);
104    NSParameterAssert (![_bonuses containsObject: bonus]);    
105      [_weapons addObject: weapon];
106    [_bonuses addObject: bonus];    
   
107    [[NSNotificationCenter defaultCenter] postNotificationName: @"updateObject"    [[NSNotificationCenter defaultCenter] postNotificationName: @"updateObject"
108                                                        object: [self game]                                                        object: [self game]
109                  userInfo: [NSDictionary dictionaryWithObject: self                  userInfo: [NSDictionary dictionaryWithObject: self
110                                                        forKey: @"HgObject"]];                                                        forKey: @"HgObject"]];
111  }  }
112    
113  /**  /**
114   * Remove the first bonus of the ship.   * Remove a weapon to the current ship.
115   * The bonus must exists and be contains in the bonus ship list.   * Th weapon must exists and it must be contains in the weapons list.
116   * Post an notification named "updateObject" containing the current game and   * Post an notification named "updateObject" containing the current game and
117   * the current object.   * the current object.
118     * Post an notification named "LgFire".
119   */   */
120  - (void) removeBonus: (NSMutableArray *)bonus  - (void) fireWeapon: (HgWeapon *)weapon
121  {  {
122    NSParameterAssert (bonus);    NSParameterAssert (weapon);
123    NSParameterAssert ([_bonuses containsObject: bonus]);    NSParameterAssert ([_weapons containsObject: weapon]);
124        
125    [_bonuses removeObject: bonus];    [_weapons removeObject: weapon];
126    
127    [[NSNotificationCenter defaultCenter] postNotificationName: @"updateObject"    [[NSNotificationCenter defaultCenter] postNotificationName: @"updateObject"
128                                                        object: [self game]                                                        object: [self game]
129                  userInfo: [NSDictionary dictionaryWithObject: self                  userInfo: [NSDictionary dictionaryWithObject: self
130                                                        forKey: @"HgObject"]];                                                        forKey: @"HgObject"]];
131    
132      [[NSNotificationCenter defaultCenter] postNotificationName: @"LgFire"
133                                                          object: [self game]
134                    userInfo: [NSDictionary dictionaryWithObject: weapon
135                                                          forKey: @"HgWeapon"]];
136  }  }
137    
138    
139  /**  /**
140   * Return the ship ammo.   * Return the ship ammos.
141   */   */
142  - (unsigned) nbAmmos  - (unsigned) nbAmmos
143  {  {
144    return _ammo;    return _ammos;
145  }  }
146    
147  /**  /**
148   * Change the ship fireRate.   * Add the ammos quantity.
149   * Post an notification named "updateObject" containing the current game and   * Post an notification named "updateObject" containing the current game and
150   * the current object.   * the current object.
151   */   */
152  - (void) setNbAmmo: (unsigned)nbAmmo  - (void) addAmmos: (int)quantity
153  {  {
154    _ammo = nbAmmo;    NSParameterAssert (quantity >= 0);
155      
156      _ammos += quantity;
157    
158    [[NSNotificationCenter defaultCenter] postNotificationName: @"updateObject"    [[NSNotificationCenter defaultCenter] postNotificationName: @"updateObject"
159                                                        object: [self game]                                                        object: [self game]
# Line 186  Line 162 
162  }  }
163    
164  /**  /**
165   * Update the ammo quantity when they're used.   * Update the ammos quantity when they're used.
166   * Post an notification named "updateObject" containing the current game and   * Post an notification named "updateObject" containing the current game and
167   * the current object.   * the current object.
168     * Post an notification named "LgFire".
169   */   */
170  - (void) useAmmos: (unsigned)quantity  - (void) fireAmmos: (int)quantity
171  {  {
172    _ammo = (_ammo - quantity);    NSParameterAssert (quantity >= 0);
173      
174      _ammos -= quantity;
175    
176      if (_ammos <= 0)
177        _ammos = 0;
178      
179    [[NSNotificationCenter defaultCenter] postNotificationName: @"updateObject"    [[NSNotificationCenter defaultCenter] postNotificationName: @"updateObject"
180                                                        object: [self game]                                                        object: [self game]
181                  userInfo: [NSDictionary dictionaryWithObject: self                  userInfo: [NSDictionary dictionaryWithObject: self
182                                                        forKey: @"HgObject"]];                                                        forKey: @"HgObject"]];
183    
184      /** FIXE ME : the weapon init**/
185      [[NSNotificationCenter defaultCenter] postNotificationName: @"LgFire"
186                                                          object: [self game]
187                    userInfo: [NSDictionary dictionaryWithObject: [HgWeapon weapon]
188                                                          forKey: @"HgWeapon"]];
189    
190  }  }
191    
192    
193  /**  /**
194   * Restore the ammo quantity.   * Return the current ship's bonus. This is the last bonus.
195     */
196    - (HgBonus *) currentBonus
197    {
198      return [_bonuses lastObject];
199    }
200    
201    /**
202     * Return the bonus list of the current ship.
203     */
204    - (NSArray *) bonuses
205    {
206      return _bonuses;
207    }
208    
209    /**
210     * Add a bonus to the ship.
211   * Post an notification named "updateObject" containing the current game and   * Post an notification named "updateObject" containing the current game and
212   * the current object.   * the current object.
213   */   */
214  - (void) addAmmos: (unsigned)quantity  - (void) addBonus: (HgBonus *)bonus
215  {  {
216    _ammo = (_ammo + quantity);    NSParameterAssert (bonus);
217      NSParameterAssert (![_bonuses containsObject: bonus]);
218    
219      [_bonuses addObject: bonus];
220    
221    [[NSNotificationCenter defaultCenter] postNotificationName: @"updateObject"    [[NSNotificationCenter defaultCenter] postNotificationName: @"updateObject"
222                                                        object: [self game]                                                        object: [self game]
# Line 215  Line 224 
224                                                        forKey: @"HgObject"]];                                                        forKey: @"HgObject"]];
225  }  }
226    
227    /**
228     * Activate the current ship's bonus. This is the last bonus.
229     */
230    - (void) activateCurrentBonus
231    {
232      [[_bonuses lastObject] activate: YES];
233      [_bonuses removeLastObject];
234    }
235    
236    
237  @end  @end
238    
239  @implementation HgShip (NSCoding)  @implementation HgShip (NSCoding)
# Line 228  Line 247 
247    [super encodeWithCoder: encoder];    [super encodeWithCoder: encoder];
248    [encoder encodeObject: _bonuses];    [encoder encodeObject: _bonuses];
249    [encoder encodeValueOfObjCType: "I" at: &_fuel];    [encoder encodeValueOfObjCType: "I" at: &_fuel];
250    [encoder encodeValueOfObjCType: "I" at: &_fireRate];    [encoder encodeValueOfObjCType: "I" at: &_ammos];
251    [encoder encodeObject: _weaponsCapacities];    [encoder encodeObject: _weaponsCapacities];
252    [encoder encodeObject: _weapons];    [encoder encodeObject: _weapons];
   [encoder encodeValueOfObjCType: "I" at: &_ammo];  
253  }  }
254    
255  - (id)initWithCoder: (NSCoder *)decoder  - (id)initWithCoder: (NSCoder *)decoder
# Line 240  Line 258 
258      {      {
259        _bonuses = RETAIN([decoder decodeObject]);        _bonuses = RETAIN([decoder decodeObject]);
260        [decoder decodeValueOfObjCType: "I" at: &_fuel];        [decoder decodeValueOfObjCType: "I" at: &_fuel];
261        [decoder decodeValueOfObjCType: "I" at: &_fireRate];        [decoder decodeValueOfObjCType: "I" at: &_ammos];
262        _weaponsCapacities = RETAIN([decoder decodeObject]);        _weaponsCapacities = RETAIN([decoder decodeObject]);
263        _weapons = RETAIN([decoder decodeObject]);        _weapons = RETAIN([decoder decodeObject]);
       [decoder decodeValueOfObjCType: "I" at: &_ammo];  
264      }      }
265        
266    return self;    return self;

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.9

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26