]> icculus.org git repositories - divverent/nexuiz.git/blob - qcsrc/gamec/t_items.c
more control over starting weapons/ammo/pickups
[divverent/nexuiz.git] / qcsrc / gamec / t_items.c
1 void Item_ClearRespawnEffect (void) {
2         self.effects = self.effects - (self.effects & EF_STARDUST);
3 }
4
5 void Item_Respawn (void)
6 {
7         self.model = self.mdl;          // restore original model
8         self.solid = SOLID_TRIGGER;     // allow it to be touched again
9         sound (self, CHAN_VOICE, "misc/itemrespawn.wav", 1, ATTN_NORM); // play respawn sound
10         setorigin (self, self.origin);
11
12         // Savage: Add simple Respawn effect and make sure it gets removed
13         self.effects = EF_STARDUST;
14         self.think = Item_ClearRespawnEffect;
15         self.nextthink = time + 0.1;
16 }
17
18 void Item_Touch (void)
19 {
20
21         local entity oldself;
22         local float     _switchweapon;
23
24         if (other.classname != "player")
25                 return;
26         if (other.deadflag)
27                 return;
28         if (self.solid != SOLID_TRIGGER)
29                 return;
30         if (self.health && other.health >= other.max_health)
31                 return;
32         // Savage: Remove the respawn effect if still present
33         self.effects = self.effects - (self.effects & EF_STARDUST);
34
35         sound (self, CHAN_BODY, self.noise, 1, ATTN_NORM);
36
37         // if the player is using their best weapon before items are given, they
38         // probably want to switch to an even better weapon after items are given
39         _switchweapon = other.switchweapon == w_getbestweapon(other);
40
41         if (self.ammo_shells)
42                 other.ammo_shells = min (other.ammo_shells + self.ammo_shells, 999);
43         if (self.ammo_nails)
44                 other.ammo_nails = min (other.ammo_nails + self.ammo_nails, 999);
45         if (self.ammo_rockets)
46                 other.ammo_rockets = min (other.ammo_rockets + self.ammo_rockets, 999);
47         if (self.ammo_cells)
48                 other.ammo_cells = min (other.ammo_cells + self.ammo_cells, 999);
49
50         if (self.items & IT_UZI)                                W_GiveWeapon (other, IT_UZI, "Machine gun");
51         if (self.items & IT_SHOTGUN)                    W_GiveWeapon (other, IT_SHOTGUN, "Shotgun");
52         if (self.items & IT_GRENADE_LAUNCHER)   W_GiveWeapon (other, IT_GRENADE_LAUNCHER, "Mortar");
53         if (self.items & IT_ELECTRO)                    W_GiveWeapon (other, IT_ELECTRO, "Electro");
54         if (self.items & IT_NEX)                                W_GiveWeapon (other, IT_NEX, "Nex");
55         if (self.items & IT_HAGAR)                              W_GiveWeapon (other, IT_HAGAR, "Hagar");
56         if (self.items & IT_ROCKET_LAUNCHER)    W_GiveWeapon (other, IT_ROCKET_LAUNCHER, "Rocket Launcher");
57         if (self.items & IT_CRYLINK)                    W_GiveWeapon (other, IT_CRYLINK, "Crylink");
58
59         if (self.strength_finished)
60                 other.strength_finished = max(other.strength_finished, time) + cvar("g_balance_powerup_strength_time");
61         if (self.invincible_finished)
62                 other.invincible_finished = max(other.invincible_finished, time) + cvar("g_balance_powerup_invincible_time");
63         //if (self.speed_finished)
64         //      other.speed_finished = max(other.speed_finished, time) + cvar("g_balance_powerup_speed_time");
65         //if (self.slowmo_finished)
66         //      other.slowmo_finished = max(other.slowmo_finished, time) + (cvar("g_balance_powerup_slowmo_time") * cvar("g_balance_powerup_slowmo_speed"));
67
68         if (self.max_health)
69         {
70                 other.health = other.health + self.max_health;
71                 other.pauserothealth_finished = max(other.pauserothealth_finished, time + 5);
72         }
73         if (self.health && other.health < other.max_health)
74                 other.health = min(other.health + self.health, other.max_health);
75         if (self.armorvalue)
76         {
77                 other.armorvalue = other.armorvalue + self.armorvalue;
78                 other.pauserotarmor_finished = max(other.pauserotarmor_finished, time + 5);
79         }
80
81         oldself = self;
82         self = other;
83
84         if (_switchweapon)
85                 self.switchweapon = w_getbestweapon(self);
86
87         //W_UpdateWeapon ();
88         //W_UpdateAmmo ();
89         weapon_action(self.weapon, WR_UPDATECOUNTS);
90
91         self = oldself;
92
93         if (self.classname == "droppedweapon")
94                 remove (self);
95         else
96         {
97                 self.solid = SOLID_NOT;
98                 self.model = string_null;
99                 self.nextthink = time + self.respawntime;
100                 self.think = Item_Respawn;
101                 setorigin (self, self.origin);
102         }
103 }
104
105 // Savage: used for item garbage-collection
106 // TODO: perhaps nice special effect?
107 void RemoveItem(void) = {
108         remove(self);
109 }
110
111
112 void StartItem (string itemmodel, string pickupsound, float defaultrespawntime, string itemname, float itemid, float itemflags)
113 {
114         if (!cvar("g_pickup_items"))
115         {
116                 remove (self);
117                 return;
118         }
119         self.mdl = itemmodel;
120         self.noise = pickupsound;
121         // let mappers override respawntime
122         if (!self.respawntime)
123                 self.respawntime = defaultrespawntime;
124         self.netname = itemname;
125         self.items = itemid;
126         self.flags = FL_ITEM | itemflags;
127         setmodel (self, self.mdl);
128         if (itemflags & FL_WEAPON)
129         {
130                 setorigin (self, self.origin + '0 0 22');
131                 setsize (self, '-12 -12 -12', '12 12 12');
132         }
133         else
134         {
135                 setorigin (self, self.origin + '0 0 15');
136         //      setsize (self, '-8 -8 -5', '8 8 8');
137         }
138         self.movetype = MOVETYPE_TOSS;
139         self.solid = SOLID_TRIGGER;
140         self.touch = Item_Touch;
141
142         // Savage: remove thrown items after a certain period of time ("garbage collection")
143         if (self.classname == "droppedweapon")
144         {
145                 self.think = RemoveItem;
146                 self.nextthink = time + 60;
147         }
148
149         if (cvar("g_fullbrightitems"))
150                 self.effects = self.effects | EF_FULLBRIGHT;
151
152 }
153
154 void weapon_uzi (void) {self.ammo_nails = 120;StartItem ("models/weapons/g_uzi.md3", "weapons/weaponpickup.wav", 15, "Uzi", IT_UZI, FL_WEAPON);}
155 void weapon_shotgun (void) {self.ammo_shells = 15;StartItem ("models/weapons/g_shotgun.md3", "weapons/weaponpickup.wav", 15, "Shotgun", IT_SHOTGUN, FL_WEAPON);}
156 void weapon_grenadelauncher (void) {self.ammo_rockets = 15;StartItem ("models/weapons/g_gl.md3", "weapons/weaponpickup.wav", 15, "Grenade Launcher", IT_GRENADE_LAUNCHER, FL_WEAPON);}
157 void weapon_electro (void) {self.ammo_cells = 25;StartItem ("models/weapons/g_electro.md3", "weapons/weaponpickup.wav", 15, "Electro", IT_ELECTRO, FL_WEAPON);}
158 void weapon_crylink (void) {self.ammo_cells = 25;StartItem ("models/weapons/g_crylink.md3", "weapons/weaponpickup.wav", 15, "Crylink", IT_CRYLINK, FL_WEAPON);}
159 void weapon_nex (void) {self.ammo_cells = 25;StartItem ("models/weapons/g_nex.md3", "weapons/weaponpickup.wav", 15, "Nex Gun", IT_NEX, FL_WEAPON);}
160 void weapon_hagar (void) {self.ammo_rockets = 15;StartItem ("models/weapons/g_hagar.md3", "weapons/weaponpickup.wav", 15, "Hagar", IT_HAGAR, FL_WEAPON);}
161 void weapon_rocketlauncher (void) {self.ammo_rockets = 15;StartItem ("models/weapons/g_rl.md3", "weapons/weaponpickup.wav", 15, "Rocket Launcher", IT_ROCKET_LAUNCHER, FL_WEAPON);}
162
163 void item_rockets (void) {self.ammo_rockets = 15;StartItem ("models/items/a_rockets.md3", "misc/itempickup.wav", 15, "rockets", IT_ROCKETS, 0);}
164 void item_bullets (void) {self.ammo_nails = 120;StartItem ("models/items/a_bullets.mdl", "misc/itempickup.wav", 15, "bullets", IT_NAILS, 0);}
165 void item_cells (void) {self.ammo_cells = 25;StartItem ("models/items/a_cells.md3", "misc/itempickup.wav", 15, "cells", IT_CELLS, 0);}
166 void item_shells (void) {self.ammo_shells = 15;StartItem ("models/items/a_shells.md3", "misc/itempickup.wav", 15, "shells", IT_SHELLS, 0);}
167
168 void item_armor1 (void) {self.armorvalue = 5;StartItem ("models/items/g_a1.md3", "misc/armor1.wav", 15, "Armor Shard", 0, 0);}
169 void item_armor25 (void) {self.armorvalue = 100;StartItem ("models/items/g_a25.md3", "misc/armor25.wav", 30, "Armor", 0, 0);}
170 void item_health1 (void) {self.max_health = 5;StartItem ("models/items/g_h1.md3", "misc/minihealth.wav", 15, "5 Health", 0, 0);}
171 void item_health25 (void) {self.max_health = 25;StartItem ("models/items/g_h25.md3", "misc/mediumhealth.wav", 15, "25 Health", 0, 0);}
172 void item_health100 (void) {self.max_health = 100;StartItem ("models/items/g_h100.md3", "misc/megahealth.wav", 30, "100 Health", 0, 0);}
173
174 void item_strength (void) {self.strength_finished = 30;self.effects = EF_ADDITIVE;StartItem ("models/items/g_strength.md3", "misc/powerup.wav", 120, "Strength Powerup", IT_STRENGTH, FL_POWERUP);}
175 void item_invincible (void) {self.invincible_finished = 30;self.effects = EF_ADDITIVE;StartItem ("models/items/g_invincible.md3", "misc/powerup.wav", 120, "Invulnerability", IT_INVINCIBLE, FL_POWERUP);}
176 //void item_speed (void) {self.speed_finished = 30;StartItem ("models/items/g_speed.md3", "misc/powerup.wav", 120, "Speed Powerup", IT_SPEED, FL_POWERUP);}
177 //void item_slowmo (void) {self.slowmo_finished = 30;StartItem ("models/items/g_slowmo.md3", "misc/powerup.wav", 120, "Slow Motion", IT_SLOWMO, FL_POWERUP);}
178
179 void misc_models (void)
180 {
181         precache_model (self.model);
182         setmodel (self, self.model);
183         setsize (self, self.mins, self.maxs);
184 }
185
186