How would I convert this cpp code to tge compliant ?
by Jeff Yaskus · in Torque Game Engine · 03/22/2010 (11:24 pm) · 2 replies
I'm trying to merge some old cpp code I have into my tge build.
But I'm not sure how to "convert" the variable types and such to be tge compatible --
i.e. I'm trying to do with .cc code not .cs script.
Here are some of the examples;
or a basic printf ... to dump something to console or such.
or even more complex, load data from a text file
Anything constructive would be appreciated -
But I'm not sure how to "convert" the variable types and such to be tge compatible --
i.e. I'm trying to do with .cc code not .cs script.
Here are some of the examples;
int d100(void)
{
return ((rand() % 100) + 1);
}or a basic printf ... to dump something to console or such.
...
printf("nArmor:(%2d) %s",ArmorType,armor_name);
...or even more complex, load data from a text file
struct wpn_type
{
char name[25];
int fumble;
char crit[5];
int table;
int mod_ob[5];
float mod_hp[5];
int str;
int BF;
int category;
};
wpn_type wpns[49];
int load_weapons(void)
{
FILE *in2 = fopen("weapons.dat","r");
int loop;
if (in2 == NULL)
{
printf("error - unable to load weapons.dat n");
return -1;
}
for (int i=0; i < MAX_WEAPONS; i++)
{
fscanf(in2,"%s ",&wpns[i].name);
fscanf(in2,"%d ",&wpns[i].fumble);
fscanf(in2,"%c ",&wpns[i].crit[0]);
fscanf(in2,"%c ",&wpns[i].crit[1]);
fscanf(in2,"%c ",&wpns[i].crit[2]);
fscanf(in2,"%d ",&wpns[i].table);
for (loop=0; loop < 5; loop++)
{
fscanf(in2,"%d ",&wpns[i].mod_ob[loop]);
fscanf(in2,"%f ",&wpns[i].mod_hp[loop]);
};
fscanf(in2,"%d ",&wpns[i].str);
fscanf(in2,"%d ",&wpns[i].BF);
fscanf(in2,"%d ",&wpns[i].category);
};
fclose(in2);
return 1;
}Anything constructive would be appreciated -
About the author
Long time gamer, hacker and programmer. With dreams of making video games -
#2
03/23/2010 (2:08 pm)
thanks - to be honest, I wasn't sure how to word such a search ... because its all Cpp code just that torque has its own standard format on top, so its cross compatible and such.
Associate William Lee Sims
Machine Code Games
2) Con::printf("nArmor:(%2d) %s",ArmorType,armor_name);
3)
int load_weapons(void) { FileObject f; if( f.readMemory( "weapons.dat" ) == false ) { Con::printf("error - unable to load weapons.dat"); return -1; } const U8 *line; for( S32 i = 0; i < MAX_WEAPONS; ++i ) { line = f.readLine(); dSscanf( (const char *)line, "%s %d %c %c %c %d", &wpns[i].name, &wpns[i].fumble, &wpns[i].crit[0], &wpns[i].crit[1], &wpns[i].crit[2], &wpns[i].table ); // etc... } f.close(); return 1; }You can search TDN to learn more about the function used here. Hope it helps!