Problem with FrikQCC and Arrays
Moderator: InsideQC Admins
6 posts
• Page 1 of 1
Problem with FrikQCC and Arrays
FrikQCC v2.8.0-MM does sound like it will make arrays so much more reasonable. As FrikaC mentions in his documentation, global arrays are a lot less painful to use than the funky entity stuff the older compiler required.
However, I've hit a pretty nasty snag and I'm wondering how I should untangle myself from it. Here's what I'm creating:
The player has 5 weapon slots. He can place any weapon in these slots, and the code needs to be able to get the right information about a weapon regardless of which slot it's been placed in. Each slot stores its own weapon id and currentammo, and may be able to think independently to perform special actions.
Each weapon slot is a .entity so that I can store extra data for each weapon.
.entity wpn1;
.entity wpn2;
.entity wpn3;
.entity wpn4;
.entity wpn5;
Each weapon entity has two fields in use for now: .weapon and .currentammo. To make things easier on myself, I'm trying to use arrays to store the max ammo, weapon name, and weapon model (when dropped as an item) so that I can do easy lookups. Unfortunately, this has turned out to be much harder than the way I did it in Conquest.
Unfortunately, this does not go over well for the compiler, which tells me I should be using the "int" type to access arrays. That's all fine and dandy, but WEP_SHOTGUN and the other constants are used throughout the code! In some places, they're assigned to a .float (for example, self.wpn3.weapon = WEP_LIGHTNING), and other times they're used to access arrays:
There doesn't appear to be a casting method that will make the compiler happy. The manual.txt mentions casting with a = a * %1; however, this doesn't prevent the warning in frikqcc.
I'm not sure how to properly handle this. In Conquest, instead of using arrays I simply had accessor methods:
Would that be the best course of action here?
However, I've hit a pretty nasty snag and I'm wondering how I should untangle myself from it. Here's what I'm creating:
The player has 5 weapon slots. He can place any weapon in these slots, and the code needs to be able to get the right information about a weapon regardless of which slot it's been placed in. Each slot stores its own weapon id and currentammo, and may be able to think independently to perform special actions.
Each weapon slot is a .entity so that I can store extra data for each weapon.
.entity wpn1;
.entity wpn2;
.entity wpn3;
.entity wpn4;
.entity wpn5;
Each weapon entity has two fields in use for now: .weapon and .currentammo. To make things easier on myself, I'm trying to use arrays to store the max ammo, weapon name, and weapon model (when dropped as an item) so that I can do easy lookups. Unfortunately, this has turned out to be much harder than the way I did it in Conquest.
- Code: Select all
// weapon max ammo
float[WEP_NUM_WEAPONS] WEP_MAX_AMMO;
// weapon names
string[WEP_NUM_WEAPONS] WEP_NAME;
// weapon models
string[WEP_NUM_WEAPONS] WEP_ITEM_MODEL;
void InitGlobalArrays()
{
WEP_NAME[WEP_AXE] = "Axe";
WEP_ITEM_MODEL[WEP_AXE] = ""; // will never drop the axe
WEP_MAX_AMMO[WEP_AXE] = 0;
WEP_NAME[WEP_SHOTGUN] = "Shotgun";
WEP_ITEM_MODEL[WEP_SHOTGUN] = "maps/b_shell0.bsp"; // FIXME: need shotgun model
WEP_MAX_AMMO[WEP_SHOTGUN] = 50;
WEP_NAME[WEP_SUPER_SHOTGUN] = "Super Shotgun";
WEP_ITEM_MODEL[WEP_SUPER_SHOTGUN] = "progs/g_shot.mdl";
WEP_MAX_AMMO[WEP_SUPER_SHOTGUN] = 100;
WEP_NAME[WEP_NAILGUN] = "Nailgun";
WEP_ITEM_MODEL[WEP_NAILGUN] = "progs/g_nail.mdl";
WEP_MAX_AMMO[WEP_NAILGUN] = 200;
WEP_NAME[WEP_SUPER_NAILGUN] = "Super Nailgun";
WEP_ITEM_MODEL[WEP_SUPER_NAILGUN] = "progs/g_nail2.mdl";
WEP_MAX_AMMO[WEP_SUPER_NAILGUN] = 200;
WEP_NAME[WEP_GRENADE_LAUNCHER] = "Grenade Launcher";
WEP_ITEM_MODEL[WEP_GRENADE_LAUNCHER] = "progs/g_rock.mdl";
WEP_MAX_AMMO[WEP_GRENADE_LAUNCHER] = 20;
WEP_NAME[WEP_ROCKET_LAUNCHER] = "Rocket Launcher";
WEP_ITEM_MODEL[WEP_ROCKET_LAUNCHER] = "progs/g_rock2.mdl";
WEP_MAX_AMMO[WEP_ROCKET_LAUNCHER] = 20;
WEP_NAME[WEP_LIGHTNING] = "Lightning Cannon";
WEP_ITEM_MODEL[WEP_LIGHTNING] = "progs/g_light.mdl";
WEP_MAX_AMMO[WEP_LIGHTNING] = 80;
}
Unfortunately, this does not go over well for the compiler, which tells me I should be using the "int" type to access arrays. That's all fine and dandy, but WEP_SHOTGUN and the other constants are used throughout the code! In some places, they're assigned to a .float (for example, self.wpn3.weapon = WEP_LIGHTNING), and other times they're used to access arrays:
- Code: Select all
setmodel(item, WEP_NAME[self.weapon];
or
setmodel(item, WEP_NAME[WEP_LIGHTNING];
There doesn't appear to be a casting method that will make the compiler happy. The manual.txt mentions casting with a = a * %1; however, this doesn't prevent the warning in frikqcc.
I'm not sure how to properly handle this. In Conquest, instead of using arrays I simply had accessor methods:
- Code: Select all
float getWeaponMaxAmmo(float wep)
{
if(wep == WEP_SHOTGUN)
return AMMO_MAX_SHOTGUN;
....
}
Would that be the best course of action here?
When my computer inevitably explodes and kills me, my cat inherits everything I own. He may be the only one capable of continuing my work.
- Wazat
- Posts: 771
- Joined: Fri Oct 15, 2004 9:50 pm
- Location: Middle 'o the desert, USA
lol, okay will do. Arrays seemed like they'd be really nice, but constants and accessor methods (as I did in Conquest) look like the best way to do this.
When my computer inevitably explodes and kills me, my cat inherits everything I own. He may be the only one capable of continuing my work.
- Wazat
- Posts: 771
- Joined: Fri Oct 15, 2004 9:50 pm
- Location: Middle 'o the desert, USA
6 posts
• Page 1 of 1
Who is online
Users browsing this forum: Bing [Bot] and 1 guest
