]> icculus.org git repositories - divverent/nexuiz.git/blob - qcsrc/gamec/t_items.c
raised items so that the map entities (have their origin at the floor) will not fall...
[divverent/nexuiz.git] / qcsrc / gamec / t_items.c
1
2 void Item_Respawn (void)
3 {
4         self.model = self.mdl;          // restore original model
5         self.solid = SOLID_TRIGGER;     // allow it to be touched again
6         sound (self, CHAN_VOICE, "misc/itemrespawn.wav", 1, ATTN_NORM); // play respawn sound
7         setorigin (self, self.origin);
8 }
9
10 void Item_Touch (void)
11 {
12         local entity oldself;
13         local float     _switchweapon;
14
15         if (self.solid != SOLID_TRIGGER)
16                 return;
17
18         if (other.classname != "player" && other.classname != "bot")
19                 return;
20         if (other.health <= 0)
21                 return;
22
23         sound (self, CHAN_BODY, self.noise, 1, ATTN_NORM);
24
25         // if the player is using their best weapon before items are given, they
26         // probably want to switch to an even better weapon after items are given
27         _switchweapon = other.weapon == W_GetBestWeapon(other);
28
29         if (self.ammo_shells)
30                 other.ammo_shells = min (other.ammo_shells + self.ammo_shells, 100);
31         if (self.ammo_nails)
32                 other.ammo_nails = min (other.ammo_nails + self.ammo_nails, 200);
33         if (self.ammo_rockets)
34                 other.ammo_rockets = min (other.ammo_rockets + self.ammo_rockets, 100);
35         if (self.ammo_cells)
36                 other.ammo_cells = min (other.ammo_cells + self.ammo_cells, 100);
37
38         if (self.items & IT_UZI)                                W_GiveWeapon (other, IT_UZI);
39         if (self.items & IT_SHOTGUN)                    W_GiveWeapon (other, IT_SHOTGUN);
40         if (self.items & IT_GRENADE_LAUNCHER)   W_GiveWeapon (other, IT_GRENADE_LAUNCHER);
41         if (self.items & IT_ELECTRO)                    W_GiveWeapon (other, IT_ELECTRO);
42         if (self.items & IT_NEX)                                W_GiveWeapon (other, IT_NEX);
43         if (self.items & IT_HAGAR)                              W_GiveWeapon (other, IT_HAGAR);
44         if (self.items & IT_ROCKET_LAUNCHER)    W_GiveWeapon (other, IT_ROCKET_LAUNCHER);
45         if (self.items & IT_CRYLINK)                    W_GiveWeapon (other, IT_CRYLINK);
46
47         if (self.strength_finished)
48                 other.strength_finished = max(other.strength_finished, time) + self.strength_finished;
49         if (self.invincible_finished)
50                 other.invincible_finished = max(other.invincible_finished, time) + self.invincible_finished;
51         if (self.speed_finished)
52                 other.speed_finished = max(other.speed_finished, time) + self.speed_finished;
53         if (self.slowmo_finished)
54                 other.slowmo_finished = max(other.slowmo_finished, time) + self.slowmo_finished;
55
56         if (self.max_health)
57                 other.health = other.health + self.max_health;
58         if (self.armorvalue)
59                 other.armorvalue = other.armorvalue + self.armorvalue;
60
61         if (other.classname == "player")
62         {
63                 sprint (other, "You got the ");
64                 sprint (other, self.netname);
65                 sprint (other, "\n");
66         }
67
68         oldself = self;
69         self = other;
70
71         if (_switchweapon)
72                 self.weapon = W_GetBestWeapon(self);
73
74         W_UpdateWeapon ();
75         W_UpdateAmmo ();
76
77         self = oldself;
78
79         if (self.norespawn)
80                 remove (self);
81         else
82         {
83                 self.solid = SOLID_NOT;
84                 self.model = string_null;
85                 self.nextthink = time + self.respawntime;
86                 self.think = Item_Respawn;
87                 setorigin (self, self.origin);
88         }
89 }
90
91 void StartItem (string itemmodel, string pickupsound, float defaultrespawntime, string itemname, float itemid, float itemflags)
92 {
93         if (game & (GAME_INSTAGIB | GAME_ROCKET_ARENA))
94         {
95                 remove (self);
96                 return;
97         }
98         self.mdl = itemmodel;
99         self.noise = pickupsound;
100         // let mappers override respawntime
101         if (!self.respawntime)
102                 self.respawntime = defaultrespawntime;
103         self.netname = itemname;
104         self.items = itemid;
105         self.flags = FL_ITEM | itemflags;
106         setmodel (self, self.mdl);
107         if (itemflags & FL_WEAPON)
108         {
109                 setorigin (self, self.origin + '0 0 12');
110                 setsize (self, '-12 -12 -12', '12 12 12');
111         }
112         else
113         {
114                 setorigin (self, self.origin + '0 0 8');
115                 setsize (self, '-8 -8 -8', '8 8 8');
116         }
117         self.movetype = MOVETYPE_TOSS;
118         self.solid = SOLID_TRIGGER;
119         self.touch = Item_Touch;
120 }
121
122 void weapon_uzi (void) {self.ammo_nails = 50;StartItem ("models/weapons/g_uzi.md3", "weapons/weaponpickup.wav", 30, "Uzi", IT_UZI, FL_WEAPON);}
123 void weapon_shotgun (void) {self.ammo_shells = 10;StartItem ("models/weapons/g_shotgun.md3", "weapons/weaponpickup.wav", 30, "Shotgun", IT_SHOTGUN, FL_WEAPON);}
124 void weapon_grenadelauncher (void) {self.ammo_rockets = 10;StartItem ("models/weapons/g_gl.md3", "weapons/weaponpickup.wav", 30, "Grenade Launcher", IT_GRENADE_LAUNCHER, FL_WEAPON);}
125 void weapon_electro (void) {self.ammo_cells = 30;StartItem ("models/weapons/g_electro.md3", "weapons/weaponpickup.wav", 30, "Electro", IT_ELECTRO, FL_WEAPON);}
126 void weapon_crylink (void) {self.ammo_cells = 30;StartItem ("models/weapons/g_crylink.md3", "weapons/weaponpickup.wav", 30, "Crylink", IT_CRYLINK, FL_WEAPON);}
127 void weapon_nex (void) {self.ammo_cells = 30;StartItem ("models/weapons/g_nex.md3", "weapons/weaponpickup.wav", 30, "Nex Gun", IT_NEX, FL_WEAPON);}
128 void weapon_hagar (void) {self.ammo_rockets = 10;StartItem ("models/weapons/g_hagar.md3", "weapons/weaponpickup.wav", 30, "Hagar", IT_HAGAR, FL_WEAPON);}
129 void weapon_rocketlauncher (void) {self.ammo_rockets = 10;StartItem ("models/weapons/g_rl.md3", "weapons/weaponpickup.wav", 30, "Rocket Launcher", IT_ROCKET_LAUNCHER, FL_WEAPON);}
130
131 void item_rockets (void) {self.ammo_rockets = 25;StartItem ("models/items/a_rockets.md3", "misc/itempickup.wav", 30, "rockets", IT_ROCKETS, 0);}
132 void item_bullets (void) {self.ammo_nails = 100;StartItem ("models/items/a_bullets.mdl", "misc/itempickup.wav", 30, "bullets", IT_NAILS, 0);}
133 void item_cells (void) {self.ammo_cells = 50;StartItem ("models/items/a_cells.md3", "misc/itempickup.wav", 30, "cells", IT_CELLS, 0);}
134 void item_shells (void) {self.ammo_shells = 50;StartItem ("models/items/a_shells.md3", "misc/itempickup.wav", 30, "shells", IT_SHELLS, 0);}
135
136 void item_armor1 (void) {self.armorvalue = 5;StartItem ("models/items/g_a1.md3", "misc/itempickup.wav", 30, "Armor Shard", 0, 0);}
137 void item_armor25 (void) {self.armorvalue = 100;StartItem ("models/items/g_a25.md3", "misc/itempickup.wav", 30, "Armor", 0, 0);}
138 void item_health1 (void) {self.max_health = 5;StartItem ("models/items/g_h1.md3", "misc/itempickup.wav", 30, "5 Health", 0, 0);}
139 void item_health25 (void) {self.max_health = 25;StartItem ("models/items/g_h25.md3", "misc/mediumhealth.wav", 30, "25 Health", 0, 0);}
140 void item_health100 (void) {self.max_health = 100;StartItem ("models/items/g_h100.md3", "misc/megahealth.wav", 30, "100 Health", 0, 0);}
141
142 //void item_strength (void) {self.strength_finished = 30;StartItem ("models/items/g_strength.zym", "misc/itempickup.wav", 120, "Strength Powerup", IT_STRENGTH, 0);}
143 //void item_invincible (void) {self.invincible_finished = 30;StartItem ("models/items/g_invincible.zym", "misc/itempickup.wav", 120, "Invulnerability", IT_INVINCIBLE, 0);}
144 //void item_speed (void) {self.speed_finished = 30;StartItem ("models/items/g_speed.zym", "misc/itempickup.wav", 120, "Speed Powerup", IT_SPEED, 0);}
145 //void item_slowmo (void) {self.slowmo_finished = 30;StartItem ("models/items/g_slowmo.zym", "misc/itempickup.wav", 120, "Slow Motion Powerup", IT_SLOWMO, 0);}
146
147 void misc_models (void)
148 {
149         precache_model (self.model);
150         setmodel (self, self.model);
151         setsize (self, self.mins, self.maxs);
152 }
153
154