Merge pull request #18 from Clownacy/master

Merge Clownacy/master into master
This commit is contained in:
Gabriel Ravier 2019-05-13 19:17:40 +02:00 committed by GitHub
commit 11f6bf9f16
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
49 changed files with 2334 additions and 1888 deletions

View file

@ -21,7 +21,7 @@
<Tool <Tool
Name="VCCLCompilerTool" Name="VCCLCompilerTool"
Optimization="0" Optimization="0"
AdditionalIncludeDirectories="SDL2/include;freetype/include;./" AdditionalIncludeDirectories="SDL2/include;freetype/include"
PreprocessorDefinitions="WIN32;_DEBUG;WINDOWS;NONPORTABLE" PreprocessorDefinitions="WIN32;_DEBUG;WINDOWS;NONPORTABLE"
MinimalRebuild="TRUE" MinimalRebuild="TRUE"
BasicRuntimeChecks="0" BasicRuntimeChecks="0"
@ -73,7 +73,7 @@
<Tool <Tool
Name="VCCLCompilerTool" Name="VCCLCompilerTool"
Optimization="0" Optimization="0"
AdditionalIncludeDirectories="SDL2/include;freetype/include;./" AdditionalIncludeDirectories="SDL2/include;freetype/include"
PreprocessorDefinitions="WIN32;NDEBUG;WINDOWS;NONPORTABLE" PreprocessorDefinitions="WIN32;NDEBUG;WINDOWS;NONPORTABLE"
MinimalRebuild="TRUE" MinimalRebuild="TRUE"
RuntimeLibrary="0" RuntimeLibrary="0"
@ -123,7 +123,7 @@
<Tool <Tool
Name="VCCLCompilerTool" Name="VCCLCompilerTool"
Optimization="0" Optimization="0"
AdditionalIncludeDirectories="SDL2/include;freetype/include;./" AdditionalIncludeDirectories="SDL2/include;freetype/include"
PreprocessorDefinitions="WIN32;NDEBUG;WINDOWS;NONPORTABLE;JAPANESE" PreprocessorDefinitions="WIN32;NDEBUG;WINDOWS;NONPORTABLE;JAPANESE"
MinimalRebuild="TRUE" MinimalRebuild="TRUE"
RuntimeLibrary="0" RuntimeLibrary="0"
@ -173,7 +173,7 @@
<Tool <Tool
Name="VCCLCompilerTool" Name="VCCLCompilerTool"
Optimization="0" Optimization="0"
AdditionalIncludeDirectories="SDL2/include;freetype/include;./" AdditionalIncludeDirectories="SDL2/include;freetype/include"
PreprocessorDefinitions="WIN32;_DEBUG;WINDOWS;NONPORTABLE;JAPANESE" PreprocessorDefinitions="WIN32;_DEBUG;WINDOWS;NONPORTABLE;JAPANESE"
MinimalRebuild="TRUE" MinimalRebuild="TRUE"
BasicRuntimeChecks="0" BasicRuntimeChecks="0"

View file

@ -515,6 +515,190 @@ addr = 0x414B20
name = "SetMapping" name = "SetMapping"
addr = 0x414B40 addr = 0x414B40
[[func]]
name = "InitMyChar"
addr = 0x414B50
[[func]]
name = "AnimationMyChar"
addr = 0x414BF0
[[func]]
name = "ShowMyChar"
addr = 0x415220
[[func]]
name = "PutMyChar"
addr = 0x415250
[[func]]
name = "ActMyChar_Normal"
addr = 0x4156C0
[[func]]
name = "ActMyChar_Stream"
addr = 0x416470
[[func]]
name = "ActMyChar"
addr = 0x4168C0
[[func]]
name = "AirProcess"
addr = 0x416990
[[func]]
name = "GetMyCharPosition"
addr = 0x416AA0
[[func]]
name = "SetMyCharPosition"
addr = 0x416AC0
[[func]]
name = "MoveMyChar"
addr = 0x416B30
[[func]]
name = "ZeroMyCharXMove"
addr = 0x416B50
[[func]]
name = "GetUnitMyChar"
addr = 0x416B60
[[func]]
name = "SetMyCharDirect"
addr = 0x416B70
[[func]]
name = "ChangeMyUnit"
addr = 0x416C40
[[func]]
name = "PitMyChar"
addr = 0x416C50
[[func]]
name = "EquipItem"
addr = 0x416C70
[[func]]
name = "ResetCheck"
addr = 0x416CA0
[[func]]
name = "SetNoise"
addr = 0x416CC0
[[func]]
name = "CutNoise"
addr = 0x416D40
[[func]]
name = "ResetNoise"
addr = 0x416D80
[[func]]
name = "SleepNoise"
addr = 0x416DF0
[[func]]
name = "ResetMyCharFlag"
addr = 0x416E20
[[func]]
name = "JudgeHitMyCharBlock"
addr = 0x416E30
[[func]]
name = "PutlittleStar"
addr = 0x417160
[[func]]
name = "JudgeHitMyCharTriangleA"
addr = 0x4171D0
[[func]]
name = "JudgeHitMyCharTriangleB"
addr = 0x4172E0
[[func]]
name = "JudgeHitMyCharTriangleC"
addr = 0x4173F0
[[func]]
name = "JudgeHitMyCharTriangleD"
addr = 0x417500
[[func]]
name = "JudgeHitMyCharTriangleE"
addr = 0x417610
[[func]]
name = "JudgeHitMyCharTriangleF"
addr = 0x417720
[[func]]
name = "JudgeHitMyCharTriangleG"
addr = 0x417830
[[func]]
name = "JudgeHitMyCharTriangleH"
addr = 0x417940
[[func]]
name = "JudgeHitMyCharWater"
addr = 0x417A50
[[func]]
name = "JudgeHitMyCharDamage"
addr = 0x417AE0
[[func]]
name = "JudgeHitMyCharDamageW"
addr = 0x417B70
[[func]]
name = "JudgeHitMyCharVectLeft"
addr = 0x417C00
[[func]]
name = "JudgeHitMyCharVectUp"
addr = 0x417C90
[[func]]
name = "JudgeHitMyCharVectRight"
addr = 0x417D20
[[func]]
name = "JudgeHitMyCharVectDown"
addr = 0x417DB0
[[func]]
name = "HitMyCharMap"
addr = 0x417E40
[[func]]
name = "JudgeHitMyCharNPC"
addr = 0x4187F0
[[func]]
name = "JudgeHitMyCharNPC3"
addr = 0x418B10
[[func]]
name = "JudgeHitMyCharNPC4"
addr = 0x418C20
[[func]]
name = "HitMyCharNpChar"
addr = 0x419030
[[func]]
name = "HitMyCharBoss"
addr = 0x419450
[[func]] [[func]]
name = "AddExpMyChar" name = "AddExpMyChar"
addr = 0x4196F0 addr = 0x4196F0
@ -2202,6 +2386,150 @@ addr = 0x46E9E0
name = "ActNpc360" name = "ActNpc360"
addr = 0x46EA90 addr = 0x46EA90
[[func]]
name = "InitNpChar"
addr = 0x46EB30
[[func]]
name = "LoadEvent"
addr = 0x46EB50
[[func]]
name = "SetUniqueParameter"
addr = 0x46EE50
[[func]]
name = "SetNpChar"
addr = 0x46EFD0
[[func]]
name = "SetDestroyNpChar"
addr = 0x46F150
[[func]]
name = "SetDestroyNpCharUp"
addr = 0x46F200
[[func]]
name = "SetExpObjects"
addr = 0x46F2B0
[[func]]
name = "SetBulletObject"
addr = 0x46F430
[[func]]
name = "SetLifeObject"
addr = 0x46F630
[[func]]
name = "VanishNpChar"
addr = 0x46F760
[[func]]
name = "PutNpChar"
addr = 0x46F810
[[func]]
name = "ActNpChar"
addr = 0x46FA00
[[func]]
name = "ChangeNpCharByEvent"
addr = 0x46FAB0
[[func]]
name = "ChangeCheckableNpCharByEvent"
addr = 0x46FD10
[[func]]
name = "SetNpCharActionNo"
addr = 0x46FF90
[[func]]
name = "MoveNpChar"
addr = 0x470060
[[func]]
name = "BackStepMyChar"
addr = 0x470150
[[func]]
name = "DeleteNpCharEvent"
addr = 0x470250
[[func]]
name = "DeleteNpCharCode"
addr = 0x4702D0
[[func]]
name = "GetNpCharPosition"
addr = 0x470460
[[func]]
name = "IsNpCharCode"
addr = 0x470490
[[func]]
name = "GetNpCharAlive"
addr = 0x4704F0
[[func]]
name = "CountAliveNpChar"
addr = 0x470560
[[func]]
name = "JadgeHitNpCharBlock"
addr = 0x4705C0
[[func]]
name = "JudgeHitNpCharTriangleA"
addr = 0x470870
[[func]]
name = "JudgeHitNpCharTriangleB"
addr = 0x470970
[[func]]
name = "JudgeHitNpCharTriangleC"
addr = 0x470A70
[[func]]
name = "JudgeHitNpCharTriangleD"
addr = 0x470B70
[[func]]
name = "JudgeHitNpCharTriangleE"
addr = 0x470C70
[[func]]
name = "JudgeHitNpCharTriangleF"
addr = 0x470D80
[[func]]
name = "JudgeHitNpCharTriangleG"
addr = 0x470E90
[[func]]
name = "JudgeHitNpCharTriangleH"
addr = 0x470FA0
[[func]]
name = "JudgeHitNpCharWater"
addr = 0x4710B0
[[func]]
name = "HitNpCharMap"
addr = 0x471160
[[func]]
name = "LoseNpChar"
addr = 0x471B80
[[func]]
name = "HitNpCharBullet"
addr = 0x471D50
[[func]] [[func]]
name = "LoadNpcTable" name = "LoadNpcTable"
addr = 0x472400 addr = 0x472400

View file

@ -1,13 +0,0 @@
#ifndef _STDINT_H_
#define _STDINT_H_
typedef signed __int8 int8_t;
typedef unsigned __int8 uint8_t;
typedef signed __int16 int16_t;
typedef unsigned __int16 uint16_t;
typedef signed __int32 int32_t;
typedef unsigned __int32 uint32_t;
typedef signed __int64 int64_t;
typedef unsigned __int64 uint64_t;
#endif /*_STDINT_H_*/

View file

@ -36,8 +36,7 @@ BOOL InitBack(const char *fName, int type)
#ifdef NONPORTABLE #ifdef NONPORTABLE
// This is ridiculously platform-dependant: // This is ridiculously platform-dependant:
// It should break on big-endian CPUs, and platforms // It should break on big-endian CPUs, and platforms where short isn't 16-bit and long isn't 32-bit.
// where short isn't 16-bit and long isn't 32-bit.
unsigned short bmp_header_buffer[7]; // These names aren't the original. This ruins the stack frame layout. unsigned short bmp_header_buffer[7]; // These names aren't the original. This ruins the stack frame layout.
unsigned long bmp_header_buffer2[10]; unsigned long bmp_header_buffer2[10];

View file

@ -1,6 +1,5 @@
#include "Boss.h" #include "Boss.h"
#include <stdint.h>
#include <string.h> #include <string.h>
#include "WindowsWrapper.h" #include "WindowsWrapper.h"

View file

