medals and clean up... smarter functions

git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@5101 e016b1c5-ed68-44aa-a2f7-31cac88cffde
This commit is contained in:
Rafael Barreto
2010-05-29 19:37:44 +00:00
parent c40c7161a5
commit f86de67884
7 changed files with 89 additions and 78 deletions
+28 -14
View File
@@ -228,6 +228,7 @@ bool good_map()
VARP(hudextras, 0, 0, 3);
int teamworkid = -1;
void showhudextras(char hudextras, char value){
void (*outf)(const char *s, ...) = (hudextras > 1 ? hudoutf : conoutf);
char *(*spam)(const char *s, char *o, int max) = (hudextras == 2 ? stolower : stoupper), o[50];
@@ -235,26 +236,39 @@ void showhudextras(char hudextras, char value){
switch(value)
{
case HE_COMBO:
outf("\f5%s",SSPAM("Combo")); break;
case HE_MASTERCOMBO:
outf("\f5%s",SSPAM("Mastercombo")); break;
case HE_COMBO2:
case HE_COMBO3:
case HE_COMBO4:
case HE_COMBO5:
{
int n = value+1 - HE_COMBO;
if (n > 4) outf("\f3%s",SSPAM("monster combo!!!"));
else if (!n) outf("\f5%s",SSPAM("combo"));
else outf("\f5%s x%d",SSPAM("multi combo"),n);
break;
}
case HE_KILL2:
case HE_KILL3:
case HE_KILL4:
case HE_KILL5:
{
int n = value - HE_KILL2;
if (n > 4) outf("\f3%s",SSPAM("monster kill!!!"));
else if (!n) outf("\f5%s",SSPAM("double kill"));
else outf("\f5%s x%d",SSPAM("multi kill"),n+1);
break;
}
case HE_TEAMWORK:
outf("\f5%s",SSPAM("Teamwork done")); break;
outf("\f5%s",SSPAM("teamwork done")); break;
case HE_FLAGDEFENDED:
outf("\f5%s",SSPAM("You defended the flag")); break;
outf("\f5%s",SSPAM("you defended the flag")); break;
case HE_FLAGCOVERED:
outf("\f5%s",SSPAM("You covered the flag")); break;
case HE_DOUBLEKILL:
outf("\f5%s",SSPAM("Double kill")); break;
case HE_MULTIKILL:
outf("\f5%s",SSPAM("Multi kill")); break;
case HE_MONSTERKILL:
outf("\f5%s",SSPAM("Monster kill")); break;
outf("\f5%s",SSPAM("you covered the flag")); break;
case HE_COVER:
if (teamworkid >= 0) {
playerent *p = getclient(teamworkid);
if (!p || p == player1) teamworkid = -1;
else outf("\f5%s %s",SSPAM("You covered"),p->name); break;
else outf("\f5you covered %s",p->name); break;
}
default:
{
@@ -262,7 +276,7 @@ void showhudextras(char hudextras, char value){
teamworkid = value-100;
playerent *p = getclient(teamworkid);
if (!p || p == player1) teamworkid = -1;
else outf("\f4You replied to %s",p->name);
else outf("\f4you replied to %s",p->name);
}
else outf("\f3Update your client, NOOB!");
break;
-3
View File
@@ -43,9 +43,6 @@ struct entity : persistent_entity
}
};
/** I did not find better place to put this definition FIXME*/
enum { HE_COMBO, HE_MASTERCOMBO, HE_COVER, HE_TEAMWORK, HE_FLAGDEFENDED, HE_FLAGCOVERED, HE_DOUBLEKILL, HE_MULTIKILL, HE_MONSTERKILL, HE_NUM };
enum { GUN_KNIFE = 0, GUN_PISTOL, GUN_RIFLE, GUN_SHOTGUN, GUN_SUBGUN, GUN_SNIPER, GUN_ASSAULT, GUN_GRENADE, GUN_AKIMBO, NUMGUNS };
#define reloadable_gun(g) (g != GUN_KNIFE && g != GUN_GRENADE)
+1 -1
View File
@@ -339,7 +339,7 @@ static const int msgsizes[] = // size inclusive message token, 0 f
SV_SWITCHNAME, 0, SV_SWITCHSKIN, 0, SV_SWITCHTEAM, 0,
SV_CLIENT, 0,
SV_EXTENSION, 0,
SV_MAPIDENT, 3, SV_HUDEXTRAS, 1,
SV_MAPIDENT, 3, SV_HUDEXTRAS, 1, SV_POINTS, 0,
-1
};
+3 -1
View File
@@ -40,7 +40,7 @@ enum
SV_SWITCHNAME, SV_SWITCHSKIN, SV_SWITCHTEAM,
SV_CLIENT,
SV_EXTENSION,
SV_MAPIDENT, SV_HUDEXTRAS, SV_NUM
SV_MAPIDENT, SV_HUDEXTRAS, SV_POINTS, SV_NUM
};
#ifdef _DEBUG
@@ -61,6 +61,8 @@ enum { FM_PICKUP = 0, FM_DROP, FM_LOST, FM_RETURN, FM_SCORE, FM_KTFSCORE, FM_SCO
enum { LMSITEM_CLEAR = 0, LMSITEM_ANNOUNCE, LMSITEM_SPAWN, LMSITEM_NUM };
enum { FTR_INFO = 0, FTR_PLAYERWISH, FTR_AUTOTEAM, FTR_SILENTFORCE, FTR_NUM }; // forceteam-reasons
enum { SP_OK = 0, SP_REFILLMATCH, SP_OK_NUM, SP_WRONGMAP, SP_SPECT, SP_NUM }; // spawn permission (<OK_NUM && isspect: change to active team allowed)
enum { HE_COMBO, HE_COMBO2, HE_COMBO3, HE_COMBO4, HE_COMBO5, HE_TEAMWORK, HE_FLAGDEFENDED, HE_FLAGCOVERED, HE_COVER, HE_KILL2, HE_KILL3, HE_KILL4, HE_KILL5, HE_NUM };
#define DMF 16.0f
#define DNF 100.0f
+27 -32
View File
@@ -349,6 +349,33 @@ void sendf(int cn, int chan, const char *format, ...)
sendpacket(cn, chan, p.finalize(), exclude);
}
void sendextras()
{
if ( gamemillis < nextsendscore ) return;
int count = 0, list[MAXCLIENTS];
loopv(clients) {
client &c = *clients[i];
if ( c.type!=ST_TCPIP || !c.isauthed || !(c.md.updated && c.md.upmillis < gamemillis) ) continue;
list[count] = i;
count++;
}
nextsendscore = gamemillis + (interm ? 10000 : 200);
if ( !count ) return;
packetbuf p(MAXTRANS, ENET_PACKET_FLAG_RELIABLE);
putint(p, SV_POINTS);
putint(p,count);
int *v = list;
loopi(count)
{
client &c = *clients[*v];
putint(p,c.clientnum); putint(p,c.md.points); c.md.updated = false; c.md.upmillis = 0;
v++;
}
sendpacket(-1, 1, p.finalize());
}
void sendservmsg(const char *msg, int client=-1)
{
sendf(client, 1, "ris", SV_SERVMSG, msg);
@@ -3157,38 +3184,6 @@ void linequalitystats(int elapsed)
}
}
// void sendscores() //FIXME
// {
// if ( gamemillis < nextsendscore ) return;
// int count = 0, list[MAXCLIENTS];
// loopv(clients) {
// client &c = *clients[i];
// if ( c.type!=ST_TCPIP || !c.isauthed || !c.md.updatedpoints ) continue;
// list[count] = i;
// count++;
// }
// nextsendscore = gamemillis + (interm ? 10000 : 500);
// if ( !count ) return;
//
// packetbuf p(MAXTRANS, ENET_PACKET_FLAG_RELIABLE);
// putint(p, SV_POINTS);
// putint(p,count);
// int *v = list;
// loopi(count)
// {
// client &c = *clients[*v];
// putint(p,c.clientnum); putint(p,c.state.points); c.md.updatedpoints = false;
// v++;
// }
// ENetPacket *packet = p.finalize();
//
// loopv(clients)
// {
// sendpacket(i, 1, packet);
// }
// }
void serverslice(uint timeout) // main server update, called from cube main loop in sp, or dedicated server loop
{
static int msend = 0, mrec = 0, csend = 0, crec = 0, mnum = 0, cnum = 0;
+4 -4
View File
@@ -196,14 +196,14 @@ struct savedscore
struct medals
{
int points, lasthit, lastgun, combohits, combo, combotime, combodamage, ncombos, ncovers, nhs;
int ask, askmillis, linked, linkmillis, linkreason;
bool updatedpoints;
int ask, askmillis, linked, linkmillis, linkreason, upmillis;
bool updated;
void reset()
{
points = lasthit = lastgun = combohits = combo = combotime = combodamage = ncombos = ncovers = nhs = 0;
askmillis = linkmillis = 0;
askmillis = linkmillis = upmillis = 0;
linkreason = linked = ask = -1;
updatedpoints = false;
updated = false;
}
};
+26 -23
View File
@@ -82,6 +82,12 @@ int checkarea(int maplayout_factor, char *maplayout) {
This part is related to medals system. WIP
*/
inline void addpt(client *c, int points) {
c->md.points += points;
c->md.updated = true;
c->md.upmillis = gamemillis + 200;
}
inline int minhits2combo(int gun)
{
switch (gun)
@@ -111,9 +117,9 @@ void checkcombo (client *target, client *actor, int damage, int gun)
actor->md.combotime+=diffhittime;
actor->md.combodamage+=damage;
int mh2c = minhits2combo(gun);
if ( actor->md.combohits > mh2c && actor->md.combo < 3 && actor->md.combohits % mh2c == 1 ) {
actor->md.combo++;
actor->md.points += 10;
if ( actor->md.combohits > mh2c && actor->md.combohits % mh2c == 1 ) {
if (actor->md.combo < 5) actor->md.combo++;
addpt(actor,10);
actor->md.ncombos++;
}
}
@@ -126,8 +132,8 @@ void checkcombo (client *target, client *actor, int damage, int gun)
actor->md.combohits++;
actor->md.combotime+=diffhittime;
actor->md.combodamage+=damage;
actor->md.combo++;
actor->md.points += 10;
if (actor->md.combo < 5) actor->md.combo++;
addpt(actor,10);
actor->md.ncombos++;
break;
}
@@ -138,7 +144,6 @@ void checkcombo (client *target, client *actor, int damage, int gun)
actor->md.combodamage=0;
actor->md.combohits=0;
}
actor->md.lastgun = gun;
}
@@ -218,7 +223,7 @@ inline void testcover(int msg, int factor, client *actor)
{
if ( a2c < COVERDIST && c2t < COVERDIST && a2t < COVERDIST ) {
sendf(actor->clientnum, 1, "ri2", SV_HUDEXTRAS, msg);
actor->md.points += factor * clientnumber; /** clientnumber now include the spectators... FIXME */
addpt(actor, factor * clientnumber); /** clientnumber now include the spectators... FIXME */
actor->md.ncovers++;
}
}
@@ -286,42 +291,40 @@ void checkfrag (client *target, client *actor, int gun, bool gib)
{
int targethasflag = clienthasflag(target->clientnum);
int actorhasflag = clienthasflag(actor->clientnum);
target->md.points -= 5;
addpt(target,-5);
if(target!=actor) {
if(!isteam(target->team, actor->team)) {
if (m_teammode) {
if(!m_flags) actor->md.points += 5 * target->md.points / 100;
else actor->md.points += 4 * target->md.points / 100;
if(!m_flags) addpt(actor, 5 * target->md.points / 100);
else addpt(actor, 4 * target->md.points / 100);
checkcover (target, actor);
if ( m_htf && actorhasflag >= 0 ) actor->md.points += clientnumber;
if ( m_htf && actorhasflag >= 0 ) addpt(actor, clientnumber);
if ( targethasflag >= 0 ) {
actor->md.points += 3 * clientnumber;
if ( m_htf ) target->md.points -= clientnumber;
addpt(actor, 3 * clientnumber);
if ( m_htf ) addpt(target, -1 * clientnumber);
}
}
else actor->md.points += 3 * target->md.points / 100;
else addpt(actor, 3 * target->md.points / 100);
if (gib) {
if ( gun == GUN_GRENADE ) actor->md.points += 10;
if ( gun == GUN_GRENADE ) addpt(actor, 10);
else if ( gun == GUN_SNIPER ) {
actor->md.points += 15;
addpt(actor, 15);
actor->md.nhs++;
}
else if ( gun == GUN_KNIFE ) actor->md.points += 20;
else if ( gun == GUN_KNIFE ) addpt(actor, 20);
}
else actor->md.points += 10;
else addpt(actor, 10);
if ( actor->md.combo ) sendf(actor->clientnum, 1, "ri2", SV_HUDEXTRAS, actor->md.combo > 2 ? HE_MASTERCOMBO : HE_COMBO);
if ( actor->md.combo ) sendf(actor->clientnum, 1, "ri2", SV_HUDEXTRAS, actor->md.combo-1 + HE_COMBO);
} else {
if ( targethasflag >= 0 ) {
actor->md.points -= 2 * clientnumber;
}
else actor->md.points -= 10;
if ( targethasflag >= 0 ) addpt(actor, -2 * clientnumber);
else addpt(actor, -10);
}
}