Quake3World.com Forums
     Programming Discussion
        best place to put your code


Post new topicReply to topic
Login | Profile | | FAQ | Search | IRC




Print view Previous topic | Next topic 
Topic Starter Topic: best place to put your code

Warrior
Warrior
Joined: 13 May 2012
Posts: 90
PostPosted: 04-16-2013 01:08 PM           Profile Send private message  E-mail  Edit post Reply with quote


Hi again.
I create recently a new cvar in order to modify some "basic" Q3A stuff.
Now my cvar, if it's integer, will modify the g_quadfactor, player respawn time and item respawn.
I thinked that the best way to put the various trap_Cvar_Set("g_quadfactor", "etc..." ); was when the server loads and checks all the various cvars but i was wrong, also because the cvar can be changed by the callvote cmd.

The first tryout was, for the quaddamage, on weapon fire...stupid thing, also because the cvar about quadfactor will be set everytime somebody fire......every time...so it will create a lot of work on cpu for nothing.

I erased everything and i'm trying to find out what will be the right spot to put it.
Any suggestion?
Fell free to reply and talk about your considerations.
I repeat, the cvar can be set before the creation of the server and also ingame by callvote, if it's integer it will change the g_quadfactor,g_forcerespawn and g_weaponrespawn, if it's not (so 0) i will trap_Cvar_Set to original q3a ones.
Ty




Top
                 

Insane Quaker
Insane Quaker
Joined: 05 Mar 2010
Posts: 384
PostPosted: 04-16-2013 02:18 PM           Profile Send private message  E-mail  Edit post Reply with quote


Do you mean like a ruleset type of functionality?

Make a new int at the top of g_main.c, call it something like rulesetModCount and make it equal -1.
Let's assume your cvar's name is g_ruleset. Make a new function in g_main.c like what follows:

Code:
void CheckRuleset( void ) {

// return if ruleset hasn't changed
// will also apply at server start since g_ruleset.modificationCount == 0 and rulesetModCount == -1
if ( g_ruleset.modificationCount == rulesetModCount ) return;
rulesetModCount = g_ruleset.modificationCount;

// apply all the cvar changes etc here
switch ( g_ruleset.integer ) {
case 1:
// ...
break;
case 2:
// ...
break;
case 3:
// ...
break;
default:
// ...
break;
}

}


Then call the function from G_RunFrame().




Last edited by themuffinman on 04-17-2013 03:15 AM, edited 1 time in total.

Top
                 

Warrior
Warrior
Joined: 13 May 2012
Posts: 90
PostPosted: 04-16-2013 05:10 PM           Profile Send private message  E-mail  Edit post Reply with quote


ahahah how you know that's the ruleset stuff? so writing it in g_RunFrame(). it will work on server start and also on callvote without being cheked everytime?
using "case" it will work also just with a:
case 1:
if (ruleset.integer ==!){
etc...
}
?
do you wrote multiple cases? O_o i just wanted to turn on or off cpma ruleset or q3a one. I already created a lot of cvars in order to switch on or off also single portion of cpma rules (only fast weapon switch or only ramp jump etc...).
I'm still going mad with the random ctd and trying to understand how to create a command on callvote. i added the ruleset and (before closing the } i added the if statement with arg2, "CPMA" etc...
Also i tried to create a trap_cvar_set just few lines after that (after the g_gametype rules in callvote) in order to mod the various cvars directly by callvote. But i still not understand well how the callvote function works.




Top
                 

Insane Quaker
Insane Quaker
Joined: 05 Mar 2010
Posts: 384
PostPosted: 04-17-2013 03:14 AM           Profile Send private message  E-mail  Edit post Reply with quote


Damnit, the line after the return should be the other way around:
Code:
rulesetModCount = g_ruleset.modificationCount;


Yes to both questions.

The main purpose of Cmd_Callvote_f is to grab the command and to set the vote strings if conditions allow it. Everything that handles the voting and whether it actually passes or not is done in CheckVote() in g_main.c using the level.voteString1 and level.voteString2..

If you're into the whole CPMA thing, maybe this will come in handy: http://q3.atdan.net/pub/code/q3/cpm1_dev_docs.zip




Top
                 

Warrior
Warrior
Joined: 13 May 2012
Posts: 90
PostPosted: 04-18-2013 04:19 PM           Profile Send private message  E-mail  Edit post Reply with quote


