Changeset 194 for code/branches/main_reto_vs05/src/weapon/weapon_manager.cc
- Timestamp:
- Nov 11, 2007, 2:24:50 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/main_reto_vs05/src/weapon/weapon_manager.cc
r189 r194 52 52 bulletCounter_(0), primaryFireRequest_(false), currentState_(IDLE), 53 53 secondaryFireRequest_(false), selectedWeapon_(0), 54 bulletManager_(bulletManager), 55 actionListReadIndex_(0), actionListWriteIndex_(0)54 bulletManager_(bulletManager), secondaryFired_(false), 55 timeSinceNextActionAdded_(0), actionAdded_(false), nextAction_(NOTHING) 56 56 { 57 57 slots_ = new Weapon*[slotSize]; 58 actionList_ = new Action[ACTION_LIST_SIZE];59 for (int i = 0; i < ACTION_LIST_SIZE; i++)60 actionList_[i] = NOTHING;61 58 } 62 59 … … 66 63 if (slots_) 67 64 delete slots_; 68 if (actionList_)69 delete actionList_;70 65 } 71 66 … … 90 85 bool WeaponManager::addAction(const Action act) 91 86 { 92 if ( actionList_[actionListWriteIndex_] == NOTHING)93 { 94 actionList_[actionListWriteIndex_]= act;95 action ListWriteIndex_ = (actionListWriteIndex_ + 1) % ACTION_LIST_SIZE;87 if (nextAction_ != NOTHING) 88 { 89 nextAction_ = act; 90 actionAdded_ = true; 96 91 return true; 97 92 } … … 109 104 void WeaponManager::primaryFire() 110 105 { 111 currentState_ = PRIMARY_FIRE;112 113 // TODO: add the name of the weapon manager. but for that,114 // the factory is required.115 106 SceneNode *temp = sceneMgr_->getRootSceneNode()->createChildSceneNode( 116 107 node_->getSceneNode()->getWorldPosition(), … … 124 115 speed += node_->getWorldSpeed(); 125 116 117 temp->setScale(Vector3(1, 1, 1) * 4); 118 temp->yaw(Degree(-90)); 119 120 bulletManager_->addBullet(new Bullet(temp, bulletEntity, speed)); 121 } 122 123 124 void WeaponManager::primaryFiring(unsigned int time) 125 { 126 if (time > 100) 127 { 128 currentState_ = IDLE; 129 } 130 } 131 132 133 void WeaponManager::secondaryFireRequest() 134 { 135 secondaryFireRequest_ = true; 136 } 137 138 139 void WeaponManager::secondaryFire() 140 { 141 SceneNode *temp = sceneMgr_->getRootSceneNode()->createChildSceneNode( 142 node_->getSceneNode()->getWorldPosition(), 143 node_->getSceneNode()->getWorldOrientation()); 144 145 Entity* bulletEntity = sceneMgr_->createEntity("BulletEntity" 146 + StringConverter::toString(bulletCounter_++), "Barrel.mesh"); 147 148 Vector3 speed = (temp->getOrientation() * Vector3(0, 0, -1)) 149 .normalisedCopy() * slots_[selectedWeapon_]->bulletSpeed_*0.5; 150 speed += node_->getWorldSpeed(); 151 126 152 temp->setScale(Vector3(1, 1, 1) * 10); 127 153 temp->yaw(Degree(-90)); 128 154 129 155 bulletManager_->addBullet(new Bullet(temp, bulletEntity, speed)); 130 131 currentState_ = IDLE; 132 } 133 134 135 void WeaponManager::secondaryFireRequest() 136 { 137 secondaryFireRequest_ = true; 138 } 139 140 void WeaponManager::secondaryFire() 141 { 156 } 157 158 159 void WeaponManager::secondaryFiring(unsigned int time) 160 { 161 if (time > 250) 162 currentState_ = IDLE; 142 163 } 143 164 … … 149 170 return true; 150 171 172 // process action adder 173 if (actionAdded_) 174 { 175 timeSinceNextActionAdded_ = time; 176 actionAdded_ = false; 177 } 178 151 179 switch (currentState_) 152 180 { 153 181 case IDLE: 154 // first, process actions155 if ( actionList_[actionListReadIndex_]!= NOTHING)182 // first, process next action 183 if (nextAction_ != NOTHING) 156 184 { 157 actionListReadIndex_ = (actionListReadIndex_ + 1) % ACTION_LIST_SIZE; 158 break; 185 actionStartTime_ = time; 186 switch (nextAction_) 187 { 188 case RELOAD: 189 break; 190 191 case CHANGE_AMMO: 192 break; 193 194 case SPECIAL: 195 break; 196 197 default: 198 break; 199 } 200 201 // pay attention when multithreaded! 202 nextAction_ = NOTHING; 159 203 } 160 161 switch (actionList_[actionListReadIndex_]) 204 else 162 205 { 163 case RELOAD: 164 break; 165 166 case ZOOM_IN: 167 break; 168 169 case ZOOM_OUT: 170 break; 171 172 default: 173 break; 206 // secondly, execute firing 207 if (primaryFireRequest_ && !(secondaryFired_ && secondaryFireRequest_)) 208 { 209 actionStartTime_ = time; 210 currentState_ = PRIMARY_FIRE; 211 secondaryFired_ = false; 212 primaryFire(); 213 } 214 else if (secondaryFireRequest_) 215 { 216 actionStartTime_ = time; 217 currentState_ = SECONDARY_FIRE; 218 secondaryFired_ = true; 219 secondaryFire(); 220 } 174 221 } 175 222 176 // secondly, execute firing177 if (primaryFireRequest_)178 primaryFire();179 else if (secondaryFireRequest_)180 secondaryFire();181 182 223 break; 183 224 184 225 case PRIMARY_FIRE: 226 primaryFiring((unsigned int)(time - actionStartTime_)); 185 227 break; 186 228 187 229 case SECONDARY_FIRE: 230 secondaryFiring((unsigned int)(time - actionStartTime_)); 188 231 break; 189 232 190 233 case RELOADING: 234 break; 235 236 case CHANGING_AMMO: 191 237 break; 192 238 } … … 194 240 primaryFireRequest_ = false; 195 241 secondaryFireRequest_ = false; 242 243 if (time - timeSinceNextActionAdded_ > nextActionValidityPeriod_) 244 nextAction_ = NOTHING; 196 245 197 246 return true; … … 205 254 for (int i = 0; i < 5; i++) 206 255 weaponList_s[i] = NULL; 207 weaponList_s[0] = new Weapon("Barrel Gun", 10, 2, 500);256 weaponList_s[0] = new Weapon("Barrel Gun", 10, 2, 1000); 208 257 return true; 209 258 }
Note: See TracChangeset
for help on using the changeset viewer.