Forum

Problem with FrikQCC and Arrays

Discuss programming in the QuakeC language.

Moderator: InsideQC Admins

Problem with FrikQCC and Arrays

Postby Wazat » Sun Mar 30, 2008 6:19 am

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.

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

Postby FrikaC » Mon Mar 31, 2008 4:33 pm

Do not use™
FrikaC
Site Admin
 
Posts: 1026
Joined: Fri Oct 08, 2004 11:19 pm

Postby Wazat » Mon Mar 31, 2008 4:46 pm

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

Postby Urre » Mon Mar 31, 2008 7:37 pm

Not to rob spotlight off frikqcc, but have you tried fteqcc? I've heard it works fine, Nexuiz uses them...
I was once a Quake modder
User avatar
Urre
 
Posts: 1109
Joined: Fri Nov 05, 2004 2:36 am
Location: Moon

Postby FrikaC » Mon Mar 31, 2008 8:52 pm

Someday I will fix up frikqcc and release an update (it's now within the quaded project so that day may come), until that day I recommend either using fteqcc or using frikqcc and ignoring most of the features.
FrikaC
Site Admin
 
Posts: 1026
Joined: Fri Oct 08, 2004 11:19 pm

Postby Urre » Mon Mar 31, 2008 8:59 pm

Wicked, frik! Look forward to quaded
I was once a Quake modder
User avatar
Urre
 
Posts: 1109
Joined: Fri Nov 05, 2004 2:36 am
Location: Moon


Return to QuakeC Programming

Who is online

Users browsing this forum: Bing [Bot] and 1 guest