Inside3D!
     

Problem with FrikQCC and Arrays

 
Post new topic   Reply to topic    Inside3d Forums Forum Index -> QuakeC Programming
View previous topic :: View next topic  
Author Message
Wazat



Joined: 15 Oct 2004
Posts: 732
Location: Middle 'o the desert, USA

PostPosted: Sun Mar 30, 2008 6:19 am    Post subject: Problem with FrikQCC and Arrays Reply with quote

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:

// 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:

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:

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.
Back to top
View user's profile Send private message MSN Messenger
FrikaC
Site Admin


Joined: 08 Oct 2004
Posts: 947

PostPosted: Mon Mar 31, 2008 4:33 pm    Post subject: Reply with quote

Do not use™
Back to top
View user's profile Send private message Send e-mail
Wazat



Joined: 15 Oct 2004
Posts: 732
Location: Middle 'o the desert, USA

PostPosted: Mon Mar 31, 2008 4:46 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message MSN Messenger
Urre



Joined: 05 Nov 2004
Posts: 1073
Location: Sweden

PostPosted: Mon Mar 31, 2008 7:37 pm    Post subject: Reply with quote

Not to rob spotlight off frikqcc, but have you tried fteqcc? I've heard it works fine, Nexuiz uses them...
_________________
Look out for Twigboy
Back to top
View user's profile Send private message Visit poster's website
FrikaC
Site Admin


Joined: 08 Oct 2004
Posts: 947

PostPosted: Mon Mar 31, 2008 8:52 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message Send e-mail
Urre



Joined: 05 Nov 2004
Posts: 1073
Location: Sweden

PostPosted: Mon Mar 31, 2008 8:59 pm    Post subject: Reply with quote

Wicked, frik! Look forward to quaded
_________________
Look out for Twigboy
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Inside3d Forums Forum Index -> QuakeC Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2004 phpBB Group