]> 4ch.mooo.com Git - 16.git/blob - src/v2/source/verge/MAPED/MINIMAP.C
wwww
[16.git] / src / v2 / source / verge / MAPED / MINIMAP.C
1 /*\r
2 Copyright (C) 1998 BJ Eirich (aka vecna)\r
3 This program is free software; you can redistribute it and/or\r
4 modify it under the terms of the GNU General Public License\r
5 as published by the Free Software Foundation; either version 2\r
6 of the License, or (at your option) any later version.\r
7 This program is distributed in the hope that it will be useful,\r
8 but WITHOUT ANY WARRANTY; without even the implied warranty of\r
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\r
10 See the GNU General Public Lic\r
11 See the GNU General Public License for more details.\r
12 You should have received a copy of the GNU General Public License\r
13 along with this program; if not, write to the Free Software\r
14 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\r
15 */\r
16 \r
17 #include <stdio.h>\r
18 #include <string.h>\r
19 #include <malloc.h>\r
20 \r
21 #include "config.h"\r
22 #include "keyboard.h"\r
23 #include "maped.h"\r
24 #include "mouse.h"\r
25 #include "vdriver.h"\r
26 \r
27 // ============================ Data ============================\r
28 \r
29 unsigned char mvsp[2048];         // mini-VSP dominant color\r
30 int xoff=0, yoff=0;               // x-offset, y-offset\r
31 \r
32 // ============================ Code ============================\r
33 /*\r
34 FindDominantColor(int i)\r
35 { unsigned char *src;\r
36   int j,tally=0;\r
37 \r
38   // This is a cheap-ass method. I have a more proper method in mind, but\r
39   // I'm going to do this for now b/c I'm lazy. Actually, the real reason is\r
40   // speed.\r
41 \r
42   src=vsp+(i*256);\r
43 \r
44   for (j=0; j<256; j++)\r
45   {\r
46     tally+=*src;\r
47     src++;\r
48   }\r
49   tally=tally/256;\r
50   mvsp[i]=(unsigned char) tally;\r
51 }\r
52 */\r
53 \r
54 void FindDominantColor(int i)\r
55 { unsigned char *src, tally[256], tab;\r
56   int j;\r
57 \r
58   src=vsp+(i*256);\r
59   memset(&tally, 0, 256);\r
60 \r
61   for (j=0; j<256; j++)\r
62   {\r
63     tally[*src]++;\r
64     src++;\r
65   }\r
66   tab=0;\r
67   for (j=0; j<256; j++)\r
68   {\r
69     if (tally[j] > tab) tab=j;\r
70   }\r
71   mvsp[i]=(unsigned char) tab;\r
72 }\r
73 \r
74 void GenerateMiniVSP()\r
75 { int i;\r
76 \r
77   for (i=0; i<numtiles; i++)\r
78       FindDominantColor(i);\r
79 }\r
80 \r
81 void MiniMAP()\r
82 { char *ptr,c;\r
83   int _x,_y,ct;\r
84   int i;\r
85 \r
86   GenerateMiniVSP();\r
87   ptr=(char *) valloc(layer[0].sizex*layer[0].sizey,"minimap",0);\r
88   //memset(ptr,0,layer[0].sizex*layer[0].sizey);\r
89 \r
90   // Now we "draw" the tiles into the buffer.\r
91 \r
92   for (i=0; i<4; i++)\r
93   {\r
94     if (!layertoggle[i]) continue;\r
95     ct=0;\r
96     for (_y=0; _y<layer[i].sizey; _y++)\r
97       for (_x=0; _x<layer[i].sizex; _x++)\r
98       {\r
99          c=(unsigned char) mvsp[layers[i][(_y*layer[i].sizex)+_x]];\r
100          if (layers[i][(_y*layer[i].sizex)+_x]) ptr[ct]=c;\r
101          ct++;\r
102       }\r
103   }\r
104 \r
105   while (!key[SCAN_ESC] && !mb)\r
106   {\r
107     ClearScreen();\r
108     CCopySprite(16-xoff, 16-yoff, layer[0].sizex, layer[0].sizey, ptr);\r
109     ReadMouse();\r
110     HLine(mx, my, 20, white);\r
111     VLine(mx, my, ty, white);\r
112     VLine(mx+19, my, ty, white);\r
113     HLine(mx, my+ty, 20, white);\r
114 \r
115     ShowPage();\r
116 \r
117     if (key[SCAN_LEFT] && xoff)\r
118     {\r
119       if (xoff > 0) xoff-=16;\r
120       key[SCAN_LEFT]=0;\r
121     }\r
122     if (key[SCAN_UP] && yoff)\r
123     {\r
124       if (yoff > 0) yoff-=16;\r
125       key[SCAN_UP]=0;\r
126     }\r
127     if (key[SCAN_DOWN])\r
128     {\r
129       if (yoff < layer[0].sizey)\r
130         yoff+=16;\r
131       key[SCAN_DOWN]=0;\r
132     }\r
133     if (key[SCAN_RIGHT])\r
134     {\r
135       if (xoff < layer[0].sizex)\r
136         xoff+=16;\r
137       key[SCAN_RIGHT]=0;\r
138     }\r
139     if (mb)\r
140     {\r
141       xwin=(xoff+mx-16)*16;\r
142       ywin=(yoff+my-16)*16;\r
143       if (xwin>=(layer[0].sizex*16)-320) xwin=(layer[0].sizex*16)-320;\r
144       if (ywin>=(layer[0].sizey*16)-tsy-15) ywin=(layer[0].sizey*16)-tsy-15;\r
145       WaitRelease();\r
146       break;\r
147     }\r
148   }\r
149   key[SCAN_ESC]=0;\r
150   vfree(ptr);\r
151 }\r