install: add install sources and resources
[doom2d-restoration.git] / GAME / LEVELS / THING.C
blob8a7e78132a03c0617f3b418feda5a4d797ecd66e
1 #include "glob.h"
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <string.h>
5 #include "vga.h"
6 #include "error.h"
7 #include "files.h"
8 #include "memory.h"
9 #include "view.h"
10 #include "misc.h"
11 #include "..\map.h"
13 #define MANCOLOR 0xD0
15 extern map_block_t blk;
17 #define IT_TN (TH__LASTI-TH_CLIP)
18 #define MN_TN (TH__LASTM-TH_DEMON)
20 extern int curth;
22 static void *spr[IT_TN+1],*mon[MN_TN];
23 static char mond[MN_TN];
24 static thing_t th[MAXTH];
26 void TH_alloc(void) {
27   int i,h;
28   char nm[IT_TN+1][4]={
29     "PLAY",
30     "CLIP","SHEL","ROCK","CELL","AMMO","SBOX","BROK","CELP","STIM","MEDI",
31     "BPAK",
32     "CSAW","SHOT","SGN2","MGUN","LAUN","PLAS","BFUG",
33     "ARM1","ARM2","MEGA","PINV","AQUA",
34     "KEYR","KEYG","KEYB","SUIT","SOUL",
35     "SMRT","SMGT","SMBT","GOR1","FCAN","GUN2"
36   }, mn[MN_TN][4]={
37         "SARG","TROO","POSS","SPOS","CYBR","CPOS","BOSS","BOS2","HEAD","SKUL",
38         "PAIN","SPID","BSPI","FATT","SKEL","VILE","FISH","BAR1","ROBO","PLAY"
39   };
41   for(i=0;i<IT_TN+1;++i) spr[i]=M_lock(F_getsprid(nm[i],0,1));
42   for(i=0;i<MN_TN;++i) {
43     mon[i]=M_lock(h=F_getsprid(mn[i],0,1));
44     mond[i]=(h&0x8000)?1:0;
45   }
48 void TH_load_old(int h) {
49   int i;
51   for(i=0;i<MAXTH;++i) {
52     read(h,&th[i],sizeof(thing_t));
53     if(th[i].t==0) break;
54   }
55   SW_load_old(h);
58 int TH_load(int h) {
59   int i;
61   switch(blk.t) {
62         case MB_THING:
63           for(i=0;i<MAXTH && blk.sz>0;++i,blk.sz-=sizeof(thing_t))
64                 read(h,&th[i],sizeof(thing_t));
65           return 1;
66   }return 0;
69 void TH_save(void) {
70   int i;
72   F_start_blk(MB_THING,0);
73   for(i=0;i<MAXTH;++i) if(th[i].t)
74         F_write_blk(&th[i],sizeof(thing_t));
75   F_end_blk();
78 void TH_init(void) {
79   int i;
81   for(i=0;i<MAXTH;++i) th[i].t=0;
84 static byte mctab[3]={0x70,0x60,0x20};
86 void TH_draw(void) {
87   int i,s;
89   for(i=0;i<MAXTH;++i) if(th[i].t) {
90     if(th[i].t<=TH_DMSTART) s=mctab[th[i].t-1];
91     else s=th[i].t-TH_CLIP+1;
92     if(th[i].t>=TH_DEMON) {
93         if(th[i].t<TH_MAN) Z_drawspr(th[i].x,th[i].y,mon[th[i].t-TH_DEMON],(th[i].f&THF_DIR)^mond[th[i].t-TH_DEMON]);
94         else Z_drawmanspr(th[i].x,th[i].y,spr[0],th[i].f&THF_DIR,MANCOLOR);
95     }else if(th[i].t>TH_DMSTART) Z_drawspr(th[i].x,th[i].y,spr[s],0);
96         else Z_drawmanspr(th[i].x,th[i].y,spr[0],th[i].f&THF_DIR,s);
97         if(i==curth) {
98           V_clr(th[i].x-5-w_x+100,11,th[i].y-10-w_y+50,1,0xAD);
99           V_clr(th[i].x-5-w_x+100,11,th[i].y-w_y+50,1,0xAD);
100           V_clr(th[i].x-5-w_x+100,1,th[i].y-9-w_y+50,9,0xAD);
101           V_clr(th[i].x+5-w_x+100,1,th[i].y-9-w_y+50,9,0xAD);
102         }
103   }
106 void TH_drawth(int x,int y,int t) {
107   int s;
109   if(t<=TH_DMSTART) s=mctab[t-1];
110   else s=t-TH_CLIP+1;
111   if(t>=TH_DEMON)
112         V_spr(x,y,mon[t-TH_DEMON]);
113   else if(t>TH_DMSTART) V_spr(x,y,spr[s]);
114   else V_manspr(x,y,spr[0],s);
117 int TH_add(int x,int y,int t) {
118   int i;
120   for(i=0;i<MAXTH;++i) if(!th[i].t) {
121     th[i].t=t;
122     th[i].x=x;th[i].y=y;
123         th[i].f=0;
124     return i;
125   }
126   return -1;
129 void TH_info(char *s) {
130   int i,p[3],m,t;
132   p[0]=p[1]=p[2]=m=t=0;
133   for(i=0;i<MAXTH;++i) if(th[i].t) {
134         if(th[i].t>=TH_DEMON) ++m;
135         else if(th[i].t>TH_DMSTART) ++t;
136         else ++p[th[i].t-TH_PLR1];
137   }
138   sprintf(s,"1ых игроков: %d   2ых игроков: %d   точек DM: %d\n"
139     "предметов: %d   монстров: %d\n\n",p[0],p[1],p[2],t,m);
142 int TH_isthing(int x,int y) {
143   int i;
145   for(i=0;i<MAXTH;++i) if(th[i].t) {
146     if(x<th[i].x-5) continue;
147     if(x>th[i].x+5) continue;
148     if(y<th[i].y-10) continue;
149     if(y>th[i].y) continue;
150     return i;
151   }
152   return -1;
155 void TH_move(int t,int x,int y) {
156   th[t].x=x;th[t].y=y;
159 int TH_getx(int t) {return th[t].x;}
161 int TH_gety(int t) {return th[t].y;}
163 int TH_getf(int t) {return th[t].f;}
165 int TH_gett(int t) {return th[t].t;}
167 void TH_setf(int t,int f) {th[t].f=f;}
169 void TH_sett(int t,int f) {th[t].t=f;}
171 void TH_delete(int t) {th[t].t=0;}
173 int TH_nextt(int t) {
174   switch(t) {
175         case TH__LASTM-1:       return TH_PLR1;
176         case TH__LASTI-1:       return TH_DEMON;
177     case TH_DMSTART:    return TH_CLIP;
178   }
179   return t+1;
182 int TH_prevt(int t) {
183   switch(t) {
184         case TH_DEMON:  return TH__LASTI-1;
185         case TH_PLR1:   return TH__LASTM-1;
186     case TH_CLIP:       return TH_DMSTART;
187   }
188   return t-1;
191 char *TH_getname(int t) {
192   switch(t) {
193         case TH_PLR1:   return "1ый игрок";
194         case TH_PLR2:   return "2ой игрок";
195         case TH_DMSTART:return "точка DM";
197         case TH_CLIP:   return "патроны";
198         case TH_SHEL:   return "4 гильзы";
199         case TH_ROCKET: return "1 ракета";
200         case TH_CELL:   return "батарейка";
201         case TH_AMMO:   return "ящик патронов";
202         case TH_SBOX:   return "25 гильз";
203         case TH_RBOX:   return "5 ракет";
204         case TH_CELP:   return "батарея";
205         case TH_STIM:   return "аптечка";
206         case TH_MEDI:   return "б.аптечка";
207         case TH_BPACK:  return "рюгзак";
208         case TH_CSAW:   return "бензопила";
209         case TH_SGUN:   return "ружьё";
210         case TH_SGUN2:  return "двустволка";
211         case TH_MGUN:   return "пулемёт";
212         case TH_LAUN:   return "ракетница";
213         case TH_PLAS:   return "плазм.пушка";
214         case TH_BFG:    return "BFG9000";
215         case TH_ARM1:   return "зелёная броня";
216         case TH_ARM2:   return "синяя броня";
217         case TH_MEGA:   return "мегасфера";
218         case TH_INVL:   return "неуязвимость";
219         case TH_AQUA:   return "акваланг";
220         case TH_RKEY:   return "красный ключ";
221         case TH_GKEY:   return "зеленый ключ";
222         case TH_BKEY:   return "синий ключ";
223         case TH_SUIT:   return "костюм";
224         case TH_SUPER:  return "шарик 100%";
225         case TH_RTORCH: return "красный факел";
226         case TH_GTORCH: return "зеленый факел";
227         case TH_BTORCH: return "синий факел";
228         case TH_GOR1:   return "чувак";
229         case TH_FCAN:   return "горящая бочка";
230         case TH_GUN2:   return "суперпулемёт";
232         case TH_DEMON:  return "демон";
233         case TH_IMP:    return "бес";
234         case TH_ZOMBY:  return "зомби";
235         case TH_SERG:   return "сержант";
236         case TH_CYBER:  return "кибердемон";
237         case TH_CGUN:   return "пулемётчик";
238         case TH_BARON:  return "барон ада";
239         case TH_KNIGHT: return "рыцарь ада";
240         case TH_CACO:   return "какодемон";
241         case TH_SOUL:   return "огненный череп";
242         case TH_PAIN:   return "авиабаза";
243         case TH_SPIDER: return "большой паук";
244         case TH_BSP:    return "арахнотрон";
245         case TH_MANCUB: return "манкубус";
246         case TH_SKEL:   return "скелет";
247         case TH_VILE:   return "колдун";
248         case TH_FISH:   return "рыба";
249         case TH_BARREL: return "бочка";
250         case TH_ROBO:   return "робот";
251         case TH_MAN:    return "приколист";
252   }
253   return NULL;