1 //-------------------------------------------------------------------------
2 /*
3 Copyright (C) 2010-2019 EDuke32 developers and contributors
4 Copyright (C) 2019 Nuke.YKT
5 
6 This file is part of NBlood.
7 
8 NBlood is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License version 2
10 as published by the Free Software Foundation.
11 
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15 
16 See the GNU General Public License for more details.
17 
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 */
22 //-------------------------------------------------------------------------
23 #include "compat.h"
24 #include "build.h"
25 #include "editor.h"
26 #include "common_game.h"
27 #include "crc32.h"
28 
29 #include "globals.h"
30 #include "tile.h"
31 #include "screen.h"
32 
qanimateoffs(int a1,int a2)33 int qanimateoffs(int a1, int a2)
34 {
35     int offset = 0;
36     if (a1 >= 0 && a1 < kMaxTiles)
37     {
38         int frames = picanm[a1].num;
39         if (frames > 0)
40         {
41             int const frameClock = (int)(editstatus ? totalclocklock : gFrameClock);
42             int vd;
43             if ((a2&0xc000) == 0x8000)
44                 vd = (Bcrc32(&a2, 2, 0)+frameClock)>>(picanm[a1].sf&PICANM_ANIMSPEED_MASK);
45             else
46                 vd = frameClock>>(picanm[a1].sf&PICANM_ANIMSPEED_MASK);
47             switch (picanm[a1].sf&PICANM_ANIMTYPE_MASK)
48             {
49             case PICANM_ANIMTYPE_OSC:
50                 offset = vd % (2*frames);
51                 if (offset >= frames)
52                     offset = 2*frames-offset;
53                 break;
54             case PICANM_ANIMTYPE_FWD:
55                 offset = vd % (frames+1);
56                 break;
57             case PICANM_ANIMTYPE_BACK:
58                 offset = -(vd % (frames+1));
59                 break;
60             }
61         }
62     }
63     return offset;
64 }
65 
qloadpalette()66 void qloadpalette()
67 {
68     scrLoadPalette();
69 }
70 
qgetpalookup(int32_t a1,int32_t a2)71 int32_t qgetpalookup(int32_t a1, int32_t a2)
72 {
73     if (gFogMode)
74         return ClipHigh(a1 >> 8, 15) * 16 + ClipRange(a2, 0, 15);
75     else
76         return ClipRange((a1 >> 8) + a2, 0, 63);
77 }
78 
HookReplaceFunctions(void)79 void HookReplaceFunctions(void)
80 {
81     void qinitspritelists();
82     int32_t qinsertsprite(int16_t nSector, int16_t nStat);
83     int32_t qdeletesprite(int16_t nSprite);
84     int32_t qchangespritesect(int16_t nSprite, int16_t nSector);
85     int32_t qchangespritestat(int16_t nSprite, int16_t nStatus);
86     int32_t qloadboard(const char* filename, char flags, vec3_t* dapos, int16_t* daang, int16_t* dacursectnum);
87     int32_t qsaveboard(const char* filename, const vec3_t* dapos, int16_t daang, int16_t dacursectnum);
88     animateoffs_replace = qanimateoffs;
89     paletteLoadFromDisk_replace = qloadpalette;
90     getpalookup_replace = qgetpalookup;
91     initspritelists_replace = qinitspritelists;
92     insertsprite_replace = qinsertsprite;
93     deletesprite_replace = qdeletesprite;
94     changespritesect_replace = qchangespritesect;
95     changespritestat_replace = qchangespritestat;
96     loadvoxel_replace = qloadvoxel;
97     loadboard_replace = qloadboard;
98     saveboard_replace = qsaveboard;
99     bloodhack = true;
100 }
101