MCPcopy Create free account
hub / github.com/assaultcube/AC / shiftweapon

Function shiftweapon

source/src/weapon.cpp:79–122  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

77COMMANDN(weapon, requestweapon, "s");
78
79void shiftweapon(int *s)
80{
81 if(keypressed && player1->state == CS_ALIVE && !ispaused)
82 {
83 if(!player1->weaponsel->deselectable()) return;
84
85 weapon *curweapon = player1->weaponsel;
86 weapon *akimbo = player1->weapons[GUN_AKIMBO];
87
88 // collect available weapons
89 vector<weapon *> availweapons;
90 loopi(NUMGUNS)
91 {
92 weapon *w = player1->weapons[i];
93 if(!w) continue;
94 if(w->selectable() || w==curweapon || (w->type==GUN_PISTOL && player1->akimbo))
95 {
96 availweapons.add(w);
97 }
98 }
99
100 // replace pistol by akimbo
101 if(player1->akimbo)
102 {
103 availweapons.removeobj(akimbo); // and remove initial akimbo
104 int pistolidx = availweapons.find(player1->weapons[GUN_PISTOL]);
105 if(pistolidx>=0) availweapons[pistolidx] = akimbo; // insert at pistols position
106 if(curweapon->type==GUN_PISTOL) curweapon = akimbo; // fix selection
107 }
108
109 // detect the next weapon
110 int num = availweapons.length();
111 int curidx = availweapons.find(curweapon);
112 if(!num || curidx<0) return;
113 int idx = (curidx + *s) % num;
114 if(idx<0) idx += num;
115 weapon *next = availweapons[idx];
116 if(next->type!=player1->weaponsel->type) // different weapon
117 {
118 selectweapon(next);
119 }
120 }
121 else if(player1->isspectating()) updatefollowplayer(*s);
122}
123COMMAND(shiftweapon, "i");
124
125void quicknadethrow(bool on)

Callers

nothing calls this directly

Calls 7

selectweaponFunction · 0.85
updatefollowplayerFunction · 0.85
deselectableMethod · 0.80
removeobjMethod · 0.80
isspectatingMethod · 0.80
findMethod · 0.45
lengthMethod · 0.45

Tested by

no test coverage detected