i got the cpm developer stuff already. A question: the main stuff he put in the header it's a sort of loopin order to check if the cvar is 1 or not? also, i'm not a C progammer, what mean the 1 ? ) 2 ? 3 at the end of it?
I think i will need to ask you, but before i will try to figure it this weekend, how you made the CA rules. i will left behind for a little the score for every client assigned for the damage done, so i suppose a +=100; the teamcount can be used in order to count everyteam player for team and assign a teamscore when it's <1 ? also i need to work and check the main function about player dead in order to understand how to set him TEAM_SPECTATOR. btw, for my opinion, i'm very curious to see what you have done, you need to release also a vm version only of your mod, like a beta tester and try it with me :D




Top
                 

Insane Quaker
Insane Quaker
Joined: 05 Mar 2010
Posts: 384
PostPosted: 04-19-2013 06:15 AM           Profile Send private message  E-mail  Edit post Reply with quote


3xistence wrote:
A question: the main stuff he put in the header it's a sort of loopin order to check if the cvar is 1 or not? also, i'm not a C progammer, what mean the 1 ? ) 2 ? 3 at the end of it?

You'll have to be more specific. Are you referring to the ternary operators?

3xistence wrote:
I think i will need to ask you, but before i will try to figure it this weekend, how you made the CA rules. i will left behind for a little the score for every client assigned for the damage done, so i suppose a +=100; the teamcount can be used in order to count everyteam player for team and assign a teamscore when it's <1 ? also i need to work and check the main function about player dead in order to understand how to set him TEAM_SPECTATOR.

