| 1 | = Weapon = |
| 2 | A Weapon is an advanced basic class for all the Weapons one can imagine: (Turrets, Rifles, Cannons, etc...) |
| 3 | |
| 4 | __Dependencies__: |
| 5 | * WorldEntity |
| 6 | * [wiki:Projectile Projectile] |
| 7 | |
| 8 | orxonox will support many types of weapons, and it will split them up into two main elements: |
| 9 | 1. __Weapons(/GUNS)__: They are fixed modules coppled in some way with the Ship (static or dynamic) |
| 10 | 2. __[wiki:Projectile Projectiles]__: They get emitted from Weapons/guns in the Direction and speed (and other initial values) given them by __[wiki:Weapon Weapon]__ |
| 11 | |
| 12 | As you can see ''[wiki:Weapon Weapon]'' and ''[wiki:Projectile Projectile]'' will be independant from each other, projectiles only get emitted by guns in a usefull manner. |
| 13 | |
| 14 | == idea == |
| 15 | Each ship may have one or multiple weapons. |
| 16 | Activation/Deactivation is handled over the !WeaponManager, that connects a !WeaponSystem to the ship. |
| 17 | * '''types''': There are different types of guns: |
| 18 | 1. __uni-directionals__: They shoot in a fixed direction |
| 19 | 1. __Turrets__: Shoot in the direction of the Aim (either automatically or with the help of the Mouse/Joystick... |
| 20 | 1. __Orbiters__: Cyrcling around the ship, these guns will fire in a special way |
| 21 | * '''States''': Weapons will cycle through different states as represented here: [[br]] http://www.orxonox.net/additionals/Weapon.png [[br]] |
| 22 | * '''Cycles''': As you can see, there are two main cycles: |
| 23 | 1. The __Activation-Cycle__, where the Weapon gets round up and uninstalled |
| 24 | 2. The __Shoot-Cycle__, where the Weapon fires and reloads. |
| 25 | |
| 26 | == Definition == |
| 27 | {{{ |
| 28 | #!cpp |
| 29 | public: |
| 30 | void requestAction(WeaponAction action); |
| 31 | |
| 32 | inline bool isActive() const; |
| 33 | inline bool isChargeable() const; |
| 34 | |
| 35 | inline void setCapability(long capabilities); |
| 36 | void setProjectileType(ClassID projectile); |
| 37 | void prepareProjectiles(unsigned int count); |
| 38 | |
| 39 | Projectile* getProjectile(); |
| 40 | |
| 41 | void setEmissionPoint(const Vector& point); |
| 42 | inline const Vector& getEmissionPoint() const; |
| 43 | |
| 44 | inline void setStateDuration(WeaponState state, float duration); |
| 45 | |
| 46 | float increaseEnergy(float energyToAdd); |
| 47 | inline void setMaximumEnergy(float energyMax, float energyLoadedMax); |
| 48 | |
| 49 | void setActionSound(WeaponAction action, const char* soundFile); |
| 50 | Animation3D* getAnimation(WeaponState state, PNode* node = NULL); |
| 51 | Animation3D* copyAnimation(WeaponState from, WeaponState to); |
| 52 | |
| 53 | void tickW(float dt); |
| 54 | |
| 55 | bool check() const; |
| 56 | void debug() const; |
| 57 | |
| 58 | protected: |
| 59 | virtual void activate() {}; |
| 60 | virtual void deactivate() {}; |
| 61 | virtual void charge() {}; |
| 62 | virtual void fire() {}; |
| 63 | virtual void reload() {}; |
| 64 | virtual void destroy() {}; |
| 65 | }}} |
| 66 | '''Description:''' |
| 67 | 1. ''Public Functions'': |
| 68 | * __requestAction__: A request to an action the weapon should take next (shooting reloading and so on) |
| 69 | * __setCapability__: The capabilities this weapon has (direction, type of weapon (turret/directional))... |
| 70 | * __setProjectileType__: The Type of Projectiles this Weapon should emit: (This automatically gets the FastFactory for the requested Projectiles). |
| 71 | * __getProjectile__: get a Projectile of the Requested type... then you can fire it :) |
| 72 | * __setEmissionPoint__: Where the Projectile gets emitted from |
| 73 | * __setStateDuration __: How long a Weapon rests in a given state before going to the next one (reloading takes 2 seconds, shooting .5 seconds). |
| 74 | * __increaseEnergy__: add more energy to the Weapon |
| 75 | * __setActionSound__: The Sound of an executed Action (eg. fire, activate, Reload...) |
| 76 | * __getAnimation__: Returns a new Animation for a State. |
| 77 | 2. ''Protected Functions'': These are functions you can extend, if you like to declare in some special Weapon stuff. like turning a weapon and so on. |
| 78 | |
| 79 | == Howto Create a Weapon == |
| 80 | 1. Have a look at the Howto Process of -> WorldEntity. |
| 81 | 2. Define a Projectile |
| 82 | 3. Define some Animations |
| 83 | 4. Have a look at source:/trunk/src/world_entities/weapons/laser.h#HEAD or source:/trunk/src/world_entities/weapons/turret.h#HEAD for examples |
| 84 | 5. Maybe define your own [wiki:Projectile Projectile] |