Changeset 4826 in orxonox.OLD for orxonox/trunk/src/world_entities/weapons
- Timestamp:
- Jul 8, 2005, 7:02:18 PM (19 years ago)
- Location:
- orxonox/trunk/src/world_entities/weapons
- Files:
-
- 2 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/world_entities/weapons/crosshair.cc
r4824 r4826 23 23 #include "p_node.h" 24 24 #include "state.h" 25 26 #include <iostream> 25 27 26 28 using namespace std; … … 113 115 */ 114 116 117 115 118 GraphicsEngine::storeMatrices(); 116 119 117 GLfloat z;118 glReadPixels ((int)position2D[0], GraphicsEngine::getInstance()->getResolutionY()-(int)position2D[1] , 1, 1, GL_DEPTH_COMPONENT, GL_DOUBLE, &z);120 float z; 121 glReadPixels ((int)position2D[0], GraphicsEngine::getInstance()->getResolutionY()-(int)position2D[1]-1, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &z); 119 122 120 printf("%p:: %d %d %f\n",this, (int)position2D[0], (int)position2D[1], z); 123 124 printf("%f %f %f\n", (int)position2D[0], (int)position2D[1], z); 125 126 //cout << z <<" "<< scale << " " << bias<< endl; 121 127 122 128 GLdouble objX, objY, objZ; 123 if (gluUnProject(position2D[0],124 GraphicsEngine::getInstance()->getResolutionY()-position2D[1],125 z,126 GraphicsEngine::modMat,127 GraphicsEngine::projMat,128 GraphicsEngine::viewPort,129 &objX,130 &objY,131 &objZ ));132 /* 129 gluUnProject(position2D[0], 130 GraphicsEngine::getInstance()->getResolutionY()-position2D[1]-1, 131 .5, 132 GraphicsEngine::modMat, 133 GraphicsEngine::projMat, 134 GraphicsEngine::viewPort, 135 &objX, 136 &objY, 137 &objZ ); 138 133 139 glBegin(GL_TRIANGLES); 134 140 glColor3f(1,0,0); … … 137 143 glVertex3f(objX, objY, objZ+1); 138 144 glEnd(); 139 */140 145 } -
orxonox/trunk/src/world_entities/weapons/weapon.cc
r4758 r4826 1 2 1 3 2 /* … … 11 10 any later version. 12 11 13 12 ### File Specific 14 13 main-programmer: Patrick Boenzli 15 14 co-programmer: 16 15 */ 17 16 18 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON 19 17 #include "weapon_manager.h" 20 18 #include "weapon.h" 21 19 #include "stdincl.h" … … 27 25 #include "world.h" 28 26 29 using namespace std;30 31 32 33 /**34 \brief this initializes the weaponManager for a given nnumber of weapon slots35 \param number of weapon slots of the model/ship <= 8 (limitied)36 */37 WeaponManager::WeaponManager(int nrOfSlots)38 {39 this->setClassID(CL_WEAPON_MANAGER, "WeaponManager");40 41 for(int i = 0; i < W_MAX_CONFIGS; ++i)42 {43 this->configs[i].bUsed = false;44 for(int j = 0; j < W_MAX_SLOTS; ++j)45 this->configs[i].slots[j] = NULL;46 }47 this->nrOfSlots = nrOfSlots;48 this->currConfID = W_CONFIG0;49 }50 51 52 WeaponManager::~WeaponManager()53 {54 /*55 i dont have to delete the weapons itself, because they are56 worldentities and therefore in the entities list of the world.57 world will clean them up for me58 */59 for(int i = 0; i < W_MAX_CONFIGS; ++i)60 {61 this->configs[i].bUsed = false;62 for(int j = 0; j < W_MAX_SLOTS; ++j)63 this->configs[i].slots[j] = NULL;64 }65 }66 67 68 /**69 \brief adds a weapon to the selected weaponconfiguration into the selected slot70 \param the weapon to add71 \param an identifier for the slot: number between 0..7 if not specified: slotID=next free slot72 \param an identifier for the weapon configuration, number between 0..373 74 if you add explicitly a weapon at config:n, slot:m, the weapon placed at this location will be75 replaced by the weapon specified. if you use the W_FREE_SLOT, the manager will look for a free76 slot in this weaponconfiguration. if there is non, the weapon won't be added and there will be77 a error message.78 */79 void WeaponManager::addWeapon(Weapon* weapon, int configID, int slotID)80 {81 if( slotID == W_FREE_SLOT)82 {83 int freeSlot = this->getNextFreeSlot( configID);84 if( freeSlot < 0 || freeSlot >= this->nrOfSlots)85 {86 PRINTF(0)("There is no free slot in this WeaponConfig to dock this weapon at! Aborting\n");87 return;88 }89 PRINTF(3)("Added new Weapon to Config:%i/Slot:%i\n", configID, freeSlot);90 this->configs[configID].bUsed = true;91 this->configs[configID].slots[freeSlot] = weapon;92 return;93 }94 this->configs[configID].bUsed = true;95 this->configs[configID].slots[slotID] = weapon;96 PRINTF(3)("Added a new Weapon to the WeaponManager: config %i/ slot %i\n", configID, slotID);97 }98 99 100 void WeaponManager::removeWeapon(Weapon* weapon, int configID)101 {102 /* empty */103 }104 105 106 /**107 \brief changes to the next weapon configuration108 109 if there are multiple weapon configurations defined by the manager, use this to switch between them110 this function will deactivate the weapons first, change the config and reactivate them later111 */112 void WeaponManager::nextWeaponConf()113 {114 PRINTF(4)("Changing weapon configuration: from %i to next\n", this->currConfID);115 116 int i, lastConfID;117 lastConfID = this->currConfID;118 for(i = this->currConfID + 1; i < W_MAX_CONFIGS && !this->configs[i].bUsed; ++i);119 if( i == W_MAX_CONFIGS) this->currConfID = W_CONFIG0;120 else this->currConfID = i;121 122 123 Weapon *w1, *w2;124 for(int j = 0; j < W_MAX_SLOTS; ++j)125 {126 w1 = this->configs[lastConfID].slots[j];127 w2 = this->configs[this->currConfID].slots[j];128 129 if( w1 == w2)130 {131 printf("no need for change\n");132 }133 else134 {135 if( w1 != NULL )136 {137 w1->deactivate();138 printf("deactivating %i,%i\n", j,lastConfID);139 }140 if( w2 != NULL)141 {142 w2->activate();143 printf("activating %i,%i\n", j, this->currConfID);144 }145 }146 }147 }148 149 150 151 /**152 \brief triggers fire of all weapons in the current weaponconfig153 */154 void WeaponManager::fire()155 {156 Weapon* firingWeapon;157 for(int i = 0; i < W_MAX_SLOTS; ++i)158 {159 firingWeapon = this->configs[this->currConfID].slots[i];160 if( firingWeapon != NULL) firingWeapon->fire();161 }162 }163 164 165 /**166 \brief triggers tick of all weapons in the current weaponconfig167 \param second passed since last tick168 */169 void WeaponManager::tick(float sec)170 {171 Weapon* w;172 for(int i = 0; i < W_MAX_SLOTS; ++i)173 {174 w = this->configs[this->currConfID].slots[i];175 if( w != NULL) w->tick(sec);176 }177 }178 179 180 /**181 \brief triggers draw of all weapons in the current weaponconfig182 */183 void WeaponManager::draw()184 {185 Weapon* w;186 for(int i = 0; i < W_MAX_SLOTS; ++i)187 {188 w = this->configs[this->currConfID].slots[i];189 if( w != NULL) w->draw();190 }191 }192 193 194 /**195 \brief private gets the next free slot in a certain weaponconfig196 \param the selected weaponconfig197 */198 int WeaponManager::getNextFreeSlot(int configID)199 {200 for( int i = 0; i < W_MAX_SLOTS; ++i)201 {202 if( this->configs[configID].slots[i] == NULL)203 return i;204 }205 return -1;206 }207 208 209 210 211 212 213 27 /** 214 28 \brief standard constructor -
orxonox/trunk/src/world_entities/weapons/weapon.h
r4759 r4826 3 3 \brief a weapon that a player can use 4 4 5 A Player has a list of weapons, that can be choosen to shoot projectiles6 (projectiles.{cc,h}) at ennemies. These weapons can be shooted sequentially7 or (if able) combined. Therefore you can choose the weapon mode = choose8 a weapon.9 5 10 6 A weapon is characterized by: … … 17 13 o sound file/ressource: this is a pointer to the sound-file/ressource. however it may be represented 18 14 o shooting animation 19 20 21 a player defines one or more weapon configurations. a player has got one to eight22 weapon slots: places where weapons can be attached to. a weapon configuration23 is a matching between weapons and slots.24 Since its clear how many weapons a player will have, there is no list of weapons:25 its hard coded and limited to 8 slots and 4 configs. More would be a waste of26 memory and time you need to customize and change to a weapon config...27 15 */ 28 16 … … 44 32 class TiXmlElement; 45 33 34 35 // typedef enum { 36 // W_SHOOT, 37 // W_EMPTY, 38 // W_RELOAD, 39 // W_SPECIAL1, 40 // W_SPECIAL2, 41 // W_SPECIAL3 42 // } WeaponSoundType; 43 46 44 typedef enum { 45 W_NONE, 47 46 W_SHOOT, 48 W_EMPTY,49 47 W_RELOAD, 50 W_ SPECIAL1,51 W_ SPECIAL2,52 W_ SPECIAL353 } WeaponS oundType;48 W_ACTIVATING, 49 W_DEACTIVATE, 50 W_IDLE, 51 } WeaponState; 54 52 55 56 //! this is an identifier for the slot. there are up to 8 weapon slots -> this means there can't be more than 8 weapons at the same time57 #define W_SLOT0 058 #define W_SLOT1 159 #define W_SLOT2 260 #define W_SLOT3 361 #define W_SLOT4 462 #define W_SLOT5 563 #define W_SLOT6 664 #define W_SLOT7 765 #define W_FREE_SLOT 9966 67 68 //! this is an identifier for the weapon config69 #define W_CONFIG0 070 #define W_CONFIG1 171 #define W_CONFIG2 272 #define W_CONFIG3 373 53 74 54 //! a weapon can be left or right sided … … 76 56 #define W_RIGHT 1 77 57 78 //! this is a weapon Configuration: it has up to 8 slots79 typedef struct weaponConfig {80 bool bUsed; //<! is set to true, if this configuration is81 Weapon* slots[8];82 };83 58 84 59 85 class WeaponManager : public BaseObject {86 public:87 WeaponManager(int nrOfSlots = 2);88 WeaponManager(const TiXmlElement* root);89 ~WeaponManager();90 60 91 void init();92 void loadParams(const TiXmlElement* root);93 94 void addWeapon(Weapon* weapon, int configID = W_CONFIG0, int slotID = W_FREE_SLOT);95 void removeWeapon(Weapon* weapon, int configID = W_CONFIG0);96 void nextWeaponConf();97 98 void fire();99 void tick(float sec);100 void draw();101 102 private:103 int nrOfSlots; //<! number of weapon slots a ship has104 int currConfID; //<! the currently selected config105 weaponConfig configs[4]; //<! a list of four configurations106 107 int getNextFreeSlot(int configID);108 };109 61 110 62 class Weapon : public WorldEntity
Note: See TracChangeset
for help on using the changeset viewer.