Swapper buff: press dropweapon to swap places with a nearby enemy. Icon by Melanosuchus
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / buffs.qh
1 #ifndef BUFFS_H
2 #define BUFFS_H
3 // Welcome to the stuff behind the scenes
4 // Below, you will find the list of buffs
5 // Add new buffs here!
6 // Note: Buffs also need spawnfuncs, which are set below
7
8 entity Buff_Type_first;
9 entity Buff_Type_last;
10 .entity enemy; // internal next pointer
11
12 int BUFF_LAST = 1;
13 int BUFF_ALL;
14
15 .int items; // buff ID
16 .string netname; // buff name
17 .string message; // human readable name
18 .vector colormod; // buff color
19 .string model2; // buff sprite
20 .int skin; // buff skin
21 .float buff_time;
22
23 // hacky function to return the cvar value only to server - TODO: do this properly!
24 float sv_cvar(string cvarname)
25 {
26 #ifdef SVQC
27         return cvar(cvarname);
28 #else
29         return 0;
30 #endif
31 }
32
33 #define REGISTER_BUFF(hname,sname,NAME,bskin,bcolor) \
34         int BUFF_##NAME; \
35         entity Buff_Type##sname; \
36         void RegisterBuffs_##sname() \
37         { \
38                 BUFF_##NAME = BUFF_LAST * 2; \
39                 BUFF_LAST = BUFF_##NAME; \
40                 BUFF_ALL |= BUFF_##NAME; \
41                 Buff_Type##sname = spawn(); \
42                 Buff_Type##sname.items = BUFF_##NAME; \
43                 Buff_Type##sname.netname = #sname; \
44                 Buff_Type##sname.message = hname; \
45                 Buff_Type##sname.skin = bskin; \
46                 Buff_Type##sname.colormod = bcolor; \
47                 Buff_Type##sname.buff_time = sv_cvar(strcat("g_buffs_", #sname, "_time")); \
48                 Buff_Type##sname.model2 = strzone(strcat("buff-", #sname)); \
49                 if(!Buff_Type_first) \
50                         Buff_Type_first = Buff_Type##sname; \
51                 if(Buff_Type_last) \
52                         Buff_Type_last.enemy = Buff_Type##sname; \
53                 Buff_Type_last = Buff_Type##sname; \
54         } \
55         ACCUMULATE_FUNCTION(RegisterBuffs, RegisterBuffs_##sname)
56
57 REGISTER_BUFF(_("Ammo"),ammo,AMMO,3,'0.2 1 0.2');
58 REGISTER_BUFF(_("Resistance"),resistance,RESISTANCE,0,'0.3 0.2 1');
59 REGISTER_BUFF(_("Speed"),speed,SPEED,9,'1 1 0.2');
60 REGISTER_BUFF(_("Medic"),medic,MEDIC,1,'1 0.3 1');
61 REGISTER_BUFF(_("Bash"),bash,BASH,5,'1 0.4 0');
62 REGISTER_BUFF(_("Vampire"),vampire,VAMPIRE,2,'1 0.15 0');
63 REGISTER_BUFF(_("Disability"),disability,DISABILITY,7,'0.66 0.66 0.73');
64 REGISTER_BUFF(_("Vengeance"),vengeance,VENGEANCE,15,'0.55 0.5 1');
65 REGISTER_BUFF(_("Jump"),jump,JUMP,10,'0.7 0.2 1');
66 REGISTER_BUFF(_("Flight"),flight,FLIGHT,11,'1 0.2 0.5');
67 REGISTER_BUFF(_("Invisible"),invisible,INVISIBLE,12,'0.9 0.9 0.9');
68 REGISTER_BUFF(_("Inferno"),inferno,INFERNO,16,'2 0 0');
69 REGISTER_BUFF(_("Swapper"),swapper,SWAPPER,17,'0.59 0 0.95');
70 #undef REGISTER_BUFF
71
72 #ifdef SVQC
73 .int buffs;
74 void buff_Init(entity ent);
75 void buff_Init_Compat(entity ent, int replacement);
76
77 #define BUFF_SPAWNFUNC(e,b,t) void spawnfunc_item_buff_##e() { self.buffs = b; self.team = t; buff_Init(self); }
78 #define BUFF_SPAWNFUNC_Q3TA_COMPAT(o,r) void spawnfunc_item_##o() { buff_Init_Compat(self,r); }
79 #define BUFF_SPAWNFUNCS(e,b)                         \
80         BUFF_SPAWNFUNC(e,           b,  0)           \
81         BUFF_SPAWNFUNC(e##_team1,   b,  NUM_TEAM_1) \
82         BUFF_SPAWNFUNC(e##_team2,   b,  NUM_TEAM_2) \
83         BUFF_SPAWNFUNC(e##_team3,   b,  NUM_TEAM_3) \
84         BUFF_SPAWNFUNC(e##_team4,   b,  NUM_TEAM_4)
85
86 BUFF_SPAWNFUNCS(resistance,             BUFF_RESISTANCE)
87 BUFF_SPAWNFUNCS(ammo,                   BUFF_AMMO)
88 BUFF_SPAWNFUNCS(speed,                  BUFF_SPEED)
89 BUFF_SPAWNFUNCS(medic,                  BUFF_MEDIC)
90 BUFF_SPAWNFUNCS(bash,                   BUFF_BASH)
91 BUFF_SPAWNFUNCS(vampire,                BUFF_VAMPIRE)
92 BUFF_SPAWNFUNCS(disability,             BUFF_DISABILITY)
93 BUFF_SPAWNFUNCS(vengeance,              BUFF_VENGEANCE)
94 BUFF_SPAWNFUNCS(jump,                   BUFF_JUMP)
95 BUFF_SPAWNFUNCS(flight,                 BUFF_FLIGHT)
96 BUFF_SPAWNFUNCS(invisible,              BUFF_INVISIBLE)
97 BUFF_SPAWNFUNCS(inferno,                BUFF_INFERNO)
98 BUFF_SPAWNFUNCS(swapper,                BUFF_SWAPPER)
99 BUFF_SPAWNFUNCS(random,                 0)
100
101 BUFF_SPAWNFUNC_Q3TA_COMPAT(doubler,    BUFF_MEDIC)
102 BUFF_SPAWNFUNC_Q3TA_COMPAT(resistance, BUFF_RESISTANCE)
103 BUFF_SPAWNFUNC_Q3TA_COMPAT(scout,      BUFF_SPEED)
104 BUFF_SPAWNFUNC_Q3TA_COMPAT(ammoregen,  BUFF_AMMO)
105
106 // actually Q3
107 BUFF_SPAWNFUNC_Q3TA_COMPAT(haste,       BUFF_SPEED)
108 BUFF_SPAWNFUNC_Q3TA_COMPAT(invis,       BUFF_INVISIBLE)
109 BUFF_SPAWNFUNC_Q3TA_COMPAT(medic,       BUFF_MEDIC)
110
111 #undef BUFF_SPAWNFUNC
112 #undef BUFF_SPAWNFUNC_Q3TA_COMPAT
113 #undef BUFF_SPAWNFUNCS
114 #endif
115
116 vector Buff_Color(int buff_id);
117 string Buff_PrettyName(int buff_id);
118 string Buff_Name(int buff_id);
119 int Buff_Type_FromName(string buff_name);
120 int Buff_Type_FromSprite(string buff_sprite);
121 int Buff_Skin(int buff_id);
122 string Buff_Sprite(int buff_id);
123 float Buff_Timer(int buff_id);
124 #endif