@ -142,6 +142,7 @@ void ActBossChar_Ballos(void)
switch (npc->act_no) switch (npc->act_no)
{ {
case 0: case 0:
// Initialize main boss
npc->act_no = 1; npc->act_no = 1;
npc->cond = 0x80; npc->cond = 0x80;
npc->exp = 1; npc->exp = 1;
@ -159,6 +160,7 @@ void ActBossChar_Ballos(void)
npc->code_event = 1000; npc->code_event = 1000;
npc->life = 800; npc->life = 800;
// Initialize eyes
gBoss[1].cond = 0x90; gBoss[1].cond = 0x90;
gBoss[1].direct = 0; gBoss[1].direct = 0;
gBoss[1].bits = 8; gBoss[1].bits = 8;
@ -175,6 +177,7 @@ void ActBossChar_Ballos(void)
gBoss[2] = gBoss[1]; gBoss[2] = gBoss[1];
gBoss[2].direct = 2; gBoss[2].direct = 2;
// Initialize the body
gBoss[3].cond = 0x90; gBoss[3].cond = 0x90;
gBoss[3].bits = 0xD; gBoss[3].bits = 0xD;
gBoss[3].view.front = 0x7800; gBoss[3].view.front = 0x7800;

View file

@ -10,6 +10,7 @@
#include "Sound.h" #include "Sound.h"
#include "Triangle.h" #include "Triangle.h"
// Balfrog's mouth
static void ActBossChar02_01(void) static void ActBossChar02_01(void)
{ {
NPCHAR *boss; NPCHAR *boss;
@ -84,6 +85,7 @@ static void ActBossChar02_02(void)
} }
} }
// Main boss AI
void ActBossChar_Frog(void) void ActBossChar_Frog(void)
{ {
int i; int i;
@ -91,6 +93,7 @@ void ActBossChar_Frog(void)
int ym; int ym;
int xm; int xm;
// Rects 1-4 are for when Balfrog is a frog, 5-8 for when he reverts and goes into the ceiling
RECT rcLeft[9] = { RECT rcLeft[9] = {
{0, 0, 0, 0}, {0, 0, 0, 0},
{0, 48, 80, 112}, {0, 48, 80, 112},

View file

@ -523,7 +523,7 @@ void ActBossChar_MonstX(void)
gBoss[2].direct = 2; gBoss[2].direct = 2;
gBoss[3].cond = 0x80; gBoss[3].cond = 0x80;
gBoss[3].life = 60; gBoss[3].life = 60;
gBoss[3].size = 3; // Redundant: this get overwriten a few lines later gBoss[3].size = 3; // Redundant: this get overwritten a few lines later
gBoss[3].hit_voice = 54; gBoss[3].hit_voice = 54;
gBoss[3].destroy_voice = 71; gBoss[3].destroy_voice = 71;
gBoss[3].size = 2; gBoss[3].size = 2;

View file

@ -45,7 +45,7 @@ int JudgeHitBulletBlock(int x, int y, BULLET *bul)
return hit; return hit;
} }
int JudgeHitBulletBlock2(int x, int y, uint8_t *atrb, BULLET *bul) int JudgeHitBulletBlock2(int x, int y, unsigned char *atrb, BULLET *bul)
{ {
int i; int i;
int workX; int workX;

View file

@ -1,7 +1,5 @@
#pragma once #pragma once
#include <stdint.h>
#include "WindowsWrapper.h" #include "WindowsWrapper.h"
struct BULLET struct BULLET
@ -20,7 +18,7 @@ struct BULLET
int act_wait; int act_wait;
int ani_wait; int ani_wait;
int ani_no; int ani_no;
uint8_t direct; unsigned char direct;
RECT rect; RECT rect;
int count1; int count1;
int count2; int count2;
@ -36,8 +34,8 @@ struct BULLET
struct BULLET_TABLE struct BULLET_TABLE
{ {
int8_t damage; signed char damage;
int8_t life; signed char life;
int life_count; int life_count;
int bbits; int bbits;
int enemyXL; int enemyXL;

View file

@ -1,5 +1,4 @@
#include <stddef.h> #include <stddef.h>
#include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
@ -16,7 +15,7 @@ static const char* const config_magic = "DOUKUTSU20041206"; // Not the original
BOOL LoadConfigData(CONFIG *conf) BOOL LoadConfigData(CONFIG *conf)
{ {
//Clear old config data // Clear old configuration data
memset(conf, 0, sizeof(CONFIG)); memset(conf, 0, sizeof(CONFIG));
// Get path // Get path
@ -69,7 +68,7 @@ BOOL LoadConfigData(CONFIG *conf)
void DefaultConfigData(CONFIG *conf) void DefaultConfigData(CONFIG *conf)
{ {
//Clear old config data // Clear old configuration data
memset(conf, 0, sizeof(CONFIG)); memset(conf, 0, sizeof(CONFIG));
// Fun fact: The Linux port added this line: // Fun fact: The Linux port added this line:

View file

@ -1,19 +1,17 @@
#pragma once #pragma once
#include <stdint.h>
#include "WindowsWrapper.h" #include "WindowsWrapper.h"
struct CONFIG struct CONFIG
{ {
char proof[0x20]; char proof[0x20];
char font_name[0x40]; char font_name[0x40];
int32_t move_button_mode; long move_button_mode;
int32_t attack_button_mode; long attack_button_mode;
int32_t ok_button_mode; long ok_button_mode;
int32_t display_mode; long display_mode;
int32_t bJoystick; long bJoystick;
int32_t joystick_button[8]; long joystick_button[8];
}; };
BOOL LoadConfigData(CONFIG *conf); BOOL LoadConfigData(CONFIG *conf);

View file

@ -1,5 +1,4 @@
#include <stddef.h> #include <stddef.h>
#include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
@ -57,8 +56,8 @@ BOOL Flip_SystemTask()
return FALSE; return FALSE;
// Framerate limiter // Framerate limiter
static uint32_t timePrev; static Uint32 timePrev;
const uint32_t timeNow = SDL_GetTicks(); const Uint32 timeNow = SDL_GetTicks();
if (timeNow >= timePrev + FRAMERATE) if (timeNow >= timePrev + FRAMERATE)
{ {
@ -359,6 +358,9 @@ static BOOL LoadBitmap_Resource(const char *res, Surface_Ids surf_no, bool creat
if (data) if (data)
{ {
// For some dumbass reason, SDL2 measures size with a signed int.
// Has anyone ever told the devs that an int can be as little as 16 bits long? Real portable.
// But hey, if I ever need to create an RWops from an array that's -32768 bytes long, they've got me covered!
SDL_RWops *fp = SDL_RWFromConstMem(data, size); SDL_RWops *fp = SDL_RWFromConstMem(data, size);
printf("Loading surface from resource %s for surface id %d\n", res, surf_no); printf("Loading surface from resource %s for surface id %d\n", res, surf_no);
@ -443,7 +445,7 @@ static void DrawBitmap(RECT *rcView, int x, int y, RECT *rect, Surface_Ids surf_
SDL_Rect clipRect = RectToSDLRectScaled(rcView); SDL_Rect clipRect = RectToSDLRectScaled(rcView);
SDL_Rect frameRect = RectToSDLRectScaled(rect); SDL_Rect frameRect = RectToSDLRectScaled(rect);
// Get dest rect // Get destination rect
SDL_Rect destRect = {x * magnification, y * magnification, frameRect.w, frameRect.h}; SDL_Rect destRect = {x * magnification, y * magnification, frameRect.w, frameRect.h};
// Set cliprect // Set cliprect
@ -485,28 +487,28 @@ unsigned long GetCortBoxColor(unsigned long col)
return col; return col;
} }
void CortBox(RECT *rect, uint32_t col) void CortBox(RECT *rect, unsigned long col)
{ {
// Get rect // Get rect
SDL_Rect destRect = RectToSDLRectScaled(rect); SDL_Rect destRect = RectToSDLRectScaled(rect);
// Set colour and draw // Set colour and draw
const unsigned char col_red = col & 0x0000FF; const unsigned char col_red = (unsigned char)(col & 0xFF);
const unsigned char col_green = (col & 0x00FF00) >> 8; const unsigned char col_green = (unsigned char)((col >> 8) & 0xFF);
const unsigned char col_blue = (col & 0xFF0000) >> 16; const unsigned char col_blue = (unsigned char)((col >> 16) & 0xFF);
SDL_SetRenderDrawColor(gRenderer, col_red, col_green, col_blue, 0xFF); SDL_SetRenderDrawColor(gRenderer, col_red, col_green, col_blue, 0xFF);
SDL_RenderFillRect(gRenderer, &destRect); SDL_RenderFillRect(gRenderer, &destRect);
} }
void CortBox2(RECT *rect, uint32_t col, Surface_Ids surf_no) void CortBox2(RECT *rect, unsigned long col, Surface_Ids surf_no)
{ {
// Get rect // Get rect
SDL_Rect destRect = RectToSDLRectScaled(rect); SDL_Rect destRect = RectToSDLRectScaled(rect);
// Set colour and draw // Set colour and draw
const unsigned char col_red = col & 0x0000FF; const unsigned char col_red = (unsigned char)(col & 0xFF);
const unsigned char col_green = (col & 0x00FF00) >> 8; const unsigned char col_green = (unsigned char)((col >> 8) & 0xFF);
const unsigned char col_blue = (col & 0xFF0000) >> 16; const unsigned char col_blue = (unsigned char)((col >> 16) & 0xFF);
SDL_FillRect(surf[surf_no].surface, &destRect, SDL_MapRGB(surf[surf_no].surface->format, col_red, col_green, col_blue)); SDL_FillRect(surf[surf_no].surface, &destRect, SDL_MapRGB(surf[surf_no].surface->format, col_red, col_green, col_blue));
surf[surf_no].needs_updating = true; surf[surf_no].needs_updating = true;
} }
@ -610,7 +612,7 @@ void InitTextObject(const char *font_name)
gFont = LoadFontFromData(res_data, data_size, fontWidth, fontHeight); gFont = LoadFontFromData(res_data, data_size, fontWidth, fontHeight);
} }
void PutText(int x, int y, const char *text, uint32_t color) void PutText(int x, int y, const char *text, unsigned long color)
{ {
int surface_width, surface_height; int surface_width, surface_height;
SDL_GetRendererOutputSize(gRenderer, &surface_width, &surface_height); SDL_GetRendererOutputSize(gRenderer, &surface_width, &surface_height);
@ -626,7 +628,7 @@ void PutText(int x, int y, const char *text, uint32_t color)
SDL_DestroyTexture(screen_texture); SDL_DestroyTexture(screen_texture);
} }
void PutText2(int x, int y, const char *text, uint32_t color, Surface_Ids surf_no) void PutText2(int x, int y, const char *text, unsigned long color, Surface_Ids surf_no)
{ {
DrawText(gFont, (unsigned char*)surf[surf_no].surface->pixels, surf[surf_no].surface->pitch, surf[surf_no].surface->w, surf[surf_no].surface->h, x * magnification, y * magnification, color, text, strlen(text)); DrawText(gFont, (unsigned char*)surf[surf_no].surface->pixels, surf[surf_no].surface->pitch, surf[surf_no].surface->w, surf[surf_no].surface->h, x * magnification, y * magnification, color, text, strlen(text));
surf[surf_no].needs_updating = true; surf[surf_no].needs_updating = true;

View file

@ -1,7 +1,5 @@
#pragma once #pragma once
#include <stdint.h>
#include "WindowsWrapper.h" #include "WindowsWrapper.h"
#ifndef RGB #ifndef RGB
@ -68,9 +66,9 @@ void PutBitmap3(RECT *rcView, int x, int y, RECT *rect, Surface_Ids surf_no);
void PutBitmap4(RECT *rcView, int x, int y, RECT *rect, Surface_Ids surf_no); void PutBitmap4(RECT *rcView, int x, int y, RECT *rect, Surface_Ids surf_no);
void Surface2Surface(int x, int y, RECT *rect, int to, int from); void Surface2Surface(int x, int y, RECT *rect, int to, int from);
unsigned long GetCortBoxColor(unsigned long col); unsigned long GetCortBoxColor(unsigned long col);
void CortBox(RECT *rect, uint32_t col); void CortBox(RECT *rect, unsigned long col);
void CortBox2(RECT *rect, uint32_t col, Surface_Ids surf_no); void CortBox2(RECT *rect, unsigned long col, Surface_Ids surf_no);
void InitTextObject(const char *font_name); void InitTextObject(const char *font_name);
void PutText(int x, int y, const char *text, uint32_t color); void PutText(int x, int y, const char *text, unsigned long color);
void PutText2(int x, int y, const char *text, uint32_t color, Surface_Ids surf_no); void PutText2(int x, int y, const char *text, unsigned long color, Surface_Ids surf_no);
void EndTextObject(); void EndTextObject();

View file

@ -1,6 +1,5 @@
#include "Ending.h" #include "Ending.h"
#include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -184,7 +183,7 @@ bool StartCreditScript()
// Read data // Read data
fread(Credit.pData, 1, Credit.size, fp); fread(Credit.pData, 1, Credit.size, fp);
EncryptionBinaryData2((uint8_t*)Credit.pData, Credit.size); EncryptionBinaryData2((unsigned char*)Credit.pData, Credit.size);
#ifdef FIX_BUGS #ifdef FIX_BUGS
// The original game forgot to close the file // The original game forgot to close the file
@ -229,7 +228,7 @@ void ActionCredit_Read()
while (Credit.offset < Credit.size) while (Credit.offset < Credit.size)
{ {
// Get character // Get character
uint8_t character = Credit.pData[Credit.offset]; unsigned char character = Credit.pData[Credit.offset];
int a, b, len; int a, b, len;
switch (character) switch (character)

View file

@ -1,7 +1,5 @@
#pragma once #pragma once
#include <stdint.h>
struct CREDIT struct CREDIT
{ {
int size; int size;

View file

@ -13,7 +13,7 @@ FRAME gFrame;
void MoveFrame3() void MoveFrame3()
{ {
int16_t map_w, map_l; short map_w, map_l;
GetMapData(0, &map_w, &map_l); GetMapData(0, &map_w, &map_l);
#if WINDOW_WIDTH != 320 || WINDOW_HEIGHT != 240 // TODO - Really need to make this a compiler flag #if WINDOW_WIDTH != 320 || WINDOW_HEIGHT != 240 // TODO - Really need to make this a compiler flag
@ -119,7 +119,7 @@ void SetFramePosition(int fx, int fy)
gFrame.quake2 = 0; gFrame.quake2 = 0;
//Move frame position //Move frame position
int16_t map_w, map_l; short map_w, map_l;
GetMapData(0, &map_w, &map_l); GetMapData(0, &map_w, &map_l);
gFrame.x = fx; gFrame.x = fx;
@ -143,7 +143,7 @@ void SetFrameMyChar()
int mc_x, mc_y; int mc_x, mc_y;
GetMyCharPosition(&mc_x, &mc_y); GetMyCharPosition(&mc_x, &mc_y);
int16_t map_w, map_l; short map_w, map_l;
GetMapData(0, &map_w, &map_l); GetMapData(0, &map_w, &map_l);
gFrame.x = mc_x - (WINDOW_WIDTH << 8); gFrame.x = mc_x - (WINDOW_WIDTH << 8);

View file

@ -304,7 +304,7 @@ int ModeTitle()
break; break;
} }
//Reset cliprect, flags, and give the player the nikumaru counter // Reset cliprect, flags, and give the player the Nikumaru counter
grcGame.left = 0; grcGame.left = 0;
// Non-vanilla: these three lines are widescreen-related(?) // Non-vanilla: these three lines are widescreen-related(?)
grcGame.top = 0; grcGame.top = 0;

View file

@ -1,6 +1,5 @@
#include "Generic.h" #include "Generic.h"
#include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include "CommonDefines.h" #include "CommonDefines.h"
@ -45,7 +44,7 @@ bool CheckFileExists(const char *name)
return false; return false;
} }
bool IsShiftJIS(uint8_t c) bool IsShiftJIS(unsigned char c)
{ {
if (c > 0x80 && c < 0xA0) if (c > 0x80 && c < 0xA0)
return true; return true;

View file

@ -1,8 +1,6 @@
#pragma once #pragma once
#include <stdint.h>
bool GetCompileVersion(int *v1, int *v2, int *v3, int *v4); bool GetCompileVersion(int *v1, int *v2, int *v3, int *v4);
long GetFileSizeLong(const char *path); long GetFileSizeLong(const char *path);
bool CheckFileExists(const char *name); bool CheckFileExists(const char *name);
bool IsShiftJIS(uint8_t c); bool IsShiftJIS(unsigned char c);

View file

@ -1,7 +1,6 @@
#include "Input.h" #include "Input.h"
#include <stddef.h> #include <stddef.h>
#include <stdint.h>
#include <string.h> #include <string.h>
#include <SDL.h> #include <SDL.h>
@ -14,7 +13,7 @@
#define JOYSTICK_DEADZONE 10000 #define JOYSTICK_DEADZONE 10000
SDL_Joystick *joystick; //This may be a name that was given by Simon, but it fits the rest of Pixel's names so it's fine. SDL_Joystick *joystick; // This was probably a name that was given by Simon, but it fits the rest of Pixel's names so it's fine.
void ReleaseDirectInput() void ReleaseDirectInput()
{ {
@ -51,8 +50,8 @@ bool GetJoystickStatus(JOYSTICK_STATUS *pStatus)
if (joystick) if (joystick)
{ {
int32_t x = SDL_JoystickGetAxis(joystick, 0); Sint16 x = SDL_JoystickGetAxis(joystick, 0);
int32_t y = SDL_JoystickGetAxis(joystick, 1); Sint16 y = SDL_JoystickGetAxis(joystick, 1);
pStatus->bLeft = x <= -JOYSTICK_DEADZONE; pStatus->bLeft = x <= -JOYSTICK_DEADZONE;
pStatus->bRight = x >= JOYSTICK_DEADZONE; pStatus->bRight = x >= JOYSTICK_DEADZONE;
pStatus->bUp = y <= -JOYSTICK_DEADZONE; pStatus->bUp = y <= -JOYSTICK_DEADZONE;

View file

@ -1,7 +1,6 @@
#include "Main.h" #include "Main.h"
#include <stddef.h> #include <stddef.h>
#include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>

View file

@ -1,7 +1,6 @@
#include "Map.h" #include "Map.h"
#include <stddef.h> #include <stddef.h>
#include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -21,7 +20,7 @@ static const char *code_pxma = "PXM";
BOOL InitMapData2() BOOL InitMapData2()
{ {
gMap.data = (uint8_t*)malloc(PXM_BUFFER_SIZE); gMap.data = (unsigned char*)malloc(PXM_BUFFER_SIZE);
return TRUE; return TRUE;
} }
@ -103,7 +102,7 @@ void ReleasePartsImage()
ReleaseSurface(SURFACE_ID_LEVEL_TILESET); ReleaseSurface(SURFACE_ID_LEVEL_TILESET);
} }
void GetMapData(uint8_t **data, int16_t *mw, int16_t *ml) void GetMapData(unsigned char **data, short *mw, short *ml)
{ {
if (data) if (data)
*data = gMap.data; *data = gMap.data;
@ -132,7 +131,7 @@ void ShiftMapParts(int x, int y)
*(gMap.data + x + gMap.width * y) -= 1; *(gMap.data + x + gMap.width * y) -= 1;
} }
BOOL ChangeMapParts(int x, int y, uint8_t no) BOOL ChangeMapParts(int x, int y, unsigned char no)
{ {
if (*(gMap.data + x + gMap.width * y) == no) if (*(gMap.data + x + gMap.width * y) == no)
return FALSE; return FALSE;

View file

@ -1,15 +1,13 @@
#pragma once #pragma once
#include <stdint.h>
#include "WindowsWrapper.h" #include "WindowsWrapper.h"
struct MAP_DATA struct MAP_DATA
{ {
uint8_t *data; unsigned char *data;
uint8_t atrb[0x101]; //Why is this 257 bytes? unsigned char atrb[0x101]; //Why is this 257 bytes?
int16_t width; short width;
int16_t length; short length;
}; };
extern MAP_DATA gMap; extern MAP_DATA gMap;
@ -19,11 +17,11 @@ BOOL LoadMapData2(const char *path_map);
BOOL LoadAttributeData(const char *path_atrb); BOOL LoadAttributeData(const char *path_atrb);
void EndMapData(); void EndMapData();
void ReleasePartsImage(); void ReleasePartsImage();
void GetMapData(uint8_t **data, int16_t *mw, int16_t *ml); void GetMapData(unsigned char **data, short *mw, short *ml);
unsigned char GetAttribute(int x, int y); unsigned char GetAttribute(int x, int y);
void DeleteMapParts(int x, int y); void DeleteMapParts(int x, int y);
void ShiftMapParts(int x, int y); void ShiftMapParts(int x, int y);
BOOL ChangeMapParts(int x, int y, uint8_t no); BOOL ChangeMapParts(int x, int y, unsigned char no);
void PutStage_Back(int fx, int fy); void PutStage_Back(int fx, int fy);
void PutStage_Front(int fx, int fy); void PutStage_Front(int fx, int fy);
void PutMapDataVector(int fx, int fy); void PutMapDataVector(int fx, int fy);

View file

@ -1,6 +1,5 @@
#include "MapName.h" #include "MapName.h"
#include <stdint.h>
#include <string.h> #include <string.h>
#include "CommonDefines.h" #include "CommonDefines.h"

View file

@ -1,6 +1,5 @@
#include "MiniMap.h" #include "MiniMap.h"
#include <stdint.h>
#include <string.h> #include <string.h>
#include "WindowsWrapper.h" #include "WindowsWrapper.h"
@ -127,7 +126,7 @@ int MiniMapLoop()
CortBox2(&rcMiniMap, 0, SURFACE_ID_MAP); CortBox2(&rcMiniMap, 0, SURFACE_ID_MAP);
int line = 0; int line = 0;
uint8_t my_wait = 0; unsigned char my_wait = 0;
while (true) while (true)
{ {
GetTrg(); GetTrg();

View file

@ -1,7 +1,5 @@
#pragma once #pragma once
#include <stdint.h>
#include "WindowsWrapper.h" #include "WindowsWrapper.h"
extern char gMapping[0x80]; extern char gMapping[0x80];

View file

@ -1,6 +1,5 @@
#include "MyChar.h" #include "MyChar.h"
#include <stdint.h>
#include <string.h> #include <string.h>
#include "WindowsWrapper.h" #include "WindowsWrapper.h"
@ -44,7 +43,7 @@ void InitMyChar()
gMC.unit = 0; gMC.unit = 0;
} }
void AnimationMyChar(bool bKey) void AnimationMyChar(BOOL bKey)
{ {
RECT rcLeft[12] = { RECT rcLeft[12] = {
{0, 0, 16, 16}, {0, 0, 16, 16},
@ -76,8 +75,9 @@ void AnimationMyChar(bool bKey)
{112, 16, 128, 32}, {112, 16, 128, 32},
}; };
if (!(gMC.cond & 2)) if (gMC.cond & 2)
{ return;
if (gMC.flag & 8) if (gMC.flag & 8)
{ {
if (gMC.cond & 1) if (gMC.cond & 1)
@ -137,23 +137,21 @@ void AnimationMyChar(bool bKey)
{ {
gMC.ani_no = 10; gMC.ani_no = 10;
} }
else if (gMC.ym <= 0) else
{ {
if (gMC.ym > 0)
gMC.ani_no = 1;
else
gMC.ani_no = 3; gMC.ani_no = 3;
} }
else
{
gMC.ani_no = 1;
}
if (gMC.direct) if (gMC.direct == 0)
gMC.rect = rcRight[gMC.ani_no];
else
gMC.rect = rcLeft[gMC.ani_no]; gMC.rect = rcLeft[gMC.ani_no];
} else
gMC.rect = rcRight[gMC.ani_no];
} }
void ShowMyChar(bool bShow) void ShowMyChar(BOOL bShow)
{ {
if (bShow) if (bShow)
gMC.cond &= ~2; gMC.cond &= ~2;
@ -163,8 +161,11 @@ void ShowMyChar(bool bShow)
void PutMyChar(int fx, int fy) void PutMyChar(int fx, int fy)
{ {
if ((gMC.cond & 0x80) && !(gMC.cond & 2)) int arms_offset_y;
{
if ((gMC.cond & 0x80) == 0 || (gMC.cond & 2))
return;
// Draw weapon // Draw weapon
gMC.rect_arms.left = 24 * (gArmsData[gSelectedArms].code % 13); gMC.rect_arms.left = 24 * (gArmsData[gSelectedArms].code % 13);
gMC.rect_arms.right = gMC.rect_arms.left + 24; gMC.rect_arms.right = gMC.rect_arms.left + 24;
@ -177,7 +178,6 @@ void PutMyChar(int fx, int fy)
gMC.rect_arms.bottom += 16; gMC.rect_arms.bottom += 16;
} }
int arms_offset_y;
if (gMC.up) if (gMC.up)
{ {
arms_offset_y = -4; arms_offset_y = -4;
@ -198,23 +198,24 @@ void PutMyChar(int fx, int fy)
if (gMC.ani_no == 1 || gMC.ani_no == 3 || gMC.ani_no == 6 || gMC.ani_no == 8) if (gMC.ani_no == 1 || gMC.ani_no == 3 || gMC.ani_no == 6 || gMC.ani_no == 8)
++gMC.rect_arms.top; ++gMC.rect_arms.top;
if (gMC.direct) if (gMC.direct == 0)
PutBitmap3(
&grcGame,
(gMC.x - gMC.view.left) / 0x200 - fx / 0x200,
(gMC.y - gMC.view.top) / 0x200 - fy / 0x200 + arms_offset_y,
&gMC.rect_arms,
SURFACE_ID_ARMS);
else
PutBitmap3( PutBitmap3(
&grcGame, &grcGame,
(gMC.x - gMC.view.left) / 0x200 - fx / 0x200 - 8, (gMC.x - gMC.view.left) / 0x200 - fx / 0x200 - 8,
(gMC.y - gMC.view.top) / 0x200 - fy / 0x200 + arms_offset_y, (gMC.y - gMC.view.top) / 0x200 - fy / 0x200 + arms_offset_y,
&gMC.rect_arms, &gMC.rect_arms,
SURFACE_ID_ARMS); SURFACE_ID_ARMS);
else
PutBitmap3(
&grcGame,
(gMC.x - gMC.view.left) / 0x200 - fx / 0x200,
(gMC.y - gMC.view.top) / 0x200 - fy / 0x200 + arms_offset_y,
&gMC.rect_arms,
SURFACE_ID_ARMS);
if ((gMC.shock / 2) % 2)
return;
if (!((gMC.shock >> 1) & 1))
{
// Draw player // Draw player
RECT rect = gMC.rect; RECT rect = gMC.rect;
if (gMC.equip & 0x40) if (gMC.equip & 0x40)
@ -233,18 +234,15 @@ void PutMyChar(int fx, int fy)
++gMC.bubble; ++gMC.bubble;
if (gMC.equip & 0x10 && gMC.flag & 0x100) if (gMC.equip & 0x10 && gMC.flag & 0x100)
PutBitmap3(&grcGame, gMC.x / 0x200 - 12 - fx / 0x200, gMC.y / 0x200 - 12 - fy / 0x200, &rcBubble[(gMC.bubble >> 1) & 1], SURFACE_ID_CARET); PutBitmap3(&grcGame, gMC.x / 0x200 - 12 - fx / 0x200, gMC.y / 0x200 - 12 - fy / 0x200, &rcBubble[(gMC.bubble / 2) % 2], SURFACE_ID_CARET);
else if (gMC.unit == 1) else if (gMC.unit == 1)
PutBitmap3(&grcGame, gMC.x / 0x200 - 12 - fx / 0x200, gMC.y / 0x200 - 12 - fy / 0x200, &rcBubble[(gMC.bubble >> 1) & 1], SURFACE_ID_CARET); PutBitmap3(&grcGame, gMC.x / 0x200 - 12 - fx / 0x200, gMC.y / 0x200 - 12 - fy / 0x200, &rcBubble[(gMC.bubble / 2) % 2], SURFACE_ID_CARET);
}
}
} }
void ActMyChar_Normal(bool bKey) void ActMyChar_Normal(BOOL bKey)
{
if (!(gMC.cond & 2))
{ {
// Get speeds and accelerations // Get speeds and accelerations
int max_move; // Unused
int max_dash; int max_dash;
int gravity1; int gravity1;
int gravity2; int gravity2;
@ -253,9 +251,16 @@ void ActMyChar_Normal(bool bKey)
int dash2; int dash2;
int resist; int resist;
int a;
int x;
if (gMC.cond & 2)
return;
if (gMC.flag & 0x100) if (gMC.flag & 0x100)
{ {
max_dash = 0x196; max_dash = 0x196;
max_move = 0x2FF;
gravity1 = 0x28; gravity1 = 0x28;
gravity2 = 0x10; gravity2 = 0x10;
jump = 0x280; jump = 0x280;
@ -266,6 +271,7 @@ void ActMyChar_Normal(bool bKey)
else else
{ {
max_dash = 0x32C; max_dash = 0x32C;
max_move = 0x5FF;
gravity1 = 0x50; gravity1 = 0x50;
gravity2 = 0x20; gravity2 = 0x20;
jump = 0x500; jump = 0x500;
@ -303,9 +309,16 @@ void ActMyChar_Normal(bool bKey)
// Move in direction held // Move in direction held
if (bKey) if (bKey)
{ {
if (gKeyTrg != gKeyDown || gKey != gKeyDown || (gMC.cond & 1) || g_GameFlags & 4) if (gKeyTrg == gKeyDown && gKey == gKeyDown && (gMC.cond & 1) == 0 && (g_GameFlags & 4) == 0)
{ {
if (gKey != gKeyDown) gMC.cond |= 1;
gMC.ques = 1;
}
else if (gKey == gKeyDown)
{
}
else
{ {
if (gKey & gKeyLeft && gMC.xm > -max_dash) if (gKey & gKeyLeft && gMC.xm > -max_dash)
gMC.xm -= dash1; gMC.xm -= dash1;
@ -318,29 +331,23 @@ void ActMyChar_Normal(bool bKey)
gMC.direct = 2; gMC.direct = 2;
} }
} }
else
{
gMC.cond |= 1;
gMC.ques = 1;
}
}
// Friction // Friction
if (!(gMC.cond & 0x20)) if (!(gMC.cond & 0x20))
{ {
if (gMC.xm < 0) if (gMC.xm < 0)
{ {
if (gMC.xm <= -resist) if (gMC.xm > -resist)
gMC.xm += resist;
else
gMC.xm = 0; gMC.xm = 0;
else
gMC.xm += resist;
} }
if (gMC.xm > 0) if (gMC.xm > 0)
{ {
if (gMC.xm >= resist) if (gMC.xm < resist)
gMC.xm -= resist;
else
gMC.xm = 0; gMC.xm = 0;
else
gMC.xm -= resist;
} }
} }
} }
@ -425,17 +432,30 @@ void ActMyChar_Normal(bool bKey)
if (bKey) if (bKey)
{ {
// Look up and down // Look up and down
gMC.up = (gKey & gKeyUp) != 0; if (gKey & gKeyUp)
gMC.down = gKey & gKeyDown && !(gMC.flag & 8); gMC.up = TRUE;
else
gMC.up = FALSE;
if (gKey & gKeyDown && (gMC.flag & 8) == 0)
gMC.down = TRUE;
else
gMC.down = FALSE;
if (gKeyTrg & gKeyJump if (gKeyTrg & gKeyJump
&& (gMC.flag & 8 || gMC.flag & 0x10 || gMC.flag & 0x20) && (gMC.flag & 8 || gMC.flag & 0x10 || gMC.flag & 0x20))
&& !(gMC.flag & 0x2000)) {
if (gMC.flag & 0x2000)
{
// Another weird empty case needed for accurate assembly
}
else
{ {
gMC.ym = -jump; gMC.ym = -jump;
PlaySoundObject(15, 1); PlaySoundObject(15, 1);
} }
} }
}
// Stop interacting when moved // Stop interacting when moved
if (bKey && (gKeyShot | gKeyJump | gKeyUp | gKeyRight | gKeyLeft) & gKey) if (bKey && (gKeyShot | gKeyJump | gKeyUp | gKeyRight | gKeyLeft) & gKey)
@ -533,7 +553,7 @@ void ActMyChar_Normal(bool bKey)
} }
// Keep player on slopes // Keep player on slopes
if (bKey && !(gKeyTrg & gKeyJump)) if (!bKey || !(gKeyTrg & gKeyJump))
{ {
if (gMC.flag & 0x10 && gMC.xm < 0) if (gMC.flag & 0x10 && gMC.xm < 0)
gMC.ym = -gMC.xm; gMC.ym = -gMC.xm;
@ -547,19 +567,15 @@ void ActMyChar_Normal(bool bKey)
gMC.ym = 0x400; gMC.ym = 0x400;
} }
// Limit speed if (0)
if (!(gMC.flag & 0x100) || gMC.flag & 0xF000)
{ {
if (gMC.xm < -0x5FF) // There used to be an if here that didn't do anything, but the compiler optimised it out.
gMC.xm = -0x5FF; // We only know this was here because empty ifs mess with the register usage.
if (gMC.xm > 0x5FF) // Since there's no code, we have no idea what the original condition actually was.
gMC.xm = 0x5FF;
if (gMC.ym < -0x5FF)
gMC.ym = -0x5FF;
if (gMC.ym > 0x5FF)
gMC.ym = 0x5FF;
} }
else
// Limit speed
if ((gMC.flag & 0x100) && (gMC.flag & 0xF000) == 0)
{ {
if (gMC.xm < -0x2FF) if (gMC.xm < -0x2FF)
gMC.xm = -0x2FF; gMC.xm = -0x2FF;
@ -570,6 +586,17 @@ void ActMyChar_Normal(bool bKey)
if (gMC.ym > 0x2FF) if (gMC.ym > 0x2FF)
gMC.ym = 0x2FF; gMC.ym = 0x2FF;
} }
else
{
if (gMC.xm < -0x5FF)
gMC.xm = -0x5FF;
if (gMC.xm > 0x5FF)
gMC.xm = 0x5FF;
if (gMC.ym < -0x5FF)
gMC.ym = -0x5FF;
if (gMC.ym > 0x5FF)
gMC.ym = 0x5FF;
}
// Water splashing // Water splashing
if (!gMC.sprash && gMC.flag & 0x100) if (!gMC.sprash && gMC.flag & 0x100)
@ -580,23 +607,29 @@ void ActMyChar_Normal(bool bKey)
else else
dir = 0; dir = 0;
if (gMC.flag & 8 || gMC.ym <= 0x200) if ((gMC.flag & 8) == 0 && gMC.ym > 0x200)
{ {
if (gMC.xm > 0x200 || gMC.xm < -0x200) for (a = 0; a < 8; a++)
{ {
for (int a = 0; a < 8; a++) x = gMC.x + (Random(-8, 8) * 0x200);
SetNpChar(73, gMC.x + (Random(-8, 8) << 9), gMC.y, gMC.xm + Random(-0x200, 0x200), Random(-0x200, 0x80), dir, 0, 0); SetNpChar(73, x, gMC.y, gMC.xm + Random(-0x200, 0x200), Random(-0x200, 0x80) - gMC.ym / 2, dir, 0, 0);
}
PlaySoundObject(56, 1); PlaySoundObject(56, 1);
} }
}
else else
{ {
for (int a = 0; a < 8; a++) if (gMC.xm > 0x200 || gMC.xm < -0x200)
SetNpChar(73, gMC.x + (Random(-8, 8) << 9), gMC.y, gMC.xm + Random(-0x200, 0x200), Random(-0x200, 0x80) - gMC.ym / 2, dir, 0, 0); {
for (a = 0; a < 8; a++)
{
x = gMC.x + (Random(-8, 8) * 0x200);
SetNpChar(73, x, gMC.y, gMC.xm + Random(-0x200, 0x200), Random(-0x200, 0x80), dir, 0, 0);
}
PlaySoundObject(56, 1); PlaySoundObject(56, 1);
} }
}
gMC.sprash = 1; gMC.sprash = 1;
} }
@ -609,18 +642,18 @@ void ActMyChar_Normal(bool bKey)
DamageMyChar(10); DamageMyChar(10);
// Camera // Camera
if (gMC.direct) if (gMC.direct == 0)
{
gMC.index_x += 0x200;
if (gMC.index_x > 0x8000)
gMC.index_x = 0x8000;
}
else
{ {
gMC.index_x -= 0x200; gMC.index_x -= 0x200;
if (gMC.index_x < -0x8000) if (gMC.index_x < -0x8000)
gMC.index_x = -0x8000; gMC.index_x = -0x8000;
} }
else
{
gMC.index_x += 0x200;
if (gMC.index_x > 0x8000)
gMC.index_x = 0x8000;
}
if (gKey & gKeyUp && bKey) if (gKey & gKeyUp && bKey)
{ {
gMC.index_y -= 0x200; gMC.index_y -= 0x200;
@ -645,16 +678,22 @@ void ActMyChar_Normal(bool bKey)
gMC.tgt_y = gMC.y + gMC.index_y; gMC.tgt_y = gMC.y + gMC.index_y;
// Change position // Change position
if (gMC.xm > resist || gMC.xm < -resist) if (gMC.xm <= resist && gMC.xm >= -resist)
gMC.x += gMC.xm; {
gMC.y += gMC.ym; // Okay, this is getting stupid. Why the HELL is the code written like this?
} }
else
{
gMC.x += gMC.xm;
} }
void ActMyChar_Stream(bool bKey) gMC.y += gMC.ym;
}
void ActMyChar_Stream(BOOL bKey)
{ {
gMC.up = false; gMC.up = FALSE;
gMC.down = false; gMC.down = FALSE;
if (bKey) if (bKey)
{ {
@ -666,17 +705,18 @@ void ActMyChar_Stream(bool bKey)
if (gKey & gKeyRight) if (gKey & gKeyRight)
gMC.xm += 0x100; gMC.xm += 0x100;
} }
else if (gMC.xm > 0x7F || gMC.xm < -0x7F) else if (gMC.xm < 0x80 && gMC.xm > -0x80)
{
if (gMC.xm > 0)
gMC.xm -= 0x80;
else if (gMC.xm < 0)
gMC.xm += 0x80;
}
else
{ {
gMC.xm = 0; gMC.xm = 0;
} }
else if (gMC.xm > 0)
{
gMC.xm -= 0x80;
}
else if (gMC.xm < 0)
{
gMC.xm += 0x80;
}
if (gKey & (gKeyDown | gKeyUp)) if (gKey & (gKeyDown | gKeyUp))
{ {
@ -686,44 +726,35 @@ void ActMyChar_Stream(bool bKey)
if (gKey & gKeyDown) if (gKey & gKeyDown)
gMC.ym += 0x100; gMC.ym += 0x100;
} }
else if (gMC.ym > 0x7F || gMC.ym < -0x7F) else if (gMC.ym < 0x80 && gMC.ym > -0x80)
{
if (gMC.ym > 0)
gMC.ym -= 0x80;
else if (gMC.ym < 0)
gMC.ym += 0x80;
}
else
{ {
gMC.ym = 0; gMC.ym = 0;
} }
else if (gMC.ym > 0)
{
gMC.ym -= 0x80;
}
else if (gMC.ym < 0)
{
gMC.ym += 0x80;
}
} }
else else
{ {
if (gMC.xm > 0x7F || gMC.xm < -0x3F) if (gMC.xm < 0x80 && gMC.xm > -0x40)
{ gMC.xm = 0;
if (gMC.xm > 0) else if (gMC.xm > 0)
gMC.xm -= 0x80; gMC.xm -= 0x80;
else if (gMC.xm < 0) else if (gMC.xm < 0)
gMC.xm += 0x80; gMC.xm += 0x80;
}
else
{
gMC.xm = 0;
}
if (gMC.ym > 0x7F || gMC.ym < -0x3F) if (gMC.ym < 0x80 && gMC.ym > -0x40)
{ gMC.ym = 0;
if (gMC.ym > 0) else if (gMC.ym > 0)
gMC.ym -= 0x80; gMC.ym -= 0x80;
else if (gMC.ym < 0) else if (gMC.ym < 0)
gMC.ym += 0x80; gMC.ym += 0x80;
} }
else
{
gMC.ym = 0;
}
}
if (gMC.ym < -0x200 && gMC.flag & 2) if (gMC.ym < -0x200 && gMC.flag & 2)
SetCaret(gMC.x, gMC.y - gMC.hit.top, 13, 5); SetCaret(gMC.x, gMC.y - gMC.hit.top, 13, 5);
@ -785,7 +816,11 @@ void AirProcess()
} }
else else
{ {
if (gMC.flag & 0x100) if ((gMC.flag & 0x100) == 0)
{
gMC.air = 1000;
}
else
{ {
if (--gMC.air <= 0) if (--gMC.air <= 0)
{ {
@ -799,19 +834,15 @@ void AirProcess()
// Drown // Drown
StartTextScript(41); StartTextScript(41);
if (gMC.direct) if (gMC.direct == 0)
SetCaret(gMC.x, gMC.y, 8, 2);
else
SetCaret(gMC.x, gMC.y, 8, 0); SetCaret(gMC.x, gMC.y, 8, 0);
else
SetCaret(gMC.x, gMC.y, 8, 2);
gMC.cond &= ~0x80; gMC.cond &= ~0x80;
} }
} }
} }
else
{
gMC.air = 1000;
}
if (gMC.flag & 0x100) if (gMC.flag & 0x100)
{ {
@ -824,10 +855,11 @@ void AirProcess()
} }
} }
void ActMyChar(bool bKey) void ActMyChar(BOOL bKey)
{
if (gMC.cond & 0x80)
{ {
if ((gMC.cond & 0x80) == 0)
return;
if (gMC.exp_wait) if (gMC.exp_wait)
--gMC.exp_wait; --gMC.exp_wait;
@ -852,14 +884,10 @@ void ActMyChar(bool bKey)
case 1: case 1:
ActMyChar_Stream(bKey); ActMyChar_Stream(bKey);
break; break;
default:
break;
} }
gMC.cond &= ~0x20; gMC.cond &= ~0x20;
} }
}
void GetMyCharPosition(int *x, int *y) void GetMyCharPosition(int *x, int *y)
{ {
@ -871,8 +899,8 @@ void SetMyCharPosition(int x, int y)
{ {
gMC.x = x; gMC.x = x;
gMC.y = y; gMC.y = y;
gMC.tgt_x = x; gMC.tgt_x = gMC.x;
gMC.tgt_y = y; gMC.tgt_y = gMC.y;
gMC.index_x = 0; gMC.index_x = 0;
gMC.index_y = 0; gMC.index_y = 0;
gMC.xm = 0; gMC.xm = 0;
@ -897,42 +925,42 @@ int GetUnitMyChar()
return gMC.unit; return gMC.unit;
} }
void SetMyCharDirect(uint8_t dir) void SetMyCharDirect(unsigned char dir)
{ {
switch (dir) if (dir == 3)
{ {
case 3:
gMC.cond |= 1; gMC.cond |= 1;
break; }
else
default: {
gMC.cond &= ~1; gMC.cond &= ~1;
if (dir < 10) if (dir < 10)
{ {
gMC.direct = dir; gMC.direct = dir;
break;
} }
for (int i = 0; i < NPC_MAX; i++)
{
if (gNPC[i].code_event == dir)
{
if (gMC.x <= gNPC[i].x)
gMC.direct = 2;
else else
{
int i;
for (i = 0; i < NPC_MAX; i++)
if (gNPC[i].code_event == dir)
break;
if (i == NPC_MAX)
return;
if (gMC.x > gNPC[i].x)
gMC.direct = 0; gMC.direct = 0;
break; else
gMC.direct = 2;
} }
} }
break;
}
gMC.xm = 0; gMC.xm = 0;
AnimationMyChar(false); AnimationMyChar(FALSE);
} }
void ChangeMyUnit(uint8_t a) void ChangeMyUnit(unsigned char a)
{ {
gMC.unit = a; gMC.unit = a;
} }
@ -942,7 +970,7 @@ void PitMyChar()
gMC.y += 0x4000; gMC.y += 0x4000;
} }
void EquipItem(int flag, bool b) void EquipItem(int flag, BOOL b)
{ {
if (b) if (b)
gMC.equip |= flag; gMC.equip |= flag;
@ -960,16 +988,18 @@ void SetNoise(int no, int freq)
noise_freq = freq; noise_freq = freq;
noise_no = no; noise_no = no;
if (no == 1) switch (noise_no)
{ {
case 1:
ChangeSoundFrequency(40, noise_freq); ChangeSoundFrequency(40, noise_freq);
ChangeSoundFrequency(41, noise_freq + 100); ChangeSoundFrequency(41, noise_freq + 100);
PlaySoundObject(40, -1); PlaySoundObject(40, -1);
PlaySoundObject(41, -1); PlaySoundObject(41, -1);
} break;
else if (no == 2)
{ case 2:
PlaySoundObject(58, -1); PlaySoundObject(58, -1);
break;
} }
} }
@ -983,16 +1013,18 @@ void CutNoise()
void ResetNoise() void ResetNoise()
{ {
if (noise_no == 1) switch (noise_no)
{ {
case 1:
ChangeSoundFrequency(40, noise_freq); ChangeSoundFrequency(40, noise_freq);
ChangeSoundFrequency(41, noise_freq + 100); ChangeSoundFrequency(41, noise_freq + 100);
PlaySoundObject(40, -1); PlaySoundObject(40, -1);
PlaySoundObject(41, -1); PlaySoundObject(41, -1);
} break;
else if (noise_no == 2)
{ case 2:
PlaySoundObject(58, -1); PlaySoundObject(58, -1);
break;
} }
} }

View file

@ -1,16 +1,14 @@
#pragma once #pragma once
#include <stdint.h>
#include "WindowsWrapper.h" #include "WindowsWrapper.h"
struct MYCHAR struct MYCHAR
{ {
uint8_t cond; unsigned char cond;
unsigned int flag; unsigned int flag;
int direct; int direct;
int up; BOOL up;
int down; BOOL down;
int unit; int unit;
int equip; int equip;
int x; int x;
@ -30,41 +28,41 @@ struct MYCHAR
int level; int level;
int exp_wait; int exp_wait;
int exp_count; int exp_count;
uint8_t shock; unsigned char shock;
uint8_t no_life; unsigned char no_life;
uint8_t rensha; unsigned char rensha;
uint8_t bubble; unsigned char bubble;
int16_t life; short life;
int16_t star; short star;
int16_t max_life; short max_life;
int16_t a; short a;
int lifeBr; int lifeBr;
int lifeBr_count; int lifeBr_count;
int air; int air;
int air_get; int air_get;
int8_t sprash; signed char sprash;
int8_t ques; signed char ques;
int8_t boost_sw; signed char boost_sw;
int boost_cnt; int boost_cnt;
}; };
extern MYCHAR gMC; extern MYCHAR gMC;
void InitMyChar(); void InitMyChar();
void AnimationMyChar(bool bKey); void AnimationMyChar(BOOL bKey);
void ShowMyChar(bool bShow); void ShowMyChar(BOOL bShow);
void PutMyChar(int fx, int fy); void PutMyChar(int fx, int fy);
void ActMyChar_Normal(bool bKey); void ActMyChar_Normal(BOOL bKey);
void ActMyChar(bool bKey); void ActMyChar(BOOL bKey);
void GetMyCharPosition(int *x, int *y); void GetMyCharPosition(int *x, int *y);
void SetMyCharPosition(int x, int y); void SetMyCharPosition(int x, int y);
void MoveMyChar(int x, int y); void MoveMyChar(int x, int y);
void ZeroMyCharXMove(); void ZeroMyCharXMove();
int GetUnitMyChar(); int GetUnitMyChar();
void SetMyCharDirect(uint8_t dir); void SetMyCharDirect(unsigned char dir);
void ChangeMyUnit(uint8_t a); void ChangeMyUnit(unsigned char a);
void PitMyChar(); void PitMyChar();
void EquipItem(int flag, bool b); void EquipItem(int flag, BOOL b);
void ResetCheck(); void ResetCheck();
void SetNoise(int no, int freq); void SetNoise(int no, int freq);
void CutNoise(); void CutNoise();

View file

@ -1,7 +1,5 @@
#include "MycHit.h" #include "MycHit.h"
#include <stdint.h>
#include "WindowsWrapper.h" #include "WindowsWrapper.h"
#include "Back.h" #include "Back.h"
@ -36,13 +34,13 @@ int JudgeHitMyCharBlock(int x, int y)
int hit = 0; int hit = 0;
// Left wall // Left wall
if (gMC.y - gMC.hit.top < (2 * (2 * y + 1) - 1) << 11 if (gMC.y - gMC.hit.top < (y * 0x10 + 4) * 0x200
&& gMC.y + gMC.hit.bottom > (2 * (2 * y - 1) + 1) << 11 && gMC.y + gMC.hit.bottom > (y * 0x10 - 4) * 0x200
&& gMC.x - gMC.hit.left < (2 * x + 1) << 12 && gMC.x - gMC.hit.left < (x * 0x10 + 8) * 0x200
&& gMC.x - gMC.hit.left > x << 13) && gMC.x - gMC.hit.left > x * 0x10 * 0x200)
{ {
// Clip // Clip
gMC.x = ((2 * x + 1) << 12) + gMC.hit.left; gMC.x = ((x * 0x10 + 8) * 0x200) + gMC.hit.left;
// Halt momentum // Halt momentum
if (gMC.xm < -0x180) if (gMC.xm < -0x180)
@ -55,13 +53,13 @@ int JudgeHitMyCharBlock(int x, int y)
} }
// Right wall // Right wall
if (gMC.y - gMC.hit.top < (2 * (2 * y + 1) - 1) << 11 if (gMC.y - gMC.hit.top < (y * 0x10 + 4) * 0x200
&& gMC.y + gMC.hit.bottom > (2 * (2 * y - 1) + 1) << 11 && gMC.y + gMC.hit.bottom > (y * 0x10 - 4) * 0x200
&& gMC.x + gMC.hit.right > (2 * x - 1) << 12 && gMC.x + gMC.hit.right > (x * 0x10 - 8) * 0x200
&& gMC.x + gMC.hit.left < x << 13) && gMC.x + gMC.hit.left < x * 0x10 * 0x200)
{ {
// Clip // Clip
gMC.x = ((2 * x - 1) << 12) - gMC.hit.right; gMC.x = ((x * 0x10 - 8) * 0x200) - gMC.hit.right;
// Halt momentum // Halt momentum
if (gMC.xm > 0x180) if (gMC.xm > 0x180)
@ -74,13 +72,13 @@ int JudgeHitMyCharBlock(int x, int y)
} }
// Ceiling // Ceiling
if (gMC.x - gMC.hit.right < ((2 * x + 1) << 12) - 0x600 if (gMC.x - gMC.hit.right < (x * 0x10 + 5) * 0x200
&& gMC.x + gMC.hit.right > ((2 * x - 1) << 12) + 0x600 && gMC.x + gMC.hit.right > (x * 0x10 - 5) * 0x200
&& gMC.y - gMC.hit.top < (2 * y + 1) << 12 && gMC.y - gMC.hit.top < (y * 0x10 + 8) * 0x200
&& gMC.y - gMC.hit.top > y << 13) && gMC.y - gMC.hit.top > y * 0x10 * 0x200)
{ {
// Clip // Clip
gMC.y = ((2 * y + 1) << 12) + gMC.hit.top; gMC.y = ((y * 0x10 + 8) * 0x200) + gMC.hit.top;
// Halt momentum // Halt momentum
if (!(gMC.cond & 2) && gMC.ym < -0x200) if (!(gMC.cond & 2) && gMC.ym < -0x200)
@ -93,13 +91,13 @@ int JudgeHitMyCharBlock(int x, int y)
} }
// Floor // Floor
if (gMC.x - gMC.hit.right < ((2 * x + 1) << 12) - 0x600 if (gMC.x - gMC.hit.right < (x * 0x10 + 5) * 0x200
&& gMC.x + gMC.hit.right > ((2 * x - 1) << 12) + 0x600 && gMC.x + gMC.hit.right > ((x * 0x10 - 5) * 0x200)
&& gMC.y + gMC.hit.bottom > (2 * y - 1) << 12 && gMC.y + gMC.hit.bottom > (y * 0x10 - 8) * 0x200
&& gMC.y + gMC.hit.bottom < y << 13) && gMC.y + gMC.hit.bottom < y * 0x10 * 0x200)
{ {
// Clip // Clip
gMC.y = ((2 * y - 1) << 12) - gMC.hit.bottom; gMC.y = ((y * 0x10 - 8) * 0x200) - gMC.hit.bottom;
// Halt momentum // Halt momentum
if (gMC.ym > 0x400) if (gMC.ym > 0x400)
@ -118,13 +116,13 @@ int JudgeHitMyCharTriangleA(int x, int y)
{ {
int hit = 0; int hit = 0;
if (gMC.x < (2 * x + 1) << 12 if (gMC.x < (x * 0x10 + 8) * 0x200
&& gMC.x > (2 * x - 1) << 12 && gMC.x > (x * 0x10 - 8) * 0x200
&& gMC.y - gMC.hit.top < (y << 13) - (-0x2000 * x + gMC.x) / 2 + 0x800 && gMC.y - gMC.hit.top < (y * 0x10 * 0x200) - (gMC.x - x * 0x10 * 0x200) / 2 + 0x800
&& gMC.y + gMC.hit.bottom > (2 * y - 1) << 12) && gMC.y + gMC.hit.bottom > (y * 0x10 - 8) * 0x200)
{ {
// Clip // Clip
gMC.y = (y << 13) - (-0x2000 * x + gMC.x) / 2 + 0x800 + gMC.hit.top; gMC.y = (y * 0x10 * 0x200) - ((gMC.x - x * 0x10 * 0x200) / 2) + 0x800 + gMC.hit.top;
// Halt momentum // Halt momentum
if (!(gMC.cond & 2) && gMC.ym < -0x200) if (!(gMC.cond & 2) && gMC.ym < -0x200)
@ -143,13 +141,13 @@ int JudgeHitMyCharTriangleB(int x, int y)
{ {
int hit = 0; int hit = 0;
if (gMC.x < (2 * x + 1) << 12 if (gMC.x < (x * 0x10 + 8) * 0x200
&& gMC.x > (2 * x - 1) << 12 && gMC.x > (x * 0x10 - 8) * 0x200
&& gMC.y - gMC.hit.top < (y << 13) - (-0x2000 * x + gMC.x) / 2 - 0x800 && gMC.y - gMC.hit.top < (y * 0x10 * 0x200) - ((gMC.x - x * 0x10 * 0x200) / 2) - 0x800
&& gMC.y + gMC.hit.bottom > (2 * y - 1) << 12) && gMC.y + gMC.hit.bottom > (y * 0x10 - 8) * 0x200)
{ {
// Clip // Clip
gMC.y = (y << 13) - (-0x2000 * x + gMC.x) / 2 - 0x800 + gMC.hit.top; gMC.y = (y * 0x10 * 0x200) - ((gMC.x - x * 0x10 * 0x200) / 2) - 0x800 + gMC.hit.top;
// Halt momentum // Halt momentum
if (!(gMC.cond & 2) && gMC.ym < -0x200) if (!(gMC.cond & 2) && gMC.ym < -0x200)
@ -168,13 +166,13 @@ int JudgeHitMyCharTriangleC(int x, int y)
{ {
int hit = 0; int hit = 0;
if (gMC.x < (2 * x + 1) << 12 if (gMC.x < (x * 0x10 + 8) * 0x200
&& gMC.x > (2 * x - 1) << 12 && gMC.x > (x * 0x10 - 8) * 0x200
&& gMC.y - gMC.hit.top < (y << 13) + (-0x2000 * x + gMC.x) / 2 - 0x800 && gMC.y - gMC.hit.top < (y * 0x10 * 0x200) + ((gMC.x - x * 0x10 * 0x200) / 2) - 0x800
&& gMC.y + gMC.hit.bottom > (2 * y - 1) << 12) && gMC.y + gMC.hit.bottom > (y * 0x10 - 8) * 0x200)
{ {
// Clip // Clip
gMC.y = (y << 13) + (-0x2000 * x + gMC.x) / 2 - 0x800 + gMC.hit.top; gMC.y = (y * 0x10 * 0x200) + ((gMC.x - x * 0x10 * 0x200) / 2) - 0x800 + gMC.hit.top;
// Halt momentum // Halt momentum
if (!(gMC.cond & 2) && gMC.ym < -0x200) if (!(gMC.cond & 2) && gMC.ym < -0x200)
@ -193,13 +191,13 @@ int JudgeHitMyCharTriangleD(int x, int y)
{ {
int hit = 0; int hit = 0;
if (gMC.x < (2 * x + 1) << 12 if (gMC.x < (x * 0x10 + 8) * 0x200
&& gMC.x > (2 * x - 1) << 12 && gMC.x > (x * 0x10 - 8) * 0x200
&& gMC.y - gMC.hit.top < (y << 13) + (-0x2000 * x + gMC.x) / 2 + 0x800 && gMC.y - gMC.hit.top < (y * 0x10 * 0x200) + ((gMC.x - x * 0x10 * 0x200) / 2) + 0x800
&& gMC.y + gMC.hit.bottom > (2 * y - 1) << 12) && gMC.y + gMC.hit.bottom > (y * 0x10 - 8) * 0x200)
{ {
// Clip // Clip
gMC.y = (y << 13) + (-0x2000 * x + gMC.x) / 2 + 0x800 + gMC.hit.top; gMC.y = (y * 0x10 * 0x200) + ((gMC.x - x * 0x10 * 0x200) / 2) + 0x800 + gMC.hit.top;
// Halt momentum // Halt momentum
if (!(gMC.cond & 2) && gMC.ym < -0x200) if (!(gMC.cond & 2) && gMC.ym < -0x200)
@ -216,15 +214,17 @@ int JudgeHitMyCharTriangleD(int x, int y)
int JudgeHitMyCharTriangleE(int x, int y) int JudgeHitMyCharTriangleE(int x, int y)
{ {
int hit = 0x10000; int hit = 0;
if (gMC.x < (2 * x + 1) << 12 hit |= 0x10000;
&& gMC.x > (2 * x - 1) << 12
&& gMC.y + gMC.hit.bottom > (y << 13) + (-0x2000 * x + gMC.x) / 2 - 0x800 if (gMC.x < (x * 0x10 + 8) * 0x200
&& gMC.y - gMC.hit.top < (2 * y + 1) << 12) && gMC.x > (x * 0x10 - 8) * 0x200
&& gMC.y + gMC.hit.bottom > (y * 0x10 * 0x200) + ((gMC.x - x * 0x10 * 0x200) / 2) - 0x800
&& gMC.y - gMC.hit.top < (y * 0x10 + 8) * 0x200)
{ {
// Clip // Clip
gMC.y = (y << 13) + (-0x2000 * x + gMC.x) / 2 - 0x800 - gMC.hit.bottom; gMC.y = (y * 0x10 * 0x200) + ((gMC.x - x * 0x10 * 0x200) / 2) - 0x800 - gMC.hit.bottom;
// Halt momentum // Halt momentum
if (gMC.ym > 0x400) if (gMC.ym > 0x400)
@ -233,7 +233,7 @@ int JudgeHitMyCharTriangleE(int x, int y)
gMC.ym = 0; gMC.ym = 0;
// Set that hit this slope // Set that hit this slope
hit = 0x10028; hit |= 0x28;
} }
return hit; return hit;
@ -241,15 +241,17 @@ int JudgeHitMyCharTriangleE(int x, int y)
int JudgeHitMyCharTriangleF(int x, int y) int JudgeHitMyCharTriangleF(int x, int y)
{ {
int hit = 0x20000; int hit = 0;
if (gMC.x < (2 * x + 1) << 12 hit |= 0x20000;
&& gMC.x > (2 * x - 1) << 12
&& gMC.y + gMC.hit.bottom > (y << 13) + (-0x2000 * x + gMC.x) / 2 + 0x800 if (gMC.x < (x * 0x10 + 8) * 0x200
&& gMC.y - gMC.hit.top < (2 * y + 1) << 12) && gMC.x > (x * 0x10 - 8) * 0x200
&& gMC.y + gMC.hit.bottom > (y * 0x10 * 0x200) + ((gMC.x - x * 0x10 * 0x200) / 2) + 0x800
&& gMC.y - gMC.hit.top < (y * 0x10 + 8) * 0x200)
{ {
// Clip // Clip
gMC.y = (y << 13) + (-0x2000 * x + gMC.x) / 2 + 0x800 - gMC.hit.bottom; gMC.y = (y * 0x10 * 0x200) + ((gMC.x - x * 0x10 * 0x200) / 2) + 0x800 - gMC.hit.bottom;
// Halt momentum // Halt momentum
if (gMC.ym > 0x400) if (gMC.ym > 0x400)
@ -258,7 +260,7 @@ int JudgeHitMyCharTriangleF(int x, int y)
gMC.ym = 0; gMC.ym = 0;
// Set that hit this slope // Set that hit this slope
hit = 0x20028; hit |= 0x28;
} }
return hit; return hit;
@ -266,15 +268,17 @@ int JudgeHitMyCharTriangleF(int x, int y)
int JudgeHitMyCharTriangleG(int x, int y) int JudgeHitMyCharTriangleG(int x, int y)
{ {
int hit = 0x40000; int hit = 0;
if (gMC.x < (2 * x + 1) << 12 hit |= 0x40000;
&& gMC.x > (2 * x - 1) << 12
&& gMC.y + gMC.hit.bottom > (y << 13) - (-0x2000 * x + gMC.x) / 2 + 0x800 if (gMC.x < (x * 0x10 + 8) * 0x200
&& gMC.y - gMC.hit.top < (2 * y + 1) << 12) && gMC.x > (x * 0x10 - 8) * 0x200
&& gMC.y + gMC.hit.bottom > (y * 0x10 * 0x200) - ((gMC.x - x * 0x10 * 0x200) / 2) + 0x800
&& gMC.y - gMC.hit.top < (y * 0x10 + 8) * 0x200)
{ {
// Clip // Clip
gMC.y = (y << 13) - (-0x2000 * x + gMC.x) / 2 + 0x800 - gMC.hit.bottom; gMC.y = (y * 0x10 * 0x200) - ((gMC.x - x * 0x10 * 0x200) / 2) + 0x800 - gMC.hit.bottom;
// Halt momentum // Halt momentum
if (gMC.ym > 0x400) if (gMC.ym > 0x400)
@ -283,7 +287,7 @@ int JudgeHitMyCharTriangleG(int x, int y)
gMC.ym = 0; gMC.ym = 0;
// Set that hit this slope // Set that hit this slope
hit = 0x40018; hit |= 0x18;
} }
return hit; return hit;
@ -291,15 +295,17 @@ int JudgeHitMyCharTriangleG(int x, int y)
int JudgeHitMyCharTriangleH(int x, int y) int JudgeHitMyCharTriangleH(int x, int y)
{ {
int hit = 0x80000; int hit = 0;
if (gMC.x < (2 * x + 1) << 12 hit |= 0x80000;
&& gMC.x > (2 * x - 1) << 12
&& gMC.y + gMC.hit.bottom > (y << 13) - (-0x2000 * x + gMC.x) / 2 - 0x800 if (gMC.x < (x * 0x10 + 8) * 0x200
&& gMC.y - gMC.hit.top < (2 * y + 1) << 12) && gMC.x > (x * 0x10 - 8) * 0x200
&& gMC.y + gMC.hit.bottom > (y * 0x10 * 0x200) - ((gMC.x - x * 0x10 * 0x200) / 2) - 0x800
&& gMC.y - gMC.hit.top < (y * 0x10 + 8) * 0x200)
{ {
// Clip // Clip
gMC.y = (y << 13) - (-0x2000 * x + gMC.x) / 2 - 0x800 - gMC.hit.bottom; gMC.y = (y * 0x10 * 0x200) - ((gMC.x - x * 0x10 * 0x200) / 2) - 0x800 - gMC.hit.bottom;
// Halt momentum // Halt momentum
if (gMC.ym > 0x400) if (gMC.ym > 0x400)
@ -308,7 +314,7 @@ int JudgeHitMyCharTriangleH(int x, int y)
gMC.ym = 0; gMC.ym = 0;
// Set that hit this slope // Set that hit this slope
hit = 0x80018; hit |= 0x18;
} }
return hit; return hit;
@ -318,11 +324,11 @@ int JudgeHitMyCharWater(int x, int y)
{ {
int hit = 0; int hit = 0;
if (gMC.x - gMC.hit.right < ((2 * x + 1) << 12) - 0x600 if (gMC.x - gMC.hit.right < (x * 0x10 + 5) * 0x200
&& gMC.x + gMC.hit.right > ((2 * x - 1) << 12) + 0x600 && gMC.x + gMC.hit.right > ((x * 0x10 - 5) * 0x200)
&& gMC.y - gMC.hit.top < ((2 * y + 1) << 12) - 0x600 && gMC.y - gMC.hit.top < ((y * 0x10 + 5) * 0x200)
&& gMC.y + gMC.hit.bottom > y << 13) && gMC.y + gMC.hit.bottom > y * 0x10 * 0x200)
hit = 0x100; hit |= 0x100;
return hit; return hit;
} }
@ -331,11 +337,11 @@ int JudgeHitMyCharDamage(int x, int y)
{ {
int hit = 0; int hit = 0;
if (gMC.x - 0x800 < (4 * x + 1) << 11 if (gMC.x - 0x800 < (x * 0x10 + 4) * 0x200
&& gMC.x + 0x800 > (4 * x - 1) << 11 && gMC.x + 0x800 > (x * 0x10 - 4) * 0x200
&& gMC.y - 0x800 < (y << 13) + 0x600 && gMC.y - 0x800 < (y * 0x10 + 3) * 0x200
&& gMC.y + 0x800 > (y << 13) - 0x600) && gMC.y + 0x800 > (y * 0x10 - 3) * 0x200)
hit = 0x400; hit |= 0x400;
return hit; return hit;
} }
@ -344,11 +350,11 @@ int JudgeHitMyCharDamageW(int x, int y)
{ {
int hit = 0; int hit = 0;
if (gMC.x - 0x800 < (4 * x + 1) << 11 if (gMC.x - 0x800 < (x * 0x10 + 4) * 0x200
&& gMC.x + 0x800 > (4 * x - 1) << 11 && gMC.x + 0x800 > (x * 0x10 - 4) * 0x200
&& gMC.y - 0x800 < (y << 13) + 0x600 && gMC.y - 0x800 < (y * 0x10 + 3) * 0x200
&& gMC.y + 0x800 > (y << 13) - 0x600) && gMC.y + 0x800 > (y * 0x10 - 3) * 0x200)
hit = 0xD00; hit |= 0xD00;
return hit; return hit;
} }
@ -356,11 +362,11 @@ int JudgeHitMyCharDamageW(int x, int y)
int JudgeHitMyCharVectLeft(int x, int y) int JudgeHitMyCharVectLeft(int x, int y)
{ {
int hit = 0; int hit = 0;
if (gMC.x - gMC.hit.right < (4 * (2 * x + 1) - 1) << 10 if (gMC.x - gMC.hit.right < (x * 0x10 + 6) * 0x200
&& gMC.x + gMC.hit.right > (4 * (2 * x - 1) + 1) << 10 && gMC.x + gMC.hit.right > (x * 0x10 - 6) * 0x200
&& gMC.y - gMC.hit.top < (4 * (2 * y + 1) - 1) << 10 && gMC.y - gMC.hit.top < (y * 0x10 + 6) * 0x200
&& gMC.y + gMC.hit.bottom > (4 * (2 * y - 1) + 1) << 10) && gMC.y + gMC.hit.bottom > (y * 0x10 - 6) * 0x200)
hit = 0x1000; hit |= 0x1000;
return hit; return hit;
} }
@ -368,11 +374,11 @@ int JudgeHitMyCharVectLeft(int x, int y)
int JudgeHitMyCharVectUp(int x, int y) int JudgeHitMyCharVectUp(int x, int y)
{ {
int hit = 0; int hit = 0;
if (gMC.x - gMC.hit.right < (4 * (2 * x + 1) - 1) << 10 if (gMC.x - gMC.hit.right < (x * 0x10 + 6) * 0x200
&& gMC.x + gMC.hit.right > (4 * (2 * x - 1) + 1) << 10 && gMC.x + gMC.hit.right > (x * 0x10 - 6) * 0x200
&& gMC.y - gMC.hit.top < (4 * (2 * y + 1) - 1) << 10 && gMC.y - gMC.hit.top < (y * 0x10 + 6) * 0x200
&& gMC.y + gMC.hit.bottom > (4 * (2 * y - 1) + 1) << 10) && gMC.y + gMC.hit.bottom > (y * 0x10 - 6) * 0x200)
hit = 0x2000; hit |= 0x2000;
return hit; return hit;
} }
@ -380,11 +386,11 @@ int JudgeHitMyCharVectUp(int x, int y)
int JudgeHitMyCharVectRight(int x, int y) int JudgeHitMyCharVectRight(int x, int y)
{ {
int hit = 0; int hit = 0;
if (gMC.x - gMC.hit.right < (4 * (2 * x + 1) - 1) << 10 if (gMC.x - gMC.hit.right < (x * 0x10 + 6) * 0x200
&& gMC.x + gMC.hit.right > (4 * (2 * x - 1) + 1) << 10 && gMC.x + gMC.hit.right > (x * 0x10 - 6) * 0x200
&& gMC.y - gMC.hit.top < (4 * (2 * y + 1) - 1) << 10 && gMC.y - gMC.hit.top < (y * 0x10 + 6) * 0x200
&& gMC.y + gMC.hit.bottom > (4 * (2 * y - 1) + 1) << 10) && gMC.y + gMC.hit.bottom > (y * 0x10 - 6) * 0x200)
hit = 0x4000; hit |= 0x4000;
return hit; return hit;
} }
@ -392,43 +398,42 @@ int JudgeHitMyCharVectRight(int x, int y)
int JudgeHitMyCharVectDown(int x, int y) int JudgeHitMyCharVectDown(int x, int y)
{ {
int hit = 0; int hit = 0;
if (gMC.x - gMC.hit.right < (4 * (2 * x + 1) - 1) << 10 if (gMC.x - gMC.hit.right < (x * 0x10 + 6) * 0x200
&& gMC.x + gMC.hit.right > (4 * (2 * x - 1) + 1) << 10 && gMC.x + gMC.hit.right > (x * 0x10 - 6) * 0x200
&& gMC.y - gMC.hit.top < (4 * (2 * y + 1) - 1) << 10 && gMC.y - gMC.hit.top < (y * 0x10 + 6) * 0x200
&& gMC.y + gMC.hit.bottom > (4 * (2 * y - 1) + 1) << 10) && gMC.y + gMC.hit.bottom > (y * 0x10 - 6) * 0x200)
hit = 0x8000; hit |= 0x8000;
return hit; return hit;
} }
void HitMyCharMap() void HitMyCharMap()
{ {
int x = gMC.x / 0x2000; int i;
int y = gMC.y / 0x2000;
int x = gMC.x / 0x10 / 0x200;
int y = gMC.y / 0x10 / 0x200;
int offy[4];
int offx[4]; int offx[4];
int offy[4];
offx[0] = 0; offx[0] = 0;
offx[1] = 1; offx[1] = 1;
offx[2] = 0; offx[2] = 0;
offx[3] = 1; offx[3] = 1;
offy[0] = 0; offy[0] = 0;
offy[1] = 0; offy[1] = 0;
offy[2] = 1; offy[2] = 1;
offy[3] = 1; offy[3] = 1;
uint8_t atrb[4]; unsigned char atrb[4];
for (int i = 0; i < 4; i++) for (i = 0; i < 4; i++)
{ {
atrb[i] = GetAttribute(x + offx[i], y + offy[i]); atrb[i] = GetAttribute(x + offx[i], y + offy[i]);
switch (atrb[i]) switch (atrb[i])
{ {
// Water
case 0x02:
gMC.flag |= JudgeHitMyCharWater(x + offx[i], y + offy[i]);
break;
// Block // Block
case 0x05: case 0x05:
case 0x41: case 0x41:
@ -437,11 +442,6 @@ void HitMyCharMap()
gMC.flag |= JudgeHitMyCharBlock(x + offx[i], y + offy[i]); gMC.flag |= JudgeHitMyCharBlock(x + offx[i], y + offy[i]);
break; break;
// Spikes
case 0x42:
gMC.flag |= JudgeHitMyCharDamage(x + offx[i], y + offy[i]);
break;
// Slopes // Slopes
case 0x50: case 0x50:
gMC.flag |= JudgeHitMyCharTriangleA(x + offx[i], y + offy[i]); gMC.flag |= JudgeHitMyCharTriangleA(x + offx[i], y + offy[i]);
@ -475,6 +475,38 @@ void HitMyCharMap()
gMC.flag |= JudgeHitMyCharTriangleH(x + offx[i], y + offy[i]); gMC.flag |= JudgeHitMyCharTriangleH(x + offx[i], y + offy[i]);
break; break;
// Spikes
case 0x42:
gMC.flag |= JudgeHitMyCharDamage(x + offx[i], y + offy[i]);
break;
// Water spikes
case 0x62:
gMC.flag |= JudgeHitMyCharDamageW(x + offx[i], y + offy[i]);
break;
// Wind
case 0x80:
gMC.flag |= JudgeHitMyCharVectLeft(x + offx[i], y + offy[i]);
break;
case 0x81:
gMC.flag |= JudgeHitMyCharVectUp(x + offx[i], y + offy[i]);
break;
case 0x82:
gMC.flag |= JudgeHitMyCharVectRight(x + offx[i], y + offy[i]);
break;
case 0x83:
gMC.flag |= JudgeHitMyCharVectDown(x + offx[i], y + offy[i]);
break;
// Water
case 0x02:
gMC.flag |= JudgeHitMyCharWater(x + offx[i], y + offy[i]);
break;
// Water and water blocks // Water and water blocks
case 0x60: case 0x60:
gMC.flag |= JudgeHitMyCharWater(x + offx[i], y + offy[i]); gMC.flag |= JudgeHitMyCharWater(x + offx[i], y + offy[i]);
@ -485,11 +517,6 @@ void HitMyCharMap()
gMC.flag |= JudgeHitMyCharWater(x + offx[i], y + offy[i]); gMC.flag |= JudgeHitMyCharWater(x + offx[i], y + offy[i]);
break; break;
// Water spikes
case 0x62:
gMC.flag |= JudgeHitMyCharDamageW(x + offx[i], y + offy[i]);
break;
// Water slopes // Water slopes
case 0x70: case 0x70:
gMC.flag |= JudgeHitMyCharTriangleA(x + offx[i], y + offy[i]); gMC.flag |= JudgeHitMyCharTriangleA(x + offx[i], y + offy[i]);
@ -531,23 +558,6 @@ void HitMyCharMap()
gMC.flag |= JudgeHitMyCharWater(x + offx[i], y + offy[i]); gMC.flag |= JudgeHitMyCharWater(x + offx[i], y + offy[i]);
break; break;
// Wind
case 0x80:
gMC.flag |= JudgeHitMyCharVectLeft(x + offx[i], y + offy[i]);
break;
case 0x81:
gMC.flag |= JudgeHitMyCharVectUp(x + offx[i], y + offy[i]);
break;
case 0x82:
gMC.flag |= JudgeHitMyCharVectRight(x + offx[i], y + offy[i]);
break;
case 0x83:
gMC.flag |= JudgeHitMyCharVectDown(x + offx[i], y + offy[i]);
break;
// Water current // Water current
case 0xA0: case 0xA0:
gMC.flag |= JudgeHitMyCharVectLeft(x + offx[i], y + offy[i]); gMC.flag |= JudgeHitMyCharVectLeft(x + offx[i], y + offy[i]);
@ -568,9 +578,6 @@ void HitMyCharMap()
gMC.flag |= JudgeHitMyCharVectDown(x + offx[i], y + offy[i]); gMC.flag |= JudgeHitMyCharVectDown(x + offx[i], y + offy[i]);
gMC.flag |= JudgeHitMyCharWater(x + offx[i], y + offy[i]); gMC.flag |= JudgeHitMyCharWater(x + offx[i], y + offy[i]);
break; break;
default:
break;
} }
} }
@ -633,20 +640,20 @@ int JudgeHitMyCharNPC(NPCHAR *npc)
return hit; return hit;
} }
int JudgeHitMyCharNPC3(NPCHAR *npc) unsigned char JudgeHitMyCharNPC3(NPCHAR *npc)
{ {
if (npc->direct) if (npc->direct == 0)
{ {
if (gMC.x + 0x400 > npc->x - npc->hit.back if (gMC.x + 0x400 > npc->x - npc->hit.front
&& gMC.x - 0x400 < npc->x + npc->hit.front && gMC.x - 0x400 < npc->x + npc->hit.back
&& gMC.y + 0x400 > npc->y - npc->hit.top && gMC.y + 0x400 > npc->y - npc->hit.top
&& gMC.y - 0x400 < npc->y + npc->hit.bottom) && gMC.y - 0x400 < npc->y + npc->hit.bottom)
return 1; return 1;
} }
else else
{ {
if (gMC.x + 0x400 > npc->x - npc->hit.front if (gMC.x + 0x400 > npc->x - npc->hit.back
&& gMC.x - 0x400 < npc->x + npc->hit.back && gMC.x - 0x400 < npc->x + npc->hit.front
&& gMC.y + 0x400 > npc->y - npc->hit.top && gMC.y + 0x400 > npc->y - npc->hit.top
&& gMC.y - 0x400 < npc->y + npc->hit.bottom) && gMC.y - 0x400 < npc->y + npc->hit.bottom)
return 1; return 1;
@ -658,65 +665,47 @@ int JudgeHitMyCharNPC3(NPCHAR *npc)
int JudgeHitMyCharNPC4(NPCHAR *npc) int JudgeHitMyCharNPC4(NPCHAR *npc)
{ {
// TODO: comment this // TODO: comment this
float fx1;
float fx2;
float fy1;
float fy2;
int hit = 0; int hit = 0;
long double v1, v2;
if (npc->x <= gMC.x) if (npc->x > gMC.x)
v1 = (long double)(gMC.x - npc->x); fx1 = (float)(npc->x - gMC.x);
else else
v1 = (long double)(npc->x - gMC.x); fx1 = (float)(gMC.x - npc->x);
float fx1 = (float)v1; if (npc->y > gMC.y)
fy1 = (float)(npc->y - gMC.y);
if (npc->y <= gMC.y)
v2 = (long double)(gMC.y - npc->y);
else else
v2 = (long double)(npc->y - gMC.y); fy1 = (float)(gMC.y - npc->y);
float fx2 = (float)npc->hit.back; fx2 = (float)npc->hit.back;
if (0.0 == fx1) fy2 = (float)npc->hit.top;
fx1 = 1.0;
if (0.0 == fx2)
fx2 = 1.0;
float fy1 = (float)v2; if (fx1 == 0.0f)
float fy2 = (float)npc->hit.top; fx1 = 1.0f;
if (fx2 == 0.0f)
fx2 = 1.0f;
if (fy1 / fx1 <= fy2 / fx2) if (fy1 / fx1 > fy2 / fx2)
{ {
if (gMC.y - gMC.hit.top < npc->y + npc->hit.bottom && gMC.y + gMC.hit.bottom > npc->y - npc->hit.top) if (gMC.x - gMC.hit.right < npc->x + npc->hit.back && gMC.x + gMC.hit.right > npc->x - npc->hit.back)
{
if (gMC.x - gMC.hit.right < npc->x + npc->hit.back && gMC.x - gMC.hit.right > npc->x)
{
if (gMC.xm < npc->xm)
gMC.xm = npc->xm;
gMC.x = npc->hit.back + npc->x + gMC.hit.right;
hit |= 1;
}
if (gMC.x + gMC.hit.right > npc->x - npc->hit.back && gMC.hit.right + gMC.x < npc->x)
{
if (gMC.xm > npc->xm)
gMC.xm = npc->xm;
gMC.x = npc->x - npc->hit.back - gMC.hit.right;
hit |= 4;
}
}
}
else if (gMC.x - gMC.hit.right < npc->x + npc->hit.back && gMC.x + gMC.hit.right > npc->x - npc->hit.back)
{ {
if (gMC.y - gMC.hit.top < npc->y + npc->hit.bottom && gMC.y - gMC.hit.top > npc->y) if (gMC.y - gMC.hit.top < npc->y + npc->hit.bottom && gMC.y - gMC.hit.top > npc->y)
{ {
if (gMC.ym >= npc->ym) if (gMC.ym < npc->ym)
{
if (gMC.ym < 0)
gMC.ym = 0;
}
else
{ {
gMC.y = npc->hit.bottom + npc->y + gMC.hit.top + 0x200; gMC.y = npc->hit.bottom + npc->y + gMC.hit.top + 0x200;
gMC.ym = npc->ym; gMC.ym = npc->ym;
} }
else
{
if (gMC.ym < 0)
gMC.ym = 0;
}
hit |= 2; hit |= 2;
} }
@ -745,20 +734,52 @@ int JudgeHitMyCharNPC4(NPCHAR *npc)
} }
} }
} }
}
else
{
if (gMC.y - gMC.hit.top < npc->y + npc->hit.bottom && gMC.y + gMC.hit.bottom > npc->y - npc->hit.top)
{
if (gMC.x - gMC.hit.right < npc->x + npc->hit.back && gMC.x - gMC.hit.right > npc->x)
{
if (gMC.xm < npc->xm)
gMC.xm = npc->xm;
gMC.x = npc->hit.back + npc->x + gMC.hit.right;
hit |= 1;
}
if (gMC.x + gMC.hit.right > npc->x - npc->hit.back && gMC.hit.right + gMC.x < npc->x)
{
if (gMC.xm > npc->xm)
gMC.xm = npc->xm;
gMC.x = npc->x - npc->hit.back - gMC.hit.right;
hit |= 4;
}
}
}
return hit; return hit;
} }
void HitMyCharNpChar() void HitMyCharNpChar()
{ {
if ((gMC.cond & 0x80) && !(gMC.cond & 2)) int i;
{
int hit;
for (int i = 0; i < NPC_MAX; i++) int hit = 0;
{
if (gNPC[i].cond & 0x80) if ((gMC.cond & 0x80) == 0 || (gMC.cond & 2))
return;
for (i = 0; i < NPC_MAX; i++)
{ {
if ((gNPC[i].cond & 0x80) == 0)
continue;
hit = 0;
if (gNPC[i].bits & npc_solidSoft) if (gNPC[i].bits & npc_solidSoft)
{ {
hit = JudgeHitMyCharNPC(&gNPC[i]); hit = JudgeHitMyCharNPC(&gNPC[i]);
@ -797,11 +818,11 @@ void HitMyCharNpChar()
} }
// Run event on contact // Run event on contact
if (!(g_GameFlags & 4) && hit && gNPC[i].bits & npc_eventTouch) if ((g_GameFlags & 4) == 0 && hit && gNPC[i].bits & npc_eventTouch)
StartTextScript(gNPC[i].code_event); StartTextScript(gNPC[i].code_event);
// NPC damage // NPC damage
if (g_GameFlags & 2 && !(gNPC[i].bits & npc_interact)) if (g_GameFlags & 2 && (gNPC[i].bits & npc_interact) == 0)
{ {
if (gNPC[i].bits & npc_rearTop) if (gNPC[i].bits & npc_rearTop)
{ {
@ -821,30 +842,33 @@ void HitMyCharNpChar()
} }
// Interaction // Interaction
if (!(g_GameFlags & 4) && hit && gMC.cond & 1 && gNPC[i].bits & npc_interact) if ((g_GameFlags & 4) == 0 && hit && gMC.cond & 1 && gNPC[i].bits & npc_interact)
{ {
StartTextScript(gNPC[i].code_event); StartTextScript(gNPC[i].code_event);
gMC.xm = 0; gMC.xm = 0;
gMC.ques = 0; gMC.ques = 0;
} }
} }
}
// Create question mark when NPC hasn't been interacted with // Create question mark when NPC hasn't been interacted with
if (gMC.ques) if (gMC.ques)
SetCaret(gMC.x, gMC.y, 9, 0); SetCaret(gMC.x, gMC.y, 9, 0);
} }
}
void HitMyCharBoss() void HitMyCharBoss()
{ {
if ((gMC.cond & 0x80) && !(gMC.cond & 2)) int hit = 0;
{
if ((gMC.cond & 0x80) == 0 || (gMC.cond & 2))
return;
for (int b = 0; b < BOSS_MAX; b++) for (int b = 0; b < BOSS_MAX; b++)
{ {
if (gBoss[b].cond & 0x80) if ((gBoss[b].cond & 0x80) == 0)
{ continue;
int hit;
hit = 0;
if (gBoss[b].bits & npc_solidSoft) if (gBoss[b].bits & npc_solidSoft)
{ {
hit = JudgeHitMyCharNPC(&gBoss[b]); hit = JudgeHitMyCharNPC(&gBoss[b]);
@ -885,9 +909,7 @@ void HitMyCharBoss()
gMC.ques = 0; gMC.ques = 0;
} }
} }
}
if (gMC.ques) if (gMC.ques)
SetCaret(gMC.x, gMC.y, 9, 0); SetCaret(gMC.x, gMC.y, 9, 0);
} }
}

View file

@ -1,7 +1,5 @@
#pragma once #pragma once
#include <stdint.h>
#include "WindowsWrapper.h" #include "WindowsWrapper.h"
struct ARMS_LEVEL struct ARMS_LEVEL
@ -11,8 +9,8 @@ struct ARMS_LEVEL
struct REC struct REC
{ {
int32_t counter[4]; long counter[4];
uint8_t random[4]; unsigned char random[4];
}; };
extern ARMS_LEVEL gArmsLevelTable[14]; extern ARMS_LEVEL gArmsLevelTable[14];

View file

@ -1,7 +1,6 @@
#include "NpChar.h" #include "NpChar.h"
#include <stddef.h> #include <stddef.h>
#include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
@ -27,7 +26,7 @@ int gCurlyShoot_y;
int gSuperXpos; int gSuperXpos;
int gSuperYpos; int gSuperYpos;
const char *gPassPixEve = "PXE\0"; const char *gPassPixEve = "PXE";
void InitNpChar() void InitNpChar()
{ {
@ -55,10 +54,16 @@ void SetUniqueParameter(NPCHAR *npc)
BOOL LoadEvent(const char *path_event) BOOL LoadEvent(const char *path_event)
{ {
FILE *fp;
int count;
int i;
int n;
EVENT eve;
char path[PATH_LENGTH]; char path[PATH_LENGTH];
sprintf(path, "%s/%s", gDataPath, path_event); sprintf(path, "%s/%s", gDataPath, path_event);
FILE *fp = fopen(path, "rb"); fp = fopen(path, "rb");
if (fp == NULL) if (fp == NULL)
return FALSE; return FALSE;
@ -75,33 +80,37 @@ BOOL LoadEvent(const char *path_event)
} }
//Get amount of NPCs //Get amount of NPCs
int count = File_ReadLE32(fp); #ifdef NONPORTABLE
fread(&count, 4, 1, fp);
#else
count = File_ReadLE32(fp);
#endif
//Load NPCs //Load NPCs
memset(gNPC, 0, sizeof(gNPC)); memset(gNPC, 0, sizeof(gNPC));
int n = 170; n = 170;
for (int i = 0; i < count; i++) for (i = 0; i < count; i++)
{ {
//Get data from file //Get data from file
EVENT eve; #ifdef NONPORTABLE
fread(&eve, sizeof(EVENT), 1, fp);
#else
eve.x = File_ReadLE16(fp); eve.x = File_ReadLE16(fp);
eve.y = File_ReadLE16(fp); eve.y = File_ReadLE16(fp);
eve.code_flag = File_ReadLE16(fp); eve.code_flag = File_ReadLE16(fp);
eve.code_event = File_ReadLE16(fp); eve.code_event = File_ReadLE16(fp);
eve.code_char = File_ReadLE16(fp); eve.code_char = File_ReadLE16(fp);
eve.bits = File_ReadLE16(fp); eve.bits = File_ReadLE16(fp);
#endif
//Set NPC parameters //Set NPC parameters
if (eve.bits & npc_altDir) gNPC[n].direct = (eve.bits & npc_altDir) ? 2 : 0;
gNPC[n].direct = 2;
else
gNPC[n].direct = 0;
gNPC[n].code_char = eve.code_char; gNPC[n].code_char = eve.code_char;
gNPC[n].code_event = eve.code_event; gNPC[n].code_event = eve.code_event;
gNPC[n].code_flag = eve.code_flag; gNPC[n].code_flag = eve.code_flag;
gNPC[n].x = eve.x << 13; gNPC[n].x = eve.x * 0x10 * 0x200;
gNPC[n].y = eve.y << 13; gNPC[n].y = eve.y * 0x10 * 0x200;
gNPC[n].bits = eve.bits; gNPC[n].bits = eve.bits;
gNPC[n].bits |= gNpcTable[gNPC[n].code_char].bits; gNPC[n].bits |= gNpcTable[gNPC[n].code_char].bits;
gNPC[n].exp = gNpcTable[gNPC[n].code_char].exp; gNPC[n].exp = gNpcTable[gNPC[n].code_char].exp;
@ -110,13 +119,13 @@ BOOL LoadEvent(const char *path_event)
//Check flags //Check flags
if (gNPC[n].bits & npc_appearSet) if (gNPC[n].bits & npc_appearSet)
{ {
if (GetNPCFlag(gNPC[n].code_flag)) if (GetNPCFlag(gNPC[n].code_flag) == TRUE)
gNPC[n].cond |= 0x80u; gNPC[n].cond |= 0x80;
} }
else if (gNPC[n].bits & npc_hideSet) else if (gNPC[n].bits & npc_hideSet)
{ {
if (!GetNPCFlag(gNPC[n].code_flag)) if (GetNPCFlag(gNPC[n].code_flag) == FALSE)
gNPC[n].cond |= 0x80u; gNPC[n].cond |= 0x80;
} }
else else
{ {
@ -133,10 +142,13 @@ BOOL LoadEvent(const char *path_event)
void SetNpChar(int code_char, int x, int y, int xm, int ym, int dir, NPCHAR *npc, int start_index) void SetNpChar(int code_char, int x, int y, int xm, int ym, int dir, NPCHAR *npc, int start_index)
{ {
for (int n = start_index; n < NPC_MAX; n++) int n = start_index;
{ while (n < NPC_MAX && gNPC[n].cond)
if (!gNPC[n].cond) ++n;
{
if (n == NPC_MAX)
return;
//Set NPC parameters //Set NPC parameters
memset(&gNPC[n], 0, sizeof(NPCHAR)); memset(&gNPC[n], 0, sizeof(NPCHAR));
gNPC[n].cond |= 0x80u; gNPC[n].cond |= 0x80u;
@ -150,20 +162,17 @@ void SetNpChar(int code_char, int x, int y, int xm, int ym, int dir, NPCHAR *npc
gNPC[n].bits = gNpcTable[gNPC[n].code_char].bits; gNPC[n].bits = gNpcTable[gNPC[n].code_char].bits;
gNPC[n].exp = gNpcTable[gNPC[n].code_char].exp; gNPC[n].exp = gNpcTable[gNPC[n].code_char].exp;
SetUniqueParameter(&gNPC[n]); SetUniqueParameter(&gNPC[n]);
break;
}
}
} }
void SetDestroyNpChar(int x, int y, int w, int num) void SetDestroyNpChar(int x, int y, int w, int num)
{ {
//Create smoke //Create smoke
int wa = w / 0x200; w /= 0x200;
for (int i = 0; i < num; i++) for (int i = 0; i < num; i++)
{ {
int offset_x = Random(-wa, wa) << 9; int offset_x = Random(-w, w) * 0x200;
int offset_y = Random(-wa, wa) << 9; int offset_y = Random(-w, w) * 0x200;
SetNpChar(4, x + offset_x, offset_y + y, 0, 0, 0, NULL, 0x100); SetNpChar(4, x + offset_x, y + offset_y, 0, 0, 0, NULL, 0x100);
} }
//Flash effect //Flash effect
@ -173,12 +182,12 @@ void SetDestroyNpChar(int x, int y, int w, int num)
void SetDestroyNpCharUp(int x, int y, int w, int num) void SetDestroyNpCharUp(int x, int y, int w, int num)
{ {
//Create smoke //Create smoke
int wa = w / 0x200; w /= 0x200;
for (int i = 0; i < num; i++) for (int i = 0; i < num; i++)
{ {
int offset_x = Random(-wa, wa) << 9; int offset_x = Random(-w, w) * 0x200;
int offset_y = Random(-wa, wa) << 9; int offset_y = Random(-w, w) * 0x200;
SetNpChar(4, x + offset_x, offset_y + y, 0, 0, 1, NULL, 0x100); SetNpChar(4, x + offset_x, y + offset_y, 0, 0, 1, NULL, 0x100);
} }
//Flash effect //Flash effect
@ -188,82 +197,83 @@ void SetDestroyNpCharUp(int x, int y, int w, int num)
void SetExpObjects(int x, int y, int exp) void SetExpObjects(int x, int y, int exp)
{ {
int sub_exp; int sub_exp;
for (int n = 0x100; exp; SetUniqueParameter(&gNPC[n])) int n = 0x100;
while (exp)
{ {
while (true) while (n < NPC_MAX && gNPC[n].cond)
{
bool v3 = n < NPC_MAX && gNPC[n].cond;
if (!v3)
break;
++n; ++n;
}
if (n == NPC_MAX) if (n == NPC_MAX)
break; break;
memset(&gNPC[n], 0, sizeof(NPCHAR)); memset(&gNPC[n], 0, sizeof(NPCHAR));
if (exp < 20) if (exp >= 20)
{
if (exp < 5)
{
if (exp > 0)
{
--exp;
sub_exp = 1;
}
}
else
{
exp -= 5;
sub_exp = 5;
}
}
else
{ {
exp -= 20; exp -= 20;
sub_exp = 20; sub_exp = 20;
} }
else if (exp >= 5)
{
exp -= 5;
sub_exp = 5;
}
else if (exp >= 1)
{
exp -= 1;
sub_exp = 1;
}
gNPC[n].cond |= 0x80u; gNPC[n].cond |= 0x80;
gNPC[n].direct = 0; gNPC[n].direct = 0;
gNPC[n].code_char = 1; gNPC[n].code_char = 1;
gNPC[n].x = x; gNPC[n].x = x;
gNPC[n].y = y; gNPC[n].y = y;
gNPC[n].bits = gNpcTable[gNPC[n].code_char].bits; gNPC[n].bits = gNpcTable[gNPC[n].code_char].bits;
gNPC[n].exp = sub_exp; gNPC[n].exp = sub_exp;
SetUniqueParameter(&gNPC[n]);
} }
} }
BOOL SetBulletObject(int x, int y, int val) BOOL SetBulletObject(int x, int y, int val)
{ {
int tamakazu_ari[10];
int n;
int t = 0; int t = 0;
int bullet_no;
int tamakazu_ari[10];
int n;
memset(tamakazu_ari, 0, sizeof(tamakazu_ari)); memset(tamakazu_ari, 0, sizeof(tamakazu_ari));
for (n = 0; n < 8; n++) for (n = 0; n < 8; ++n)
{ {
int code = gArmsData[n].code; switch (gArmsData[n].code)
if (code == 5) {
case 5:
tamakazu_ari[t++] = 0; tamakazu_ari[t++] = 0;
else if (code == 10) break;
case 10:
tamakazu_ari[t++] = 1; tamakazu_ari[t++] = 1;
else break;
default:
tamakazu_ari[t] = 0; tamakazu_ari[t] = 0;
break;
}
} }
if (!t) if (t == 0)
return FALSE; return FALSE;
n = Random(1, 10 * t); n = Random(1, 10 * t);
int bullet_no = tamakazu_ari[n % t]; bullet_no = tamakazu_ari[n % t];
for (n = 0x100; n < NPC_MAX; n++) n = 0x100;
{ while (n < NPC_MAX && gNPC[n].cond)
if (!gNPC[n].cond) ++n;
{
if (n == NPC_MAX)
return FALSE;
memset(&gNPC[n], 0, sizeof(NPCHAR)); memset(&gNPC[n], 0, sizeof(NPCHAR));
gNPC[n].cond |= 0x80u; gNPC[n].cond |= 0x80;
gNPC[n].direct = 0; gNPC[n].direct = 0;
gNPC[n].code_event = bullet_no; gNPC[n].code_event = bullet_no;
gNPC[n].code_char = 86; gNPC[n].code_char = 86;
@ -274,19 +284,18 @@ BOOL SetBulletObject(int x, int y, int val)
SetUniqueParameter(&gNPC[n]); SetUniqueParameter(&gNPC[n]);
return TRUE; return TRUE;
} }
}
return FALSE;
}
BOOL SetLifeObject(int x, int y, int val) BOOL SetLifeObject(int x, int y, int val)
{ {
for (int n = 0x100; n < NPC_MAX; n++) int n = 0x100;
{ while (n < NPC_MAX && gNPC[n].cond)
if (!gNPC[n].cond) ++n;
{
if (n == NPC_MAX)
return FALSE;
memset(&gNPC[n], 0, sizeof(NPCHAR)); memset(&gNPC[n], 0, sizeof(NPCHAR));
gNPC[n].cond |= 0x80u; gNPC[n].cond |= 0x80;
gNPC[n].direct = 0; gNPC[n].direct = 0;
gNPC[n].code_char = 87; gNPC[n].code_char = 87;
gNPC[n].x = x; gNPC[n].x = x;
@ -296,10 +305,6 @@ BOOL SetLifeObject(int x, int y, int val)
SetUniqueParameter(&gNPC[n]); SetUniqueParameter(&gNPC[n]);
return TRUE; return TRUE;
} }
}
return FALSE;
}
void VanishNpChar(NPCHAR *npc) void VanishNpChar(NPCHAR *npc)
{ {
@ -309,7 +314,7 @@ void VanishNpChar(NPCHAR *npc)
npc->count1 = 0; npc->count1 = 0;
npc->x = x; npc->x = x;
npc->y = y; npc->y = y;
npc->cond |= 0x80u; npc->cond |= 0x80;
npc->direct = 0; npc->direct = 0;
npc->code_char = 3; npc->code_char = 3;
npc->bits = gNpcTable[npc->code_char].bits; npc->bits = gNpcTable[npc->code_char].bits;
@ -319,15 +324,15 @@ void VanishNpChar(NPCHAR *npc)
void PutNpChar(int fx, int fy) void PutNpChar(int fx, int fy)
{ {
for (int n = 0; n < NPC_MAX; n++) signed char a = 0;
for (int n = 0; n < NPC_MAX; ++n)
{ {
if (gNPC[n].cond & 0x80) if (gNPC[n].cond & 0x80)
{ {
int8_t a;
if (gNPC[n].shock) if (gNPC[n].shock)
{ {
a = 2 * ((gNPC[n].shock >> 1) & 1) - 1; a = 2 * ((gNPC[n].shock / 2) % 2) - 1;
} }
else else
{ {
@ -340,10 +345,10 @@ void PutNpChar(int fx, int fy)
} }
int side; int side;
if (gNPC[n].direct) if (gNPC[n].direct == 0)
side = gNPC[n].view.back;
else
side = gNPC[n].view.front; side = gNPC[n].view.front;
else
side = gNPC[n].view.back;
PutBitmap3( PutBitmap3(
&grcGame, &grcGame,
@ -357,11 +362,13 @@ void PutNpChar(int fx, int fy)
void ActNpChar() void ActNpChar()
{ {
for (int i = 0; i < NPC_MAX; i++) for (int i = 0; i < NPC_MAX; ++i)
{ {
if (gNPC[i].cond & 0x80) if (gNPC[i].cond & 0x80)
{ {
gpNpcFuncTbl[gNPC[i].code_char](&gNPC[i]); int code_char = gNPC[i].code_char;
gpNpcFuncTbl[code_char](&gNPC[i]);
if (gNPC[i].shock) if (gNPC[i].shock)
--gNPC[i].shock; --gNPC[i].shock;
@ -373,14 +380,14 @@ void ChangeNpCharByEvent(int code_event, int code_char, int dir)
{ {
for (int n = 0; n < NPC_MAX; n++) for (int n = 0; n < NPC_MAX; n++)
{ {
if ((gNPC[n].cond & 0x80u) && gNPC[n].code_event == code_event) if ((gNPC[n].cond & 0x80) && gNPC[n].code_event == code_event)
{ {
gNPC[n].bits &= (npc_eventTouch | npc_eventDie | 0x400 | npc_appearSet | npc_altDir | npc_interact | npc_hideSet); gNPC[n].bits &= (npc_eventTouch | npc_eventDie | 0x400 | npc_appearSet | npc_altDir | npc_interact | npc_hideSet);
gNPC[n].code_char = code_char; gNPC[n].code_char = code_char;
gNPC[n].bits |= gNpcTable[gNPC[n].code_char].bits; gNPC[n].bits |= gNpcTable[gNPC[n].code_char].bits;
gNPC[n].exp = gNpcTable[gNPC[n].code_char].exp; gNPC[n].exp = gNpcTable[gNPC[n].code_char].exp;
SetUniqueParameter(&gNPC[n]); SetUniqueParameter(&gNPC[n]);
gNPC[n].cond |= 0x80u; gNPC[n].cond |= 0x80;
gNPC[n].act_no = 0; gNPC[n].act_no = 0;
gNPC[n].act_wait = 0; gNPC[n].act_wait = 0;
gNPC[n].count1 = 0; gNPC[n].count1 = 0;
@ -390,20 +397,21 @@ void ChangeNpCharByEvent(int code_event, int code_char, int dir)
gNPC[n].xm = 0; gNPC[n].xm = 0;
gNPC[n].ym = 0; gNPC[n].ym = 0;
if (dir != 5) if (dir == 5)
{ {
if (dir == 4) // Another empty case that has to exist for the same assembly to be generated
}
else if (dir == 4)
{ {
if (gNPC[n].x >= gMC.x) if (gNPC[n].x < gMC.x)
gNPC[n].direct = 0;
else
gNPC[n].direct = 2; gNPC[n].direct = 2;
else
gNPC[n].direct = 0;
} }
else else
{ {
gNPC[n].direct = dir; gNPC[n].direct = dir;
} }
}
gpNpcFuncTbl[code_char](&gNPC[n]); gpNpcFuncTbl[code_char](&gNPC[n]);
} }
@ -414,15 +422,15 @@ void ChangeCheckableNpCharByEvent(int code_event, int code_char, int dir)
{ {
for (int n = 0; n < NPC_MAX; n++) for (int n = 0; n < NPC_MAX; n++)
{ {
if ((gNPC[n].cond & 0x80u) != 0 && gNPC[n].code_event == code_event) if ((gNPC[n].cond & 0x80) != 0 && gNPC[n].code_event == code_event)
{ {
gNPC[n].bits &= (npc_eventTouch | npc_eventDie | 0x400 | npc_appearSet | npc_altDir | npc_interact | npc_hideSet); gNPC[n].bits &= ~(npc_showDamage | npc_rearTop | npc_solidHard | npc_shootable | npc_bouncy | npc_ignoreSolid | npc_invulnerable | npc_ignore44 | npc_solidSoft);
gNPC[n].bits |= npc_interact; gNPC[n].bits |= npc_interact;
gNPC[n].code_char = code_char; gNPC[n].code_char = code_char;
gNPC[n].bits |= gNpcTable[gNPC[n].code_char].bits; gNPC[n].bits |= gNpcTable[gNPC[n].code_char].bits;
gNPC[n].exp = gNpcTable[gNPC[n].code_char].exp; gNPC[n].exp = gNpcTable[gNPC[n].code_char].exp;
SetUniqueParameter(&gNPC[n]); SetUniqueParameter(&gNPC[n]);
gNPC[n].cond |= 0x80u; gNPC[n].cond |= 0x80;
gNPC[n].act_no = 0; gNPC[n].act_no = 0;
gNPC[n].act_wait = 0; gNPC[n].act_wait = 0;
gNPC[n].count1 = 0; gNPC[n].count1 = 0;
@ -432,19 +440,20 @@ void ChangeCheckableNpCharByEvent(int code_event, int code_char, int dir)
gNPC[n].xm = 0; gNPC[n].xm = 0;
gNPC[n].ym = 0; gNPC[n].ym = 0;
if (dir != 5) if (dir == 5)
{ {
if (dir == 4) // Another empty case that has to exist for the same assembly to be generated
}
else if (dir == 4)
{ {
if (gNPC[n].x >= gMC.x) if (gNPC[n].x < gMC.x)
gNPC[n].direct = 0;
else
gNPC[n].direct = 2; gNPC[n].direct = 2;
else
gNPC[n].direct = 0;
} }
else else
{ {
gNPC[n].direct = dir; gNPC[n].direct = (signed char)dir;
}
} }
gpNpcFuncTbl[code_char](&gNPC[n]); gpNpcFuncTbl[code_char](&gNPC[n]);
@ -454,95 +463,111 @@ void ChangeCheckableNpCharByEvent(int code_event, int code_char, int dir)
void SetNpCharActionNo(int code_event, int act_no, int dir) void SetNpCharActionNo(int code_event, int act_no, int dir)
{ {
for (int n = 0; n < NPC_MAX; n++) int n = 0;
while (n < NPC_MAX)
{ {
if ((gNPC[n].cond & 0x80) && gNPC[n].code_event == code_event) if ((gNPC[n].cond & 0x80) && gNPC[n].code_event == code_event)
{ break;
++n;
}
if (n == NPC_MAX)
return;
gNPC[n].act_no = act_no; gNPC[n].act_no = act_no;
if (dir != 5) if (dir == 5)
{ {
if (dir == 4) // Another empty case that has to exist for the same assembly to be generated
}
else if (dir == 4)
{ {
if (gNPC[n].x >= gMC.x) if (gNPC[n].x < gMC.x)
gNPC[n].direct = 0;
else
gNPC[n].direct = 2; gNPC[n].direct = 2;
else
gNPC[n].direct = 0;
} }
else else
{ {
gNPC[n].direct = dir; gNPC[n].direct = dir;
} }
} }
break;
}
}
}
void MoveNpChar(int code_event, int x, int y, int dir) void MoveNpChar(int code_event, int x, int y, int dir)
{ {
for (int n = 0; n < NPC_MAX; n++) int n = 0;
while (n < NPC_MAX)
{ {
if ((gNPC[n].cond & 0x80) && gNPC[n].code_event == code_event) if ((gNPC[n].cond & 0x80) && gNPC[n].code_event == code_event)
{ break;
++n;
}
if (n == NPC_MAX)
return;
gNPC[n].x = x; gNPC[n].x = x;
gNPC[n].y = y; gNPC[n].y = y;
if (dir != 5) if (dir == 5)
{ {
if (dir == 4) // Another empty case that has to exist for the same assembly to be generated
}
else if (dir == 4)
{ {
if (gNPC[n].x >= gMC.x) if (gNPC[n].x < gMC.x)
gNPC[n].direct = 0;
else
gNPC[n].direct = 2; gNPC[n].direct = 2;
else
gNPC[n].direct = 0;
} }
else else
{ {
gNPC[n].direct = dir; gNPC[n].direct = (signed char)dir;
}
}
break;
}
} }
} }
void BackStepMyChar(int code_event) void BackStepMyChar(int code_event)
{ {
int n = 0;
gMC.cond &= ~1; gMC.cond &= ~1;
gMC.ym = -0x200; gMC.ym = -0x200;
if (code_event) if (code_event == 0)
{ {
if (code_event == 2) gMC.direct = 0;
gMC.xm = 0x200;
}
else if (code_event == 2)
{ {
gMC.direct = 2; gMC.direct = 2;
gMC.xm = -0x200; gMC.xm = -0x200;
} }
else else
{ {
for (int n = 0; n < NPC_MAX; n++) while (n < NPC_MAX)
{ {
if ((gNPC[n].cond & 0x80) && gNPC[n].code_event == code_event) if ((gNPC[n].cond & 0x80) && gNPC[n].code_event == code_event)
break;
++n;
}
if (n == NPC_MAX)
return;
if (gNPC[n].x < gMC.x)
{ {
if (gNPC[n].x >= gMC.x) gMC.direct = 0;
gMC.xm = 0x200;
}
else
{ {
gMC.direct = 2; gMC.direct = 2;
gMC.xm = -0x200; gMC.xm = -0x200;
} }
else
{
gMC.direct = 0;
gMC.xm = 0x200;
}
}
}
}
}
else
{
gMC.direct = 0;
gMC.xm = 0x200;
} }
} }
@ -558,7 +583,7 @@ void DeleteNpCharEvent(int code)
} }
} }
void DeleteNpCharCode(int code, bool bSmoke) void DeleteNpCharCode(int code, BOOL bSmoke)
{ {
for (int n = 0; n < NPC_MAX; n++) for (int n = 0; n < NPC_MAX; n++)
{ {
@ -573,15 +598,15 @@ void DeleteNpCharCode(int code, bool bSmoke)
switch (gNPC[n].size) switch (gNPC[n].size)
{ {
case 1:
SetDestroyNpChar(gNPC[n].x, gNPC[n].y, gNPC[n].view.back, 4);
break;
case 2: case 2:
SetDestroyNpChar(gNPC[n].x, gNPC[n].y, gNPC[n].view.back, 8); SetDestroyNpChar(gNPC[n].x, gNPC[n].y, gNPC[n].view.back, 8);
break; break;
case 3: case 3:
SetDestroyNpChar(gNPC[n].x, gNPC[n].y, gNPC[n].view.back, 16); SetDestroyNpChar(gNPC[n].x, gNPC[n].y, gNPC[n].view.back, 16);
break; break;
case 1:
SetDestroyNpChar(gNPC[n].x, gNPC[n].y, gNPC[n].view.back, 4);
break;
} }
} }
} }
@ -596,23 +621,23 @@ void GetNpCharPosition(int *x, int *y, int i)
BOOL IsNpCharCode(int code) BOOL IsNpCharCode(int code)
{ {
for (int i = 0; i < NPC_MAX; i++) for (int i = 0; i < NPC_MAX; ++i)
{
if ((gNPC[i].cond & 0x80) && gNPC[i].code_char == code) if ((gNPC[i].cond & 0x80) && gNPC[i].code_char == code)
return TRUE; return TRUE;
}
return FALSE; return FALSE;
} }
BOOL GetNpCharAlive(int code_event) BOOL GetNpCharAlive(int code_event)
{ {
for (int i = 0; i < NPC_MAX; i++) int i;
{ for (i = 0; i < NPC_MAX; ++i)
if ((gNPC[i].cond & 0x80) && gNPC[i].code_event == code_event) if ((gNPC[i].cond & 0x80) && gNPC[i].code_event == code_event)
return TRUE; break;
}
if (i < NPC_MAX)
return TRUE;
else
return FALSE; return FALSE;
} }

View file

@ -1,7 +1,5 @@
#pragma once #pragma once
#include <stdint.h>
#include "WindowsWrapper.h" #include "WindowsWrapper.h"
#include "Draw.h" #include "Draw.h"
@ -29,7 +27,7 @@ enum NPC_flags
struct NPCHAR struct NPCHAR
{ {
uint8_t cond; unsigned char cond;
int flag; int flag;
int x; int x;
int y; int y;
@ -49,7 +47,7 @@ struct NPCHAR
int exp; int exp;
int size; int size;
int direct; int direct;
uint16_t bits; unsigned short bits;
RECT rect; RECT rect;
int ani_wait; int ani_wait;
int ani_no; int ani_no;
@ -59,7 +57,7 @@ struct NPCHAR
int act_wait; int act_wait;
RECT hit; RECT hit;
RECT view; RECT view;
uint8_t shock; unsigned char shock;
int damage_view; int damage_view;
int damage; int damage;
NPCHAR *pNpc; NPCHAR *pNpc;
@ -67,12 +65,12 @@ struct NPCHAR
struct EVENT struct EVENT
{ {
int16_t x; short x;
int16_t y; short y;
int16_t code_flag; short code_flag;
int16_t code_event; short code_event;
int16_t code_char; short code_char;
uint16_t bits; unsigned short bits;
}; };
extern NPCHAR gNPC[NPC_MAX]; extern NPCHAR gNPC[NPC_MAX];
@ -99,7 +97,7 @@ void SetNpCharActionNo(int code_event, int act_no, int dir);
void MoveNpChar(int code_event, int x, int y, int dir); void MoveNpChar(int code_event, int x, int y, int dir);
void BackStepMyChar(int code_event); void BackStepMyChar(int code_event);
void DeleteNpCharEvent(int code); void DeleteNpCharEvent(int code);
void DeleteNpCharCode(int code, bool bSmoke); void DeleteNpCharCode(int code, BOOL bSmoke);
void GetNpCharPosition(int *x, int *y, int i); void GetNpCharPosition(int *x, int *y, int i);
BOOL IsNpCharCode(int code); BOOL IsNpCharCode(int code);
BOOL GetNpCharAlive(int code_event); BOOL GetNpCharAlive(int code_event);

View file

@ -1352,8 +1352,18 @@ void ActNpc117(NPCHAR *npc)
break; break;
case 3: case 3:
// TODO: This code is being problematic, and if (0)
// assembling with the wrong registers. {
// There used to be an if here that didn't do anything, but the compiler optimised it out.
// We only know this was here because empty ifs mess with the register usage.
// Since there's no code, we have no idea what the original condition actually was.
}
if (0)
{
// Another empty if
}
npc->act_no = 4; npc->act_no = 4;
npc->ani_no = 1; npc->ani_no = 1;
npc->ani_wait = 0; npc->ani_wait = 0;
@ -1382,9 +1392,15 @@ void ActNpc117(NPCHAR *npc)
npc->ani_no = 5; npc->ani_no = 5;
SetDestroyNpChar(npc->x, npc->y, npc->view.back, 8); SetDestroyNpChar(npc->x, npc->y, npc->view.back, 8);
break; break;
// End of wrong-reg code
case 6: case 6:
if (0)
{
// There used to be an if here that didn't do anything, but the compiler optimised it out.
// We only know this was here because empty ifs mess with the register usage.
// Since there's no code, we have no idea what the original condition actually was.
}
npc->ani_no = 5; npc->ani_no = 5;
break; break;

View file

@ -1,5 +1,7 @@
#include "NpcHit.h" #include "NpcHit.h"
#include "WindowsWrapper.h"
#include "Back.h" #include "Back.h"
#include "Bullet.h" #include "Bullet.h"
#include "Caret.h" #include "Caret.h"
@ -16,40 +18,40 @@ void JadgeHitNpCharBlock(NPCHAR *npc, int x, int y)
{ {
int hit = 0; int hit = 0;
if (npc->y - npc->hit.top < ((2 * y + 1) << 12) - 0x600 if (npc->y - npc->hit.top < (y * 0x10 + 5) * 0x200
&& npc->y + npc->hit.bottom > ((2 * y - 1) << 12) + 0x600 && npc->y + npc->hit.bottom > (y * 0x10 - 5) * 0x200
&& npc->x - npc->hit.back < (2 * x + 1) << 12 && npc->x - npc->hit.back < (x * 0x10 + 8) * 0x200
&& npc->x - npc->hit.back > x << 13) && npc->x - npc->hit.back > x * 0x10 * 0x200)
{ {
npc->x = ((2 * x + 1) << 12) + npc->hit.back; npc->x = ((x * 0x10 + 8) * 0x200) + npc->hit.back;
hit |= 1; hit |= 1;
} }
if (npc->y - npc->hit.top < ((2 * y + 1) << 12) - 0x600 if (npc->y - npc->hit.top < (y * 0x10 + 5) * 0x200
&& npc->y + npc->hit.bottom > ((2 * y - 1) << 12) + 0x600 && npc->y + npc->hit.bottom > (y * 0x10 - 5) * 0x200
&& npc->hit.back + npc->x > (2 * x - 1) << 12 && npc->x + npc->hit.back > (x * 0x10 - 8) * 0x200
&& npc->hit.back + npc->x < x << 13) && npc->x + npc->hit.back < x * 0x10 * 0x200)
{ {
npc->x = ((2 * x - 1) << 12) - npc->hit.back; npc->x = ((x * 0x10 - 8) * 0x200) - npc->hit.back;
hit |= 4; hit |= 4;
} }
if (npc->x - npc->hit.back < ((2 * x + 1) << 12) - 0x600 if (npc->x - npc->hit.back < (x * 0x10 + 5) * 0x200
&& npc->hit.back + npc->x > ((2 * x - 1) << 12) + 0x600 && npc->x + npc->hit.back > (x * 0x10 - 5) * 0x200
&& npc->y - npc->hit.top < (2 * y + 1) << 12 && npc->y - npc->hit.top < (y * 0x10 + 8) * 0x200
&& npc->y - npc->hit.top > y << 13) && npc->y - npc->hit.top > y * 0x10 * 0x200)
{ {
npc->y = ((2 * y + 1) << 12) + npc->hit.top; npc->y = ((y * 0x10 + 8) * 0x200) + npc->hit.top;
npc->ym = 0; npc->ym = 0;
hit |= 2; hit |= 2;
} }
if (npc->x - npc->hit.back < ((2 * x + 1) << 12) - 0x600 if (npc->x - npc->hit.back < (x * 0x10 + 5) * 0x200
&& npc->hit.back + npc->x > ((2 * x - 1) << 12) + 0x600 && npc->x + npc->hit.back > (x * 0x10 - 5) * 0x200
&& npc->y + npc->hit.bottom > (2 * y - 1) << 12 && npc->y + npc->hit.bottom > (y * 0x10 - 8) * 0x200
&& npc->y + npc->hit.bottom < y << 13) && npc->y + npc->hit.bottom < y * 0x10 * 0x200)
{ {
npc->y = ((2 * y - 1) << 12) - npc->hit.bottom; npc->y = ((y * 0x10 - 8) * 0x200) - npc->hit.bottom;
npc->ym = 0; npc->ym = 0;
hit |= 8; hit |= 8;
} }
@ -61,20 +63,20 @@ void JudgeHitNpCharTriangleA(NPCHAR *npc, int x, int y)
{ {
int hit = 0; int hit = 0;
if (npc->x < (2 * x + 1) << 12 if (npc->x < (x * 0x10 + 8) * 0x200
&& npc->x > (2 * x - 1) << 12 && npc->x > (x * 0x10 - 8) * 0x200
&& npc->y - npc->hit.top < (y << 13) - (-0x2000 * x + npc->x) / 2 + 0x800 && npc->y - npc->hit.top < (y * 0x10 * 0x200) - ((npc->x - (x * 0x10 * 0x200)) / 2) + 0x800
&& npc->y + npc->hit.bottom > (2 * y - 1) << 12) && npc->y + npc->hit.bottom > (y * 0x10 - 8) * 0x200)
{ {
//Clip //Clip
npc->y = npc->hit.top + (y << 13) - (-0x2000 * x + npc->x) / 2 + 0x800; npc->y = (y * 0x10 * 0x200) - ((npc->x - (x * 0x10 * 0x200)) / 2) + 0x800 + npc->hit.top;
//Halt momentum //Halt momentum
if (npc->ym < 0) if (npc->ym < 0)
npc->ym = 0; npc->ym = 0;
//Set that hit a ceiling //Set that hit a ceiling
hit = 2; hit |= 2;
} }
npc->flag |= hit; npc->flag |= hit;
@ -84,20 +86,20 @@ void JudgeHitNpCharTriangleB(NPCHAR *npc, int x, int y)
{ {
int hit = 0; int hit = 0;
if (npc->x < (2 * x + 1) << 12 if (npc->x < (x * 0x10 + 8) * 0x200
&& npc->x > (2 * x - 1) << 12 && npc->x > (x * 0x10 - 8) * 0x200
&& npc->y - npc->hit.top < (y << 13) - (-0x2000 * x + npc->x) / 2 - 0x800 && npc->y - npc->hit.top < (y * 0x10 * 0x200) - ((npc->x - (x * 0x10 * 0x200)) / 2) - 0x800
&& npc->y + npc->hit.bottom > (2 * y - 1) << 12) && npc->y + npc->hit.bottom > (y * 0x10 - 8) * 0x200)
{ {
//Clip //Clip
npc->y = npc->hit.top + (y << 13) - (-0x2000 * x + npc->x) / 2 - 0x800; npc->y = (y * 0x10 * 0x200) - ((npc->x - (x * 0x10 * 0x200)) / 2) - 0x800 + npc->hit.top;
//Halt momentum //Halt momentum
if (npc->ym < 0) if (npc->ym < 0)
npc->ym = 0; npc->ym = 0;
//Set that hit a ceiling //Set that hit a ceiling
hit = 2; hit |= 2;
} }
npc->flag |= hit; npc->flag |= hit;
@ -107,20 +109,20 @@ void JudgeHitNpCharTriangleC(NPCHAR *npc, int x, int y)
{ {
int hit = 0; int hit = 0;
if (npc->x < (2 * x + 1) << 12 if (npc->x < (x * 0x10 + 8) * 0x200
&& npc->x > (2 * x - 1) << 12 && npc->x > (x * 0x10 - 8) * 0x200
&& npc->y - npc->hit.top < (y << 13) + (-0x2000 * x + npc->x) / 2 - 0x800 && npc->y - npc->hit.top < (y * 0x10 * 0x200) + ((npc->x - (x * 0x10 * 0x200)) / 2) - 0x800
&& npc->y + npc->hit.bottom > (2 * y - 1) << 12) && npc->y + npc->hit.bottom > (y * 0x10 - 8) * 0x200)
{ {
//Clip //Clip
npc->y = npc->hit.top + (y << 13) + (-0x2000 * x + npc->x) / 2 - 0x800; npc->y = (y * 0x10 * 0x200) + ((npc->x - (x * 0x10 * 0x200)) / 2) - 0x800 + npc->hit.top;
//Halt momentum //Halt momentum
if (npc->ym < 0) if (npc->ym < 0)
npc->ym = 0; npc->ym = 0;
//Set that hit a ceiling //Set that hit a ceiling
hit = 2; hit |= 2;
} }
npc->flag |= hit; npc->flag |= hit;
@ -130,20 +132,20 @@ void JudgeHitNpCharTriangleD(NPCHAR *npc, int x, int y)
{ {
int hit = 0; int hit = 0;
if (npc->x < (2 * x + 1) << 12 if (npc->x < (x * 0x10 + 8) * 0x200
&& npc->x > (2 * x - 1) << 12 && npc->x > (x * 0x10 - 8) * 0x200
&& npc->y - npc->hit.top < (y << 13) + (-0x2000 * x + npc->x) / 2 + 0x800 && npc->y - npc->hit.top < (y * 0x10 * 0x200) + ((npc->x - (x * 0x10 * 0x200)) / 2) + 0x800
&& npc->y + npc->hit.bottom > (2 * y - 1) << 12) && npc->y + npc->hit.bottom > (y * 0x10 - 8) * 0x200)
{ {
//Clip //Clip
npc->y = npc->hit.top + (y << 13) + (-0x2000 * x + npc->x) / 2 + 0x800; npc->y = (y * 0x10 * 0x200) + ((npc->x - (x * 0x10 * 0x200)) / 2) + 0x800 + npc->hit.top;
//Halt momentum //Halt momentum
if (npc->ym < 0) if (npc->ym < 0)
npc->ym = 0; npc->ym = 0;
//Set that hit a ceiling //Set that hit a ceiling
hit = 2; hit |= 2;
} }
npc->flag |= hit; npc->flag |= hit;
@ -151,22 +153,24 @@ void JudgeHitNpCharTriangleD(NPCHAR *npc, int x, int y)
void JudgeHitNpCharTriangleE(NPCHAR *npc, int x, int y) void JudgeHitNpCharTriangleE(NPCHAR *npc, int x, int y)
{ {
int hit = 0x10000; int hit = 0;
if ( npc->x < (2 * x + 1) << 12 hit |= 0x10000;
&& npc->x > (2 * x - 1) << 12
&& npc->y + npc->hit.bottom > (y << 13) + (-0x2000 * x + npc->x) / 2 - 0x800 if (npc->x < (x * 0x10 + 8) * 0x200
&& npc->y - npc->hit.top < (2 * y + 1) << 12 ) && npc->x > (x * 0x10 - 8) * 0x200
&& npc->y + npc->hit.bottom > (y * 0x10 * 0x200) + ((npc->x - (x * 0x10 * 0x200)) / 2) - 0x800
&& npc->y - npc->hit.top < (y * 0x10 + 8) * 0x200)
{ {
//Clip //Clip
npc->y = (y << 13) + (-0x2000 * x + npc->x) / 2 - 0x800 - npc->hit.bottom; npc->y = (y * 0x10 * 0x200) + ((npc->x - (x * 0x10 * 0x200)) / 2) - 0x800 - npc->hit.bottom;
//Halt momentum //Halt momentum
if (npc->ym > 0) if (npc->ym > 0)
npc->ym = 0; npc->ym = 0;
//Set that hit this slope //Set that hit this slope
hit = 0x10028; hit |= 0x28;
} }
npc->flag |= hit; npc->flag |= hit;
@ -174,22 +178,24 @@ void JudgeHitNpCharTriangleE(NPCHAR *npc, int x, int y)
void JudgeHitNpCharTriangleF(NPCHAR *npc, int x, int y) void JudgeHitNpCharTriangleF(NPCHAR *npc, int x, int y)
{ {
int hit = 0x20000; int hit = 0;
if ( npc->x < (2 * x + 1) << 12 hit |= 0x20000;
&& npc->x > (2 * x - 1) << 12
&& npc->y + npc->hit.bottom > (y << 13) + (-0x2000 * x + npc->x) / 2 + 0x800 if (npc->x < (x * 0x10 + 8) * 0x200
&& npc->y - npc->hit.top < (2 * y + 1) << 12 ) && npc->x >= (x * 0x10 - 8) * 0x200 // Note that this function uses '>='. I'm not sure if this is a bug.
&& npc->y + npc->hit.bottom > (y * 0x10 * 0x200) + ((npc->x - (x * 0x10 * 0x200)) / 2) + 0x800
&& npc->y - npc->hit.top < (y * 0x10 + 8) * 0x200)
{ {
//Clip //Clip
npc->y = (y << 13) + (-0x2000 * x + npc->x) / 2 + 0x800 - npc->hit.bottom; npc->y = (y * 0x10 * 0x200) + ((npc->x - (x * 0x10 * 0x200)) / 2) + 0x800 - npc->hit.bottom;
//Halt momentum //Halt momentum
if (npc->ym > 0) if (npc->ym > 0)
npc->ym = 0; npc->ym = 0;
//Set that hit this slope //Set that hit this slope
hit = 0x20028; hit |= 0x28;
} }
npc->flag |= hit; npc->flag |= hit;
@ -197,22 +203,24 @@ void JudgeHitNpCharTriangleF(NPCHAR *npc, int x, int y)
void JudgeHitNpCharTriangleG(NPCHAR *npc, int x, int y) void JudgeHitNpCharTriangleG(NPCHAR *npc, int x, int y)
{ {
int hit = 0x40000; int hit = 0;
if ( npc->x < (2 * x + 1) << 12 hit |= 0x40000;
&& npc->x > (2 * x - 1) << 12
&& npc->y + npc->hit.bottom > (y << 13) - (-0x2000 * x + npc->x) / 2 + 0x800 if (npc->x < (x * 0x10 + 8) * 0x200
&& npc->y - npc->hit.top < (2 * y + 1) << 12 ) && npc->x > (x * 0x10 - 8) * 0x200
&& npc->y + npc->hit.bottom > (y * 0x10 * 0x200) - ((npc->x - (x * 0x10 * 0x200)) / 2) + 0x800
&& npc->y - npc->hit.top < (y * 0x10 + 8) * 0x200)
{ {
//Clip //Clip
npc->y = (y << 13) - (-0x2000 * x + npc->x) / 2 + 0x800 - npc->hit.bottom; npc->y = (y * 0x10 * 0x200) - ((npc->x - (x * 0x10 * 0x200)) / 2) + 0x800 - npc->hit.bottom;
//Halt momentum //Halt momentum
if (npc->ym > 0) if (npc->ym > 0)
npc->ym = 0; npc->ym = 0;
//Set that hit this slope //Set that hit this slope
hit = 0x40018; hit |= 0x18;
} }
npc->flag |= hit; npc->flag |= hit;
@ -220,22 +228,24 @@ void JudgeHitNpCharTriangleG(NPCHAR *npc, int x, int y)
void JudgeHitNpCharTriangleH(NPCHAR *npc, int x, int y) void JudgeHitNpCharTriangleH(NPCHAR *npc, int x, int y)
{ {
int hit = 0x80000; int hit = 0;
if ( npc->x < (2 * x + 1) << 12 hit |= 0x80000;
&& npc->x > (2 * x - 1) << 12
&& npc->y + npc->hit.bottom > (y << 13) - (-0x2000 * x + npc->x) / 2 - 0x800 if (npc->x < (x * 0x10 + 8) * 0x200
&& npc->y - npc->hit.top < (2 * y + 1) << 12 ) && npc->x > (x * 0x10 - 8) * 0x200
&& npc->y + npc->hit.bottom > (y * 0x10 * 0x200) - ((npc->x - (x * 0x10 * 0x200)) / 2) - 0x800
&& npc->y - npc->hit.top < (y * 0x10 + 8) * 0x200)
{ {
//Clip //Clip
npc->y = (y << 13) - (-0x2000 * x + npc->x) / 2 - 0x800 - npc->hit.bottom; npc->y = (y * 0x10 * 0x200) - ((npc->x - (x * 0x10 * 0x200)) / 2) - 0x800 - npc->hit.bottom;
//Halt momentum //Halt momentum
if (npc->ym > 0) if (npc->ym > 0)
npc->ym = 0; npc->ym = 0;
//Set that hit this slope //Set that hit this slope
hit = 0x80018; hit |= 0x18;
} }
npc->flag |= hit; npc->flag |= hit;
@ -245,19 +255,24 @@ void JudgeHitNpCharWater(NPCHAR *npc, int x, int y)
{ {
int hit = 0; int hit = 0;
if (npc->x - npc->hit.back < (4 * (2 * x + 1) - 1) << 10 if (npc->x - npc->hit.back < (x * 0x10 + 6) * 0x200
&& npc->hit.back + npc->x > (4 * (2 * x - 1) + 1) << 10 && npc->x + npc->hit.back > (x * 0x10 - 6) * 0x200
&& npc->y - npc->hit.top < (4 * (2 * y + 1) - 1) << 10 && npc->y - npc->hit.top < (y * 0x10 + 6) * 0x200
&& npc->y + npc->hit.bottom > (4 * (2 * y - 1) + 1) << 10) && npc->y + npc->hit.bottom > (y * 0x10 - 6) * 0x200)
hit = 0x100; hit |= 0x100;
npc->flag |= hit; npc->flag |= hit;
} }
void HitNpCharMap() void HitNpCharMap()
{ {
int offy[9]; int judg, x, y;
int offx[9]; int offx[9];
int offy[9];
int i;
int j;
offx[0] = 0; offx[0] = 0;
offx[1] = 1; offx[1] = 1;
@ -279,37 +294,38 @@ void HitNpCharMap()
offy[7] = 2; offy[7] = 2;
offy[8] = 2; offy[8] = 2;
for (int i = 0; i < NPC_MAX; i++) for (i = 0; i < NPC_MAX; i++)
{ {
if ((gNPC[i].cond & 0x80) && !(gNPC[i].bits & 8)) if ((gNPC[i].cond & 0x80) == 0)
continue;
if (gNPC[i].bits & 8)
continue;
if (gNPC[i].size >= 3)
{ {
int judg, x, y; judg = 9;
if (gNPC[i].size <= 2) x = (gNPC[i].x - 0x1000) / 0x10 / 0x200;
{ y = (gNPC[i].y - 0x1000) / 0x10 / 0x200;
judg = 4;
x = gNPC[i].x / 0x2000;
y = gNPC[i].y / 0x2000;
} }
else else
{ {
judg = 9; judg = 4;
x = (gNPC[i].x - 0x1000) / 0x2000; x = gNPC[i].x / 0x10 / 0x200;
y = (gNPC[i].y - 0x1000) / 0x2000; y = gNPC[i].y / 0x10 / 0x200;
} }
gNPC[i].flag = 0; gNPC[i].flag = 0;
for (int j = 0; j < judg; j++) for (j = 0; j < judg; j++)
{ {
switch (GetAttribute(x + offx[j], y + offy[j])) switch (GetAttribute(x + offx[j], y + offy[j]))
{ {
//Water //No NPC block
case 0x02: case 0x44:
case 0x60: if (gNPC[i].bits & npc_ignore44)
case 0x62:
JudgeHitNpCharWater(&gNPC[i], x + offx[j], y + offy[j]);
break; break;
// Fallthrough
//Block //Block
case 0x03: case 0x03:
case 0x05: case 0x05:
@ -318,20 +334,6 @@ void HitNpCharMap()
JadgeHitNpCharBlock(&gNPC[i], x + offx[j], y + offy[j]); JadgeHitNpCharBlock(&gNPC[i], x + offx[j], y + offy[j]);
break; break;
//Water block
case 0x04:
case 0x61:
case 0x64:
JadgeHitNpCharBlock(&gNPC[i], x + offx[j], y + offy[j]);
JudgeHitNpCharWater(&gNPC[i], x + offx[j], y + offy[j]);
break;
//No NPC block
case 0x44:
if (!(gNPC[i].bits & npc_ignore44))
JadgeHitNpCharBlock(&gNPC[i], x + offx[j], y + offy[j]);
break;
//Slopes //Slopes
case 0x50: case 0x50:
JudgeHitNpCharTriangleA(&gNPC[i], x + offx[j], y + offy[j]); JudgeHitNpCharTriangleA(&gNPC[i], x + offx[j], y + offy[j]);
@ -365,6 +367,21 @@ void HitNpCharMap()
JudgeHitNpCharTriangleH(&gNPC[i], x + offx[j], y + offy[j]); JudgeHitNpCharTriangleH(&gNPC[i], x + offx[j], y + offy[j]);
break; break;
//Water
case 0x02:
case 0x60:
case 0x62:
JudgeHitNpCharWater(&gNPC[i], x + offx[j], y + offy[j]);
break;
//Water block
case 0x04:
case 0x61:
case 0x64:
JadgeHitNpCharBlock(&gNPC[i], x + offx[j], y + offy[j]);
JudgeHitNpCharWater(&gNPC[i], x + offx[j], y + offy[j]);
break;
//Water slopes //Water slopes
case 0x70: case 0x70:
JudgeHitNpCharTriangleA(&gNPC[i], x + offx[j], y + offy[j]); JudgeHitNpCharTriangleA(&gNPC[i], x + offx[j], y + offy[j]);
@ -405,7 +422,34 @@ void HitNpCharMap()
JudgeHitNpCharTriangleH(&gNPC[i], x + offx[j], y + offy[j]); JudgeHitNpCharTriangleH(&gNPC[i], x + offx[j], y + offy[j]);
JudgeHitNpCharWater(&gNPC[i], x + offx[j], y + offy[j]); JudgeHitNpCharWater(&gNPC[i], x + offx[j], y + offy[j]);
break; break;
}
case 0xA0:
gNPC[i].flag |= 0x100;
// Fallthrough
case 0x80:
gNPC[i].flag |= 0x1000;
break;
case 0xA1:
gNPC[i].flag |= 0x100;
// Fallthrough
case 0x81:
gNPC[i].flag |= 0x2000;
break;
case 0xA2:
gNPC[i].flag |= 0x100;
// Fallthrough
case 0x82:
gNPC[i].flag |= 0x4000;
break;
case 0xA3:
gNPC[i].flag |= 0x100;
// Fallthrough
case 0x83:
gNPC[i].flag |= 0x8000;
break;
} }
if (gNPC[i].y > gWaterY + 0x800) if (gNPC[i].y > gWaterY + 0x800)
@ -414,7 +458,7 @@ void HitNpCharMap()
} }
} }
void LoseNpChar(NPCHAR *npc, bool bVanish) void LoseNpChar(NPCHAR *npc, BOOL bVanish)
{ {
//Play death sound //Play death sound
PlaySoundObject(npc->destroy_voice, 1); PlaySoundObject(npc->destroy_voice, 1);
@ -436,18 +480,34 @@ void LoseNpChar(NPCHAR *npc, bool bVanish)
//Create drop //Create drop
if (npc->exp) if (npc->exp)
{ {
int v3 = Random(1, 5); int val;
char v4;
if (v3 == 1) switch (Random(1, 5))
{ {
if (npc->exp <= 6) case 1:
SetLifeObject(npc->x, npc->y, 2); // Spawn health
if (npc->exp > 6)
val = 6;
else else
SetLifeObject(npc->x, npc->y, 6); val = 2;
}
else if (v3 != 2 || (npc->exp <= 6 ? (v4 = SetBulletObject(npc->x, npc->y, 1)) : (v4 = SetBulletObject(npc->x, npc->y, 3)), !v4)) //TODO: what the FUCK SetLifeObject(npc->x, npc->y, val);
{
break;
case 2:
// Spawn missile launcher ammo
if (npc->exp > 6)
val = 3;
else
val = 1;
if (SetBulletObject(npc->x, npc->y, val))
break;
// Fallthrough
default:
// Spawn weapon energy
SetExpObjects(npc->x, npc->y, npc->exp); SetExpObjects(npc->x, npc->y, npc->exp);
} }
} }
@ -456,43 +516,55 @@ void LoseNpChar(NPCHAR *npc, bool bVanish)
SetNPCFlag(npc->code_flag); SetNPCFlag(npc->code_flag);
//Create value view //Create value view
if (!(npc->bits & npc_showDamage)) if (npc->bits & npc_showDamage)
{
npc->cond = 0;
}
else
{ {
if ((npc->bits & npc_showDamage) && npc->damage_view) if ((npc->bits & npc_showDamage) && npc->damage_view)
SetValueView(&npc->x, &npc->y, npc->damage_view); SetValueView(&npc->x, &npc->y, npc->damage_view);
if (bVanish) if (bVanish)
VanishNpChar(npc); VanishNpChar(npc);
} }
else
{
npc->cond = 0;
}
} }
void HitNpCharBullet() void HitNpCharBullet()
{ {
for (int n = 0; n < NPC_MAX; n++) int n;
int b;
BOOL bHit;
for (n = 0; n < NPC_MAX; n++)
{ {
if ((gNPC[n].cond & 0x80) && (!(gNPC[n].bits & npc_shootable) || !(gNPC[n].bits & npc_interact))) if ((gNPC[n].cond & 0x80) == 0)
{ continue;
for (int b = 0; b < BULLET_MAX; b++)
{ if (gNPC[n].bits & npc_shootable && gNPC[n].bits & npc_interact)
if (gBul[b].cond & 0x80 && gBul[b].damage != -1) continue;
for (b = 0; b < BULLET_MAX; b++)
{ {
if ((gBul[b].cond & 0x80) == 0)
continue;
if (gBul[b].damage == -1)
continue;
//Check if bullet touches npc //Check if bullet touches npc
bool bHit = false; bHit = FALSE;
if (gNPC[n].bits & npc_shootable if (gNPC[n].bits & npc_shootable
&& gNPC[n].x - gNPC[n].hit.back < gBul[b].x + gBul[b].enemyXL && gNPC[n].x - gNPC[n].hit.back < gBul[b].x + gBul[b].enemyXL
&& gNPC[n].x + gNPC[n].hit.back > gBul[b].x - gBul[b].enemyXL && gNPC[n].x + gNPC[n].hit.back > gBul[b].x - gBul[b].enemyXL
&& gNPC[n].y - gNPC[n].hit.top < gBul[b].y + gBul[b].enemyYL && gNPC[n].y - gNPC[n].hit.top < gBul[b].y + gBul[b].enemyYL
&& gNPC[n].y + gNPC[n].hit.bottom > gBul[b].y - gBul[b].enemyYL) && gNPC[n].y + gNPC[n].hit.bottom > gBul[b].y - gBul[b].enemyYL)
bHit = true; bHit = TRUE;
else if (gNPC[n].bits & npc_invulnerable else if (gNPC[n].bits & npc_invulnerable
&& gNPC[n].x - gNPC[n].hit.back < gBul[b].x + gBul[b].blockXL && gNPC[n].x - gNPC[n].hit.back < gBul[b].x + gBul[b].blockXL
&& gNPC[n].x + gNPC[n].hit.back > gBul[b].x - gBul[b].blockXL && gNPC[n].x + gNPC[n].hit.back > gBul[b].x - gBul[b].blockXL
&& gNPC[n].y - gNPC[n].hit.top < gBul[b].y + gBul[b].blockYL && gNPC[n].y - gNPC[n].hit.top < gBul[b].y + gBul[b].blockYL
&& gNPC[n].y + gNPC[n].hit.bottom > gBul[b].y - gBul[b].blockYL) && gNPC[n].y + gNPC[n].hit.bottom > gBul[b].y - gBul[b].blockYL)
bHit = true; bHit = TRUE;
if (bHit) if (bHit)
{ {
@ -501,7 +573,19 @@ void HitNpCharBullet()
{ {
gNPC[n].life -= gBul[b].damage; gNPC[n].life -= gBul[b].damage;
if (gNPC[n].life > 0) if (gNPC[n].life < 1)
{
gNPC[n].life = 0;
if (gNPC[n].bits & npc_showDamage)
gNPC[n].damage_view -= gBul[b].damage;
if ((gMC.cond & 0x80) && gNPC[n].bits & npc_eventDie)
StartTextScript(gNPC[n].code_event);
else
gNPC[n].cond |= 8;
}
else
{ {
if (gNPC[n].shock < 14) if (gNPC[n].shock < 14)
{ {
@ -515,28 +599,19 @@ void HitNpCharBullet()
if (gNPC[n].bits & npc_showDamage) if (gNPC[n].bits & npc_showDamage)
gNPC[n].damage_view -= gBul[b].damage; gNPC[n].damage_view -= gBul[b].damage;
} }
else }
else if (gBul[b].code_bullet == 13
|| gBul[b].code_bullet == 14
|| gBul[b].code_bullet == 15
|| gBul[b].code_bullet == 28
|| gBul[b].code_bullet == 29
|| gBul[b].code_bullet == 30)
{ {
gNPC[n].life = 0; // Strange empty case that's needed for accurate assembly
if (gNPC[n].bits & npc_showDamage)
gNPC[n].damage_view -= gBul[b].damage;
if ((gMC.cond & 0x80) && gNPC[n].bits & npc_eventDie)
StartTextScript(gNPC[n].code_event);
else
gNPC[n].cond |= 8;
}
} }
else if ((gBul[b].bbits & 0x10) == 0)
{
//Hit invulnerable NPC //Hit invulnerable NPC
else if (gBul[b].code_bullet != 13
&& gBul[b].code_bullet != 14
&& gBul[b].code_bullet != 15
&& gBul[b].code_bullet != 28
&& gBul[b].code_bullet != 29
&& gBul[b].code_bullet != 30
&& !(gBul[b].bbits & 0x10))
{
SetCaret((gBul[b].x + gNPC[n].x) / 2, (gBul[b].y + gNPC[n].y) / 2, 2, 2); SetCaret((gBul[b].x + gNPC[n].x) / 2, (gBul[b].y + gNPC[n].y) / 2, 2, 2);
PlaySoundObject(31, 1); PlaySoundObject(31, 1);
gBul[b].life = 0; gBul[b].life = 0;
@ -546,10 +621,8 @@ void HitNpCharBullet()
--gBul[b].life; --gBul[b].life;
} }
} }
}
if (gNPC[n].cond & 8) if (gNPC[n].cond & 8)
LoseNpChar(&gNPC[n], true); LoseNpChar(&gNPC[n], TRUE);
}
} }
} }

View file

@ -1,5 +1,7 @@
#pragma once #pragma once
#include "WindowsWrapper.h"
#include "NpChar.h" #include "NpChar.h"
void JadgeHitNpCharBlock(NPCHAR *npc, int x, int y); void JadgeHitNpCharBlock(NPCHAR *npc, int x, int y);
@ -13,5 +15,5 @@ void JudgeHitNpCharTriangleG(NPCHAR *npc, int x, int y);
void JudgeHitNpCharTriangleH(NPCHAR *npc, int x, int y); void JudgeHitNpCharTriangleH(NPCHAR *npc, int x, int y);
void JudgeHitNpCharWater(NPCHAR *npc, int x, int y); void JudgeHitNpCharWater(NPCHAR *npc, int x, int y);
void HitNpCharMap(); void HitNpCharMap();
void LoseNpChar(NPCHAR *npc, bool bVanish); void LoseNpChar(NPCHAR *npc, BOOL bVanish);
void HitNpCharBullet(); void HitNpCharBullet();

View file

@ -1,7 +1,5 @@
#pragma once #pragma once
#include <stdint.h>
#include "WindowsWrapper.h" #include "WindowsWrapper.h"
#include "Draw.h" #include "Draw.h"
@ -9,22 +7,22 @@
struct NPC_TBL_RECT struct NPC_TBL_RECT
{ {
uint8_t front; unsigned char front;
uint8_t top; unsigned char top;
uint8_t back; unsigned char back;
uint8_t bottom; unsigned char bottom;
}; };
struct NPC_TABLE struct NPC_TABLE
{ {
uint16_t bits; unsigned short bits;
uint16_t life; unsigned short life;
uint8_t surf; unsigned char surf;
uint8_t hit_voice; unsigned char hit_voice;
uint8_t destroy_voice; unsigned char destroy_voice;
uint8_t size; unsigned char size;
int32_t exp; long exp;
int32_t damage; long damage;
NPC_TBL_RECT hit; NPC_TBL_RECT hit;
NPC_TBL_RECT view; NPC_TBL_RECT view;
}; };

View file

@ -1,7 +1,6 @@
#include "Organya.h" #include "Organya.h"
#include <stddef.h> #include <stddef.h>
#include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
@ -33,7 +32,7 @@ int gTrackVol[MAXTRACK];
int gOrgVolume = 100; int gOrgVolume = 100;
bool bFadeout = false; bool bFadeout = false;
bool OrganyaNoteAlloc(uint16_t alloc) bool OrganyaNoteAlloc(unsigned short alloc)
{ {
for(int j = 0; j < MAXTRACK; j++) for(int j = 0; j < MAXTRACK; j++)
{ {
@ -110,7 +109,7 @@ OCTWAVE oct_wave[8] = {
{ 8,128, 32 }, //7 Oct { 8,128, 32 }, //7 Oct
}; };
bool MakeSoundObject8(int8_t *wavep, int8_t track, int8_t pipi) bool MakeSoundObject8(signed char *wavep, signed char track, signed char pipi)
{ {
for (int j = 0; j < 8; j++) for (int j = 0; j < 8; j++)
{ {
@ -123,13 +122,13 @@ bool MakeSoundObject8(int8_t *wavep, int8_t track, int8_t pipi)
lpORGANBUFFER[track][j][k] = new SOUNDBUFFER(data_size); lpORGANBUFFER[track][j][k] = new SOUNDBUFFER(data_size);
//Get wave data //Get wave data
uint8_t *wp = new uint8_t[data_size]; unsigned char *wp = new unsigned char[data_size];
uint8_t *wp_sub = wp; unsigned char *wp_sub = wp;
size_t wav_tp = 0; size_t wav_tp = 0;
for (size_t i = 0; i < data_size; i++) for (size_t i = 0; i < data_size; i++)
{ {
uint8_t work = *(wavep+wav_tp); unsigned char work = *(wavep+wav_tp);
work += 0x80; work += 0x80;
*wp_sub = work; *wp_sub = work;
@ -142,7 +141,7 @@ bool MakeSoundObject8(int8_t *wavep, int8_t track, int8_t pipi)
} }
//Copy wave data to sound buffer //Copy wave data to sound buffer
uint8_t *buf; unsigned char *buf;
lpORGANBUFFER[track][j][k]->Lock(&buf, NULL); lpORGANBUFFER[track][j][k]->Lock(&buf, NULL);
memcpy(buf, wp, data_size); memcpy(buf, wp, data_size);
lpORGANBUFFER[track][j][k]->Unlock(); lpORGANBUFFER[track][j][k]->Unlock();
@ -157,7 +156,7 @@ bool MakeSoundObject8(int8_t *wavep, int8_t track, int8_t pipi)
//Playing melody tracks //Playing melody tracks
short freq_tbl[12] = { 262,277,294,311,330,349,370,392,415,440,466,494 }; short freq_tbl[12] = { 262,277,294,311,330,349,370,392,415,440,466,494 };
void ChangeOrganFrequency(uint8_t key, int8_t track, int32_t a) void ChangeOrganFrequency(unsigned char key, signed char track, long a)
{ {
for (int j = 0; j < 8; j++) { for (int j = 0; j < 8; j++) {
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
@ -166,24 +165,24 @@ void ChangeOrganFrequency(uint8_t key, int8_t track, int32_t a)
} }
} }
int16_t pan_tbl[13] = {0, 43, 86, 129, 172, 215, 256, 297, 340, 383, 426, 469, 512}; short pan_tbl[13] = {0, 43, 86, 129, 172, 215, 256, 297, 340, 383, 426, 469, 512};
uint8_t old_key[MAXTRACK] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; unsigned char old_key[MAXTRACK] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
uint8_t key_on[MAXTRACK] = {0}; unsigned char key_on[MAXTRACK] = {0};
uint8_t key_twin[MAXTRACK] = {0}; unsigned char key_twin[MAXTRACK] = {0};
void ChangeOrganPan(uint8_t key, uint8_t pan, int8_t track) void ChangeOrganPan(unsigned char key, unsigned char pan, signed char track)
{ {
if(old_key[track] != PANDUMMY) if(old_key[track] != PANDUMMY)
lpORGANBUFFER[track][old_key[track]/12][key_twin[track]]->SetPan((pan_tbl[pan] - 0x100) * 10); lpORGANBUFFER[track][old_key[track]/12][key_twin[track]]->SetPan((pan_tbl[pan] - 0x100) * 10);
} }
void ChangeOrganVolume(int no, int32_t volume, int8_t track) void ChangeOrganVolume(int no, long volume, signed char track)
{ {
if(old_key[track] != VOLDUMMY) if(old_key[track] != VOLDUMMY)
lpORGANBUFFER[track][old_key[track]/12][key_twin[track]]->SetVolume((volume - 0xFF) * 8); lpORGANBUFFER[track][old_key[track]/12][key_twin[track]]->SetVolume((volume - 0xFF) * 8);
} }
void PlayOrganObject(uint8_t key, int mode, int8_t track, int32_t freq) void PlayOrganObject(unsigned char key, int mode, signed char track, long freq)
{ {
if (lpORGANBUFFER[track][key/12][key_twin[track]] != NULL) if (lpORGANBUFFER[track][key/12][key_twin[track]] != NULL)
{ {
@ -240,7 +239,7 @@ void PlayOrganObject(uint8_t key, int mode, int8_t track, int32_t freq)
} }
//Release tracks //Release tracks
void ReleaseOrganyaObject(int8_t track) void ReleaseOrganyaObject(signed char track)
{ {
for(int i = 0; i < 8; i++) for(int i = 0; i < 8; i++)
{ {
@ -258,7 +257,7 @@ void ReleaseOrganyaObject(int8_t track)
} }
//Handling WAVE100 //Handling WAVE100
int8_t wave_data[100][0x100]; signed char wave_data[100][0x100];
BOOL InitWaveData100() BOOL InitWaveData100()
{ {
@ -273,7 +272,7 @@ BOOL InitWaveData100()
} }
//Create org wave //Create org wave
bool MakeOrganyaWave(int8_t track, int8_t wave_no, int8_t pipi) bool MakeOrganyaWave(signed char track, signed char wave_no, signed char pipi)
{ {
if(wave_no > 99) if(wave_no > 99)
{ {
@ -287,17 +286,17 @@ bool MakeOrganyaWave(int8_t track, int8_t wave_no, int8_t pipi)
} }
//Dram //Dram
void ChangeDramFrequency(uint8_t key, int8_t track) void ChangeDramFrequency(unsigned char key, signed char track)
{ {
lpDRAMBUFFER[track]->SetFrequency(key * 800 + 100); lpDRAMBUFFER[track]->SetFrequency(key * 800 + 100);
} }
void ChangeDramPan(uint8_t pan, int8_t track) void ChangeDramPan(unsigned char pan, signed char track)
{ {
lpDRAMBUFFER[track]->SetPan((pan_tbl[pan] - 0x100) * 10); lpDRAMBUFFER[track]->SetPan((pan_tbl[pan] - 0x100) * 10);
} }
void ChangeDramVolume(int32_t volume, int8_t track) void ChangeDramVolume(long volume, signed char track)
{ {
lpDRAMBUFFER[track]->SetVolume((volume - 0xFF) * 8); lpDRAMBUFFER[track]->SetVolume((volume - 0xFF) * 8);
} }
@ -324,9 +323,9 @@ void PlayDramObject(unsigned char key, int mode, signed char track)
} }
//Play data //Play data
int32_t play_p; long play_p;
NOTELIST *play_np[MAXTRACK]; NOTELIST *play_np[MAXTRACK];
int32_t now_leng[MAXMELODY] = {0}; long now_leng[MAXMELODY] = {0};
void OrganyaPlayData() void OrganyaPlayData()
{ {
@ -393,7 +392,7 @@ void OrganyaPlayData()
} }
} }
void SetPlayPointer(int32_t x) void SetPlayPointer(long x)
{ {
for (int i = 0; i < MAXTRACK; i++) for (int i = 0; i < MAXTRACK; i++)
{ {
@ -428,7 +427,7 @@ void LoadOrganya(const char *name)
const unsigned char *p = FindResource(name, "ORG", NULL); const unsigned char *p = FindResource(name, "ORG", NULL);
//Version Check //Version Check
uint8_t ver = 0; unsigned char ver = 0;
char pass_check[6]; char pass_check[6];
memcpy(pass_check, p, 6); memcpy(pass_check, p, 6);
@ -454,7 +453,7 @@ void LoadOrganya(const char *name)
for (int i = 0; i < 16; i++) { for (int i = 0; i < 16; i++) {
info.tdata[i].freq = READ_LE16(p); info.tdata[i].freq = READ_LE16(p);
info.tdata[i].wave_no = *p++; info.tdata[i].wave_no = *p++;
const int8_t pipi = *p++; const signed char pipi = *p++;
info.tdata[i].pipi = ver == 1 ? 0 : pipi; info.tdata[i].pipi = ver == 1 ? 0 : pipi;
info.tdata[i].note_num = READ_LE16(p); info.tdata[i].note_num = READ_LE16(p);
} }
@ -586,7 +585,7 @@ int OrganyaPlayTimer(void *ptr)
SDL_SetThreadPriority(SDL_THREAD_PRIORITY_HIGH); SDL_SetThreadPriority(SDL_THREAD_PRIORITY_HIGH);
//Set time for next step to play //Set time for next step to play
uint32_t NextTick = SDL_GetTicks() + info.wait; Uint32 NextTick = SDL_GetTicks() + info.wait;
while (bEndTimer == false) while (bEndTimer == false)
{ {

View file

@ -1,13 +1,11 @@
#pragma once #pragma once
#include <stdint.h>
//Below are Organya song data structures //Below are Organya song data structures
struct NOTELIST { struct NOTELIST {
NOTELIST *from; //Previous address NOTELIST *from; //Previous address
NOTELIST *to; //Next address NOTELIST *to; //Next address
int32_t x; //Position long x; //Position
unsigned char length; //Sound length unsigned char length; //Sound length
unsigned char y; //Sound height unsigned char y; //Sound height
unsigned char volume; //Volume unsigned char volume; //Volume
@ -16,10 +14,10 @@ struct NOTELIST {
//Track data * 8 //Track data * 8
struct TRACKDATA { struct TRACKDATA {
uint16_t freq; //Frequency (1000 is default) unsigned short freq; //Frequency (1000 is default)
uint8_t wave_no; //Waveform No. unsigned char wave_no; //Waveform No.
int8_t pipi; signed char pipi;
uint16_t note_num; //Number of notes unsigned short note_num; //Number of notes
NOTELIST *note_p; NOTELIST *note_p;
NOTELIST *note_list; NOTELIST *note_list;
@ -27,20 +25,20 @@ struct TRACKDATA {
//Unique information held in songs //Unique information held in songs
struct MUSICINFO { struct MUSICINFO {
uint16_t wait; unsigned short wait;
bool loaded; bool loaded;
bool playing; bool playing;
unsigned char line; //Number of lines in one measure unsigned char line; //Number of lines in one measure
unsigned char dot; //Number of dots per line unsigned char dot; //Number of dots per line
uint16_t alloc_note; //Number of allocated notes unsigned short alloc_note; //Number of allocated notes
int32_t repeat_x; //Repeat long repeat_x; //Repeat
int32_t end_x; //End of song (Return to repeat) long end_x; //End of song (Return to repeat)
TRACKDATA tdata[16]; TRACKDATA tdata[16];
}; };
bool MakeOrganyaWave(int8_t track, int8_t wave_no, int8_t pipi); bool MakeOrganyaWave(signed char track, signed char wave_no, signed char pipi);
void OrganyaPlayData(); void OrganyaPlayData();
void SetPlayPointer(int32_t x); void SetPlayPointer(long x);
void LoadOrganya(const char *name); void LoadOrganya(const char *name);
void SetOrganyaPosition(unsigned int x); void SetOrganyaPosition(unsigned int x);
unsigned int GetOrganyaPosition(); unsigned int GetOrganyaPosition();

View file

@ -1,7 +1,6 @@
#include "Profile.h" #include "Profile.h"
#include <stddef.h> #include <stddef.h>
#include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>

View file

@ -1,7 +1,5 @@
#pragma once #pragma once
#include <stdint.h>
#include "WindowsWrapper.h" #include "WindowsWrapper.h"
#include "ArmsItem.h" #include "ArmsItem.h"
@ -15,10 +13,10 @@ struct PROFILE
int x; int x;
int y; int y;
int direct; int direct;
int16_t max_life; short max_life;
int16_t star; short star;
int16_t life; short life;
int16_t a; short a;
int select_arms; int select_arms;
int select_item; int select_item;
int equip; int equip;
@ -29,7 +27,7 @@ struct PROFILE
PERMIT_STAGE permitstage[8]; PERMIT_STAGE permitstage[8];
signed char permit_mapping[0x80]; signed char permit_mapping[0x80];
char FLAG[4]; char FLAG[4];
uint8_t flags[1000]; unsigned char flags[1000];
}; };
BOOL IsProfile(); BOOL IsProfile();

View file

@ -2,7 +2,6 @@
#include <algorithm> #include <algorithm>
#include <cmath> #include <cmath>
#include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <string> #include <string>
#include <cstring> #include <cstring>
@ -48,7 +47,7 @@ SOUNDBUFFER::SOUNDBUFFER(size_t bufSize)
samplePosition = 0.0; samplePosition = 0.0;
//Create waveform buffer //Create waveform buffer
data = new uint8_t[bufSize]; data = new unsigned char[bufSize];
memset(data, 0x80, bufSize); memset(data, 0x80, bufSize);
//Add to buffer list //Add to buffer list
@ -88,7 +87,7 @@ void SOUNDBUFFER::Release()
delete this; delete this;
} }
void SOUNDBUFFER::Lock(uint8_t **outBuffer, size_t *outSize) void SOUNDBUFFER::Lock(unsigned char **outBuffer, size_t *outSize)
{ {
SDL_LockAudioDevice(audioDevice); SDL_LockAudioDevice(audioDevice);
@ -104,35 +103,35 @@ void SOUNDBUFFER::Unlock()
SDL_UnlockAudioDevice(audioDevice); SDL_UnlockAudioDevice(audioDevice);
} }
void SOUNDBUFFER::SetCurrentPosition(uint32_t dwNewPosition) void SOUNDBUFFER::SetCurrentPosition(unsigned long dwNewPosition)
{ {
SDL_LockAudioDevice(audioDevice); SDL_LockAudioDevice(audioDevice);
samplePosition = dwNewPosition; samplePosition = dwNewPosition;
SDL_UnlockAudioDevice(audioDevice); SDL_UnlockAudioDevice(audioDevice);
} }
void SOUNDBUFFER::SetFrequency(uint32_t dwFrequency) void SOUNDBUFFER::SetFrequency(unsigned long dwFrequency)
{ {
SDL_LockAudioDevice(audioDevice); SDL_LockAudioDevice(audioDevice);
frequency = (double)dwFrequency; frequency = (double)dwFrequency;
SDL_UnlockAudioDevice(audioDevice); SDL_UnlockAudioDevice(audioDevice);
} }
float MillibelToVolume(int32_t lVolume) float MillibelToVolume(long lVolume)
{ {
//Volume is in hundredths of decibels, from 0 to -10000 //Volume is in hundredths of decibels, from 0 to -10000
lVolume = clamp(lVolume, (int32_t)-10000, (int32_t)0); lVolume = clamp(lVolume, (long)-10000, (long)0);
return (float)pow(10.0, lVolume / 2000.0); return (float)pow(10.0, lVolume / 2000.0);
} }
void SOUNDBUFFER::SetVolume(int32_t lVolume) void SOUNDBUFFER::SetVolume(long lVolume)
{ {
SDL_LockAudioDevice(audioDevice); SDL_LockAudioDevice(audioDevice);
volume = MillibelToVolume(lVolume); volume = MillibelToVolume(lVolume);
SDL_UnlockAudioDevice(audioDevice); SDL_UnlockAudioDevice(audioDevice);
} }
void SOUNDBUFFER::SetPan(int32_t lPan) void SOUNDBUFFER::SetPan(long lPan)
{ {
SDL_LockAudioDevice(audioDevice); SDL_LockAudioDevice(audioDevice);
volume_l = MillibelToVolume(-lPan); volume_l = MillibelToVolume(-lPan);
@ -288,19 +287,19 @@ void PlaySoundObject(int no, int mode)
} }
} }
void ChangeSoundFrequency(int no, uint32_t rate) void ChangeSoundFrequency(int no, unsigned long rate)
{ {
if (lpSECONDARYBUFFER[no]) if (lpSECONDARYBUFFER[no])
lpSECONDARYBUFFER[no]->SetFrequency(10 * rate + 100); lpSECONDARYBUFFER[no]->SetFrequency(10 * rate + 100);
} }
void ChangeSoundVolume(int no, int32_t volume) void ChangeSoundVolume(int no, long volume)
{ {
if (lpSECONDARYBUFFER[no]) if (lpSECONDARYBUFFER[no])
lpSECONDARYBUFFER[no]->SetVolume(8 * volume - 2400); lpSECONDARYBUFFER[no]->SetVolume(8 * volume - 2400);
} }
void ChangeSoundPan(int no, int32_t pan) void ChangeSoundPan(int no, long pan)
{ {
if (lpSECONDARYBUFFER[no]) if (lpSECONDARYBUFFER[no])
lpSECONDARYBUFFER[no]->SetPan(10 * (pan - 256)); lpSECONDARYBUFFER[no]->SetPan(10 * (pan - 256));

View file

@ -1,7 +1,6 @@
#pragma once #pragma once
#include <stddef.h> #include <stddef.h>
#include <stdint.h>
#include "PixTone.h" #include "PixTone.h"
@ -13,13 +12,13 @@ class SOUNDBUFFER
void Release(); void Release();
void Lock(uint8_t **buffer, size_t *size); void Lock(unsigned char **buffer, size_t *size);
void Unlock(); void Unlock();
void SetCurrentPosition(uint32_t dwNewPosition); void SetCurrentPosition(unsigned long dwNewPosition);
void SetFrequency(uint32_t dwFrequency); void SetFrequency(unsigned long dwFrequency);
void SetVolume(int32_t lVolume); void SetVolume(long lVolume);
void SetPan(int32_t lPan); void SetPan(long lPan);
void Play(bool bLooping); void Play(bool bLooping);
void Stop(); void Stop();
@ -28,7 +27,7 @@ class SOUNDBUFFER
SOUNDBUFFER *next; SOUNDBUFFER *next;
private: private:
uint8_t *data; unsigned char *data;
size_t size; size_t size;
bool playing; bool playing;
@ -95,7 +94,7 @@ extern SOUNDBUFFER* lpSECONDARYBUFFER[SOUND_NO];
bool InitDirectSound(); bool InitDirectSound();
void EndDirectSound(); void EndDirectSound();
void PlaySoundObject(int no, int mode); void PlaySoundObject(int no, int mode);
void ChangeSoundFrequency(int no, uint32_t rate); void ChangeSoundFrequency(int no, unsigned long rate);
void ChangeSoundVolume(int no, int32_t volume); void ChangeSoundVolume(int no, long volume);
void ChangeSoundPan(int no, int32_t pan); void ChangeSoundPan(int no, long pan);
int MakePixToneObject(const PIXTONEPARAMETER *ptp, int ptp_num, int no); int MakePixToneObject(const PIXTONEPARAMETER *ptp, int ptp_num, int no);

View file

@ -1,6 +1,5 @@
#include "Stage.h" #include "Stage.h"
#include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>

View file

@ -1,6 +1,5 @@
#include "TextScr.h" #include "TextScr.h"
#include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -91,7 +90,7 @@ void EndTextScript()
} }
//Decrypt .tsc //Decrypt .tsc
void EncryptionBinaryData2(uint8_t *pData, int size) void EncryptionBinaryData2(unsigned char *pData, int size)
{ {
int val1; int val1;
@ -136,7 +135,7 @@ BOOL LoadTextScript2(const char *name)
strcpy(gTS.path, name); strcpy(gTS.path, name);
//Decrypt data //Decrypt data
EncryptionBinaryData2((uint8_t*)gTS.data, gTS.size); EncryptionBinaryData2((unsigned char*)gTS.data, gTS.size);
return TRUE; return TRUE;
} }
@ -157,7 +156,7 @@ BOOL LoadTextScript_Stage(const char *name)
//Read Head.tsc //Read Head.tsc
fread(gTS.data, 1, head_size, fp); fread(gTS.data, 1, head_size, fp);
EncryptionBinaryData2((uint8_t*)gTS.data, head_size); EncryptionBinaryData2((unsigned char*)gTS.data, head_size);
gTS.data[head_size] = 0; gTS.data[head_size] = 0;
fclose(fp); fclose(fp);
@ -174,7 +173,7 @@ BOOL LoadTextScript_Stage(const char *name)
//Read stage's tsc //Read stage's tsc
fread(&gTS.data[head_size], 1, body_size, fp); fread(&gTS.data[head_size], 1, body_size, fp);
EncryptionBinaryData2((uint8_t*)&gTS.data[head_size], body_size); EncryptionBinaryData2((unsigned char*)&gTS.data[head_size], body_size);
gTS.data[head_size + body_size] = 0; gTS.data[head_size + body_size] = 0;
fclose(fp); fclose(fp);

View file

@ -1,7 +1,5 @@
#pragma once #pragma once
#include <stdint.h>
#include "WindowsWrapper.h" #include "WindowsWrapper.h"
#include "CommonDefines.h" #include "CommonDefines.h"
@ -54,12 +52,12 @@ struct TEXT_SCRIPT
int offsetY; int offsetY;
//NOD cursor blink //NOD cursor blink
uint8_t wait_beam; unsigned char wait_beam;
}; };
BOOL InitTextScript2(); BOOL InitTextScript2();
void EndTextScript(); void EndTextScript();
void EncryptionBinaryData2(uint8_t *pData, int size); void EncryptionBinaryData2(unsigned char *pData, int size);
BOOL LoadTextScript2(const char *name); BOOL LoadTextScript2(const char *name);
BOOL LoadTextScript_Stage(const char *name); BOOL LoadTextScript_Stage(const char *name);
void GetTextScriptPath(char *path); void GetTextScriptPath(char *path);

View file

@ -1,10 +1,9 @@
#include "Triangle.h" #include "Triangle.h"
#include <stdint.h>
#include <math.h> #include <math.h>
int gSin[0x100]; int gSin[0x100];
int16_t gTan[0x21]; short gTan[0x21];
void InitTriangleTable() void InitTriangleTable()
{ {
@ -23,27 +22,27 @@ void InitTriangleTable()
{ {
a = (float)(i * 6.2831855f / 256.0f); a = (float)(i * 6.2831855f / 256.0f);
b = sinf(a) / cosf(a); b = sinf(a) / cosf(a);
gTan[i] = (int16_t)(b * 8192.0f); gTan[i] = (short)(b * 8192.0f);
} }
} }
int GetSin(uint8_t deg) int GetSin(unsigned char deg)
{ {
return gSin[deg]; return gSin[deg];
} }
int GetCos(uint8_t deg) int GetCos(unsigned char deg)
{ {
deg += 0x40; deg += 0x40;
return gSin[deg]; return gSin[deg];
} }
uint8_t GetArktan(int x, int y) unsigned char GetArktan(int x, int y)
{ {
x *= -1; x *= -1;
y *= -1; y *= -1;
uint8_t a = 0; unsigned char a = 0;
int16_t k; short k;
if (x > 0) if (x > 0)
{ {

View file

@ -1,8 +1,6 @@
#pragma once #pragma once
#include <stdint.h>
void InitTriangleTable(); void InitTriangleTable();
int GetSin(uint8_t deg); int GetSin(unsigned char deg);
int GetCos(uint8_t deg); int GetCos(unsigned char deg);
uint8_t GetArktan(int x, int y); unsigned char GetArktan(int x, int y);