I haven't coded any CA gametype, but in any case... for individual scoring, ideally you'd add a new entry to persEnum_t for damage given, ie: PERS_DMG_GIVEN (make sure you're not going over MAX_PERSISTANT). In G_Damage() add an int dmgscore and after the initial checks in the function, set it to what the attacker's initial PERS_DMG_GIVEN is. After the damage checks and calculations are complete add the extra damage to PERS_DMG_GIVEN, subtract that from dmgscore to get the difference, multiply it by -1, then if dmgscore is >= 100, divide dmgscore by 100 and then finally AddScore( attacker, attacker->r.currentOrigin, dmgscore ).

Team scoring is pretty much as you said, adding a delay, respawning all players and then going through the whole gamestate change thing for a new round. CheckTournament() may answer a lot of your questions.

Eliminated players should not be set to TEAM_SPECTATOR since that can mess up a lot of crap including the scores. Instead you should set the player as being eliminated with a pm_type (sort of like PM_SPECTATOR) and just inhibit the qualities of a spectator without the team change.

3xistence wrote:
btw, for my opinion, i'm very curious to see what you have done, you need to release also a vm version only of your mod, like a beta tester and try it with me :D


It's still quite a way off from an alpha release, especially with all the hurdles I keep running into. Recently tried adding sky portals and aerial fog support from RtCW, alas, I failed hard. On the plus side I managed to add bloom post-processing...




Top
                 

Warrior
Warrior
Joined: 13 May 2012
Posts: 90
PostPosted: 04-23-2013 11:43 AM           Profile Send private message  E-mail  Edit post Reply with quote


Hi again, i'm trying to do the damagescore stuff as muffin suggest.
few questions: "take" is the damage calculated without the armor damage done and "damage" is all the damage (including knockback and self one)?

Can i assign to a client the PM_SPECTATOR using the string:
(inside player die)
self->client->ps.pm_type = PM_SPECTATOR;
?
And it will make troubles if i assigned the respawn time to = INFINITE in order to don't let players spawn until the match will end?

I need to work on "counts team" stuff, i think the best place to put it is inside the player die stuff (so it will check and count the team members everytime somebody will die until it will reach the == 0 )

Another very dumb question:
using the "switch"
I created some switch code based on a cvar: now i assume that using a switch(cvar.integer) will works ONLY if the cvar is != 0 ...i'm right? there's a way to use a "switch" also if the cvar is == 0 or i need to create before an IF statement like
if (cvar.integer == 0 ){
do stuff;
} else {
switch(cvar.integer){
case 1:
if (cvar.integer == 1){
do stuff;
break;
}
case 2:
if (cvar.integer ==2){
do stuff;
break;
}
etc... ?

Also i'm wondering if i can specify the cvar.integer == 1,2 etc... inside the "case" without adding another IF statement.
like case (cvar.integer == 1):
?
can i create another switch after this one without troubles (for another cvar)?

For the stuff about ruleset i'm inside a deep sea!...i need to understand better the whole stuff. Also where's the best place to put things to CHECK everytime a cvar is modified? I thinked inside the UpdateCvars or similar but after some tries i start to think that isn't the best place.

Some info about coding in C: it's better (ever talking about cvars stuff) use IF statements or Switch? What one will overload more the code?
Let's assume that my cvars do different stuff like from 0 to 4 so there are always 5 IF statements.
thanks you




Top
                 

Insane Quaker
Insane Quaker
Joined: 05 Mar 2010
Posts: 384
PostPosted: 04-25-2013 10:57 AM           Profile Send private message  E-mail  Edit post Reply with quote


1.
Yes, and atake is the damage absorbed by armor.

2.
It should be fine. Then you'll want to apply it to instances of TEAM_SPECTATOR where it doesn't involve messing around with the teams. TeamCount will also need to make provisions for it. Again, If I were you I'd get OpenArena's source code and searching to see how they did GT_ELIMINATION.

3.
http://www.cprogramming.com/tutorial/lesson5.html
You should really go and read the tutorials on that site.

4.
I already told you about modificationCount... didn't my example work?

5.
No idea which is technically more efficient but I'd take a guess and say switches since they're limited to checking integers against a variable.




Top
                 

Warrior
Warrior
Joined: 13 May 2012
Posts: 90
PostPosted: 06-17-2013 02:06 PM           Profile Send private message  E-mail  Edit post Reply with quote


themuffinman wrote:
I haven't coded any CA gametype, but in any case... for individual scoring, ideally you'd add a new entry to persEnum_t for damage given, ie: PERS_DMG_GIVEN (make sure you're not going over MAX_PERSISTANT). In G_Damage() add an int dmgscore and after the initial checks in the function, set it to what the attacker's initial PERS_DMG_GIVEN is. After the damage checks and calculations are complete add the extra damage to PERS_DMG_GIVEN, subtract that from dmgscore to get the difference, multiply it by -1, then if dmgscore is >= 100, divide dmgscore by 100 and then finally AddScore( attacker, attacker->r.currentOrigin, dmgscore ).


maybe i still make some errors but your solution, for my ugly mind will figure out something like this:

Code:
int dmgscore;
PERS_DMG_GIVEN += take += atake;  //PERS_DMG_GIVEN will store all the damage done for all the match
dmgscore = 0;  //the var will be set to zero at start
dmgscore = dmgscore - PERS_DMG_GIVEN;
dmgscore * -1;  //from negative to positive
if (dmgscore >= 100){  //if it exceed the 100
dmgscore = dmgscore / 100;  // divide it
if (dmgscore.integer){   //if it's integer
AddScore( attacker, attacker->r.currentOrigin, dmgscore );    //add to client score, i changed it with a r.currentOrigin, 1 );
}


I didn't tested it, i'm still brainstorming my mind in order to understand how to add 1 score for every 100 or multiples of damage.
Also because in that way if PERS_DMG_GIVEN is >= 100 the game will still add scores also if it the damage done is 120 etc...
a good way was to substract -100 everytime it goes >= 100 and add one score but i will not get the final total damage done at the end of the match.




Top
                 

Insane Quaker
Insane Quaker
Joined: 05 Mar 2010
Posts: 384
PostPosted: 06-18-2013 01:10 PM           Profile Send private message  E-mail  Edit post Reply with quote


Add int accumulateDmgGiven to clientPersistant_t, then add something like this above G_Damage():

Code:
/*
================
G_ScoreFromDamage
muff: used for damage-based scoring for CA etc.
================
*/
static void G_ScoreFromDamage( gentity_t *attacker, const int damage, const int damagePerPoint ) {
   clientPersistant_t *pe = &attacker->client->pers;
   int points = 0;

   if ( !damage || !damagePerPoint ) return;

   // accumulate damage
   pe->accumulateDmgGiven += damage;

   // not enough damage accumulated to score yet
   if ( pe->accumulateDmgGiven < damagePerPoint ) return;
   
   // determine score to add
   points = pe->accumulateDmgGiven / damagePerPoint;

   // save residual damage
   pe->accumulateDmgGiven -= points * damagePerPoint;

   // add score
   AddScore( attacker, attacker->r.currentOrigin, points );
}


Then add that to G_Damage() somewhere after the damage calculations (and preferably using a seperate damage int that is capped to the target's total health and armor):
Code:
   G_ScoreFromDamage( attacker, dmgCapped, 100 );




Top
                 

Warrior
Warrior
Joined: 13 May 2012
Posts: 90
PostPosted: 06-21-2013 01:19 PM           Profile Send private message  E-mail  Edit post Reply with quote


so you suggest to create a new function and maybe i can add a little check like if (g_gametype.integer == GT_CA ) {
G_ScoreFromDamage ();
}
For now i haven't added new functions (just a couple for hud and graphics). I will think about it (usually i want to understand what i do before to write something on code...also because i'm still using just notepad and i can't easily turn back)
I got a new problem, right now i'm still working on graphics hud shaders etc...
I find the code that say to the game to put the proximity mine blue if the player is TEAM_BLUE...now...the strange stuff is that i can't find the code which tells the game to put it red when a player is inside a TEAM_RED. I'm dumb or this thing isn't in the same place of blue mine code? For now my progress are very few, i got few stuff, where i think i will be able to find a solution, that i'm working on:
1.Railtrail, strangely the base code for cg_oldrail 0 (so the one with spiral) seems that makes the trail dishappear when you aim the "space" or "sky" (sometimes i can just see the trail but like if somebody else very far from me shooted it)
2. Some weird problem about this proximity mines shader, i can't find where's the code about red mines if you are on red team
3. Modify the chaingun speed like quakelive, in TA if you got a lot of ammo for chaingun you can kill easily everybody.

For other stuff i'm too slow and unexperienced and nothing's done. Everyday my TO DO LIST grows and the DONE one still be nearby the same :D
A Question about your mod, do you managed to add also q2 maps, entities etc...? ...and most of all (i'm a fan of quakeworld)...your mod will allow to play also q1 maps? :P°°° add me on QL! i'm "3XistenCE"




Top
                 

Insane Quaker
Insane Quaker
Joined: 05 Mar 2010
Posts: 384
PostPosted: 06-22-2013 02:20 AM           Profile Send private message  E-mail  Edit post Reply with quote


3xistence wrote:
also because i'm still using just notepad


Holy cow, no wonder you're struggling and making a ton of mistakes, and you'll continue to do so as long as you're using Notepad.

3xistence wrote:
1.Railtrail, strangely the base code for cg_oldrail 0 (so the one with spiral) seems that makes the trail dishappear when you aim the "space" or "sky" (sometimes i can just see the trail but like if somebody else very far from me shooted it)
2. Some weird problem about this proximity mines shader, i can't find where's the code about red mines if you are on red team
3. Modify the chaingun speed like quakelive, in TA if you got a lot of ammo for chaingun you can kill easily everybody.


1. That is indeed a glitch with the spiral code, not sure how to fix it. It might be a server side issue with tracing for SURF_SKY so that the cgame knows where the endpos is.
2. That's because the missile model is set to red by default ( in CG_RegisterWeapon() ), hence why it only needs to check to see if cent->currentState.generic1 is TEAM_BLUE in CG_Missile().
3. You'll need to make a new int for a timer in playerState_t, then do a few modifications in PM_Weapon(). The timer will have to be reset to zero when it detects no BUTTON_ATTACK, set to 1000 on initial key press, and have to be counted down to zero with pml.msec near the top but after the initial return checks in that function. Then just addTime *= 2 near the end right after considerations for PW_HASTE whenever the timer > 0.

3xistence wrote:
A Question about your mod, do you managed to add also q2 maps, entities etc...? ...and most of all (i'm a fan of quakeworld)...your mod will allow to play also q1 maps? :P°°° add me on QL! i'm "3XistenCE"


No Q2 BSP/WAL/PAK support yet. I did rewrite a bunch of code for BSPs but I haven't been brave enough to compile it yet! The collision map loading should be fine but the rendering is another story. Most entities from Q2 have been added ages ago (func_door_rotating; func_door_secret; target_changelevel; info_player_coop and spawn point handling for co-op/missions and optional spawn pads; most items including keys, power armor, ammo pack and bandolier, adrenaline; etc.) but still need assets made where appropriate (I'm no model designer). I haven't even contemplated Q1 map support yet. I have however ported over both QW and Q2 player physics but both still needs some refinements/fixes.




Top
                 

Cool #9
Cool #9
Joined: 01 Dec 2000
Posts: 44138
PostPosted: 06-22-2013 04:35 AM           Profile   Send private message  E-mail  Edit post Reply with quote


What's the goal of your mod, muff? Sounds like a weak EntityPlus clone ;) :p




Top
                 

Insane Quaker
Insane Quaker
Joined: 05 Mar 2010
Posts: 384
PostPosted: 06-22-2013 09:34 AM           Profile Send private message  E-mail  Edit post Reply with quote


Well, the aim is to make an all-in-one type of mod that practically integrates almost every feature from every Quake and every popular mod. Because of my shitty coding skills, the bug fixing is what takes a major amount of time... otherwise I'd have a release version by now!

It's vastly different to your EP mod given that EP's focus is solely on single player missions and Q3 compatibility while this focuses more on MP and has its own modified engine.




Top
                 
Quake3World.com | Forum Index | Programming Discussion


Post new topic Reply to topic


cron
Quake3World.com
© ZeniMax. Zenimax, QUAKE III ARENA, Id Software and associated trademarks are trademarks of the ZeniMax group of companies. All rights reserved.
This is an unofficial fan website without any affiliation with or endorsement by ZeniMax.
All views and opinions expressed are those of the author.