DEADSOFTWARE

update copyrights
[flatwaifu.git] / src / items.c
1 /* Copyright (C) 1996-1997 Aleksey Volynskov
2 * Copyright (C) 2011 Rambo
3 * Copyright (C) 2020 SovietPony
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 3 of the License ONLY.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
18 #include "glob.h"
19 #include <stdlib.h>
20 #include "error.h"
21 #include "view.h"
22 #include "items.h"
23 #include "fx.h"
24 #include "player.h"
25 #include "monster.h"
26 #include "things.h"
27 #include "misc.h"
28 #include "map.h"
29 #include "my.h"
30 #include "files.h"
31 #include "game.h"
32 item_t it[MAXITEM];
34 static void *snd[4];
35 static int tsndtm, rsndtm;
37 int itm_rtime = 1092;
39 void IT_alloc (void) {
40 int i, j, n;
41 static char nm[][6] = {
42 "ITEMUP", "WPNUP", "GETPOW", "ITMBK"
43 };
44 for (i = 0; i < 4; ++i) {
45 snd[i] = Z_getsnd(nm[i]);
46 }
47 for (i = 0; i < MAXITEM; ++i) {
48 it[i].o.r = 10;
49 it[i].o.h = 8;
50 }
51 }
53 void IT_init (void) {
54 int i;
55 for (i = 0; i < MAXITEM; ++i) {
56 it[i].t = I_NONE;
57 it[i].o.xv = 0;
58 it[i].o.yv = 0;
59 it[i].o.vx = 0;
60 it[i].o.vy = 0;
61 }
62 tsndtm = 0;
63 rsndtm = 0;
64 }
66 static void takesnd (int t) {
67 if(tsndtm) return;
68 t&=0x7FFF;
69 if(t<=I_CELP || (t>=I_BPACK && t<=I_BFG) || t==I_GUN2)
70 {tsndtm=Z_sound(snd[1],128);return;}
71 if(t==I_MEGA || t==I_INVL || t==I_SUPER)
72 {tsndtm=Z_sound(snd[2],192);return;}
73 tsndtm=Z_sound(snd[0], 255);
74 }
76 void IT_act (void) {
77 int i,j;
79 if(tsndtm) --tsndtm;
80 if(rsndtm) --rsndtm;
81 for(i=0;i<MAXITEM;++i) if(it[i].t)
82 if(it[i].s<0) {
83 if(++it[i].s==-8) {
84 FX_ifog(it[i].o.x,it[i].o.y);
85 if(!rsndtm) rsndtm=Z_sound(snd[3],128);
86 }
87 }else{
88 switch(it[i].t) {
89 case I_ARM1: case I_ARM2:
90 if(++it[i].s>=18) it[i].s=0; break;
91 case I_MEGA: case I_INVL:
92 case I_SUPER: case I_RTORCH: case I_GTORCH: case I_BTORCH:
93 if(++it[i].s>=8) it[i].s=0; break;
94 case I_GOR1: case I_FCAN:
95 if(++it[i].s>=6) it[i].s=0; break;
96 }
97 if(it[i].t&0x8000) {
98 if((j=Z_moveobj(&it[i].o))&Z_FALLOUT) {it[i].t=0;continue;}
99 else if(j&Z_HITWATER) Z_splash(&it[i].o,it[i].o.r+it[i].o.h);
101 if(Z_overlap(&it[i].o,&pl1.o))
102 if(PL_give(&pl1,it[i].t&0x7FFF)) {
103 takesnd(it[i].t);
104 if(_2pl) if((it[i].t&0x7FFF)>=I_KEYR && (it[i].t&0x7FFF)<=I_KEYB) continue;
105 if(!(it[i].s=-itm_rtime) || (it[i].t&0x8000)) it[i].t=0;
106 continue;
108 if(_2pl) if(Z_overlap(&it[i].o,&pl2.o))
109 if(PL_give(&pl2,it[i].t&0x7FFF)) {
110 takesnd(it[i].t);
111 if((it[i].t&0x7FFF)>=I_KEYR && (it[i].t&0x7FFF)<=I_KEYB) continue;
112 if(!(it[i].s=-itm_rtime) || (it[i].t&0x8000)) it[i].t=0;
113 continue;
118 void IT_spawn (int x,int y,int t) {
119 int i;
121 for(i=0;i<MAXITEM;++i) if(!it[i].t) {
122 it[i].t=t|0x8000;it[i].s=0;
123 it[i].o.x=x;it[i].o.y=y;
124 it[i].o.xv=it[i].o.yv=it[i].o.vx=it[i].o.vy=0;
125 it[i].o.r=10;it[i].o.h=8;
126 return;
130 void IT_drop_ammo (int t, int n, int x, int y) {
131 static int an[8]={10,4,1,40,50,25,5,100};
132 int a;
134 again:;
135 for(a=an[t-I_CLIP];n>=a;n-=a)
136 IT_spawn(x+myrand(3*2+1)-3,y-myrand(7),t);
137 if(t>=I_AMMO) {t-=4;goto again;}