Skip to content

Commit

Permalink
Merge pull request #166 from mateusfavarin/main
Browse files Browse the repository at this point in the history
New reserve bar, fix checkpoints not resetting properly, fix engine revving
  • Loading branch information
mateusfavarin authored Jun 29, 2024
2 parents 15f2f57 + 873e212 commit 804b89c
Show file tree
Hide file tree
Showing 9 changed files with 234 additions and 110 deletions.
15 changes: 15 additions & 0 deletions decompile/General/AltMods/Mods1.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,21 @@
#include "OnlineCTR/debugcam.c"
#include "OnlineCTR/lapData.c"
#include "OnlineCTR/names3d.c"

void StatsUpgrade()
{
/*
Stat 9 is acceleration,
Stats 11 and 12 speed related
*/
for (int i = 9; i < 13; i++)
{
for (int j = 0; j < 4; j++)
{
data.metaPhys[i].value[j] = data.metaPhys[i].value[4]; // copy MAX
}
}
}
#endif
#endif

Expand Down
135 changes: 135 additions & 0 deletions decompile/General/AltMods/Mods2.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,140 @@
// used for 16x9 (part 1)
// used for oxide
#include <common.h>

#ifdef USE_ONLINE
Color HsvToRgb(int h, int s, int v);
#endif

#ifdef USE_BOOSTBAR
void DrawBoostBar(short posX, short posY, struct Driver* driver)
{
#ifdef USE_ONLINE
const int numberBarDivisions = 5;
const Color barEmptyColor = MakeColor(0x80, 0x80, 0x80);
#endif

struct GameTracker * gGT = sdata->gGT;
short fullHeight = 3;
#ifdef USE_ONLINE
short fullWidth = WIDE_34(96);
int numBarsFilled = driver->reserves / SECONDS(1);
int numFullBarsFilled = driver->reserves / SECONDS(5);
int reserveLength = driver->reserves % SECONDS(5);
int meterLength = (fullWidth * reserveLength) / SECONDS(5);
posX += 35;
#else
short fullWidth = WIDE_34(49);
short meterLength = ((driver->reserves * 0xE)/0x960);
if ((meterLength > fullWidth) || (driver->reserves < 0)) { meterLength = fullWidth; }
#endif

RECT box;
short topX = posX - fullWidth;
short topY = posY - fullHeight;
box.x = topX;
box.y = topY;
box.w = fullWidth;
box.h = fullHeight;

struct DB * backDB = gGT->backBuffer;

DECOMP_CTR_Box_DrawWireBox(&box, MakeColor(0, 0, 0), gGT->pushBuffer_UI.ptrOT);

#ifdef USE_ONLINE
int spacing = fullWidth / numberBarDivisions;
int remainder = fullWidth % numberBarDivisions;
for (int i = 0; i < numberBarDivisions - 1; i++)
{
LineF2 * p;
GetPrimMem(p);
if (p == nullptr) { return; }

const PrimCode primCode = { .line = { .renderCode = RenderCode_Line } };
const Color colorCode = MakeColorCode(0, 0, 0, primCode);
p->colorCode = colorCode;
s16 xPos = posX - (spacing * (i + 1));
if (remainder > 0) { xPos--; remainder--; }
p->v[0].pos.x = xPos;
p->v[0].pos.y = topY;
p->v[1].pos.x = xPos;
p->v[1].pos.y = topY + fullHeight;
AddPrimitive(p, gGT->pushBuffer_UI.ptrOT);
}
#endif

const PrimCode primCode = { .poly = { .quad = 1, .renderCode = RenderCode_Polygon } };

#ifdef USE_ONLINE
char barNumberStr[2];
int strLen = 2;
if (numFullBarsFilled < 10)
{
barNumberStr[0] = (numFullBarsFilled % 10) + '0';
strLen--;
}
else
{
barNumberStr[0] = (numFullBarsFilled / 10) + '0';
barNumberStr[1] = (numFullBarsFilled % 10) + '0';
}
DECOMP_DecalFont_DrawLineStrlen(barNumberStr, strLen, topX - 2, topY - 3, FONT_SMALL, PENTA_WHITE | JUSTIFY_RIGHT);

ColorCode colorCode;
ColorCode bgBarColor = barEmptyColor;
if (numFullBarsFilled > 0) { bgBarColor = HsvToRgb(5 * numberBarDivisions * (numFullBarsFilled - 1), (int)(255 * 0.5), (int)(255 * 0.5)); }
colorCode = HsvToRgb(5 * numBarsFilled, (int)(255 * 0.9), (int)(255 * 1.0));
colorCode.code = primCode;
bgBarColor.code = primCode;
#else
/* === BoostBar ===
red: 0-2s
yellow: 2s-4s
green: 4s-full
blue: full-saffi
purple: saffi */
ColorCode colorCode = MakeColorCode(0xFF, 0, 0, primCode); // red
if (driver->reserves < 0) {
colorCode = MakeColorCode(0xFF, 0x0, 0xFF, primCode); // purple
}
else if (meterLength == fullWidth) {
colorCode = MakeColorCode(0, 0, 0xFF, primCode); // blue
}
else if (driver->reserves >= SECONDS(4)) {
colorCode = MakeColorCode(0, 0xFF, 0, primCode); // green
}
else if (driver->reserves >= SECONDS(2)) {
colorCode = MakeColorCode(0xFF, 0xFF, 0, primCode); // yellow
}
#endif

for (int i = 0; i < 2; i++)
{
PolyF4 * p;
GetPrimMem(p);
if (p == nullptr) { return; }

p->colorCode = colorCode;
p->v[0].pos.x = posX - meterLength;
p->v[0].pos.y = topY;
p->v[1].pos.x = posX;
p->v[1].pos.y = topY;
p->v[2].pos.x = posX - meterLength;
p->v[2].pos.y = posY;
p->v[3].pos.x = posX;
p->v[3].pos.y = posY;
AddPrimitive(p, gGT->pushBuffer_UI.ptrOT);

#ifdef USE_ONLINE
colorCode = bgBarColor;
#else
colorCode = MakeColorCode(0x80, 0x80, 0x80, primCode); // Gray color for Prim #2
#endif
meterLength = fullWidth;
}
}
#endif

#ifdef USE_16BY9
void ui16by9_ViewProj(struct PushBuffer* pb)
{
Expand Down
90 changes: 0 additions & 90 deletions decompile/General/AltMods/Mods4.c
Original file line number Diff line number Diff line change
@@ -1,90 +0,0 @@
#include <common.h>

#ifdef USE_ONLINE
void StatsUpgrade()
{
/*
Stat 9 is acceleration,
Stats 11 and 12 speed related
*/
for (int i = 9; i < 13; i++)
{
for (int j = 0; j < 4; j++)
{
data.metaPhys[i].value[j] = data.metaPhys[i].value[4]; // copy MAX
}
}
}
#endif

#ifdef USE_BOOSTBAR
void DrawBoostBar(short posX, short posY, struct Driver* driver)
{
struct GameTracker * gGT = sdata->gGT;

short fullHeight = 3;
int fullWidth = WIDE_34(49);

short meterLength = ((driver->reserves * 0xE)/0x960);
if ((meterLength > fullWidth) || (driver->reserves < 0)) { meterLength = fullWidth; }

RECT box;
box.x = posX - fullWidth;
box.y = posY - fullHeight;
box.w = fullWidth;
box.h = fullHeight;

struct DB * backDB = gGT->backBuffer;

DECOMP_CTR_Box_DrawWireBox(
&box, MakeColor(0, 0, 0),
gGT->pushBuffer_UI.ptrOT);

int topY = posY - fullHeight;

/* === BoostBar ===
red: 0-2s
yellow: 2s-4s
green: 4s-full
blue: full-saffi
purple: saffi */

PrimCode primCode = { .poly = { .quad = 1, .renderCode = RenderCode_Polygon } };
ColorCode colorCode = MakeColorCode(0xFF, 0, 0, primCode); // red

if (driver->reserves < 0) {
colorCode = MakeColorCode(0xFF, 0x0, 0xFF, primCode); // purple
}
else if (meterLength == fullWidth) {
colorCode = MakeColorCode(0, 0, 0xFF, primCode); // blue
}
else if (driver->reserves >= SECONDS(4)) {
colorCode = MakeColorCode(0, 0xFF, 0, primCode); // green
}
else if (driver->reserves >= SECONDS(2)) {
colorCode = MakeColorCode(0xFF, 0xFF, 0, primCode); // yellow
}

for (int i = 0; i < 2; i++)
{
PolyF4 * p;
GetPrimMem(p);
if (p == nullptr) { return; }

p->colorCode = colorCode;
p->v[0].pos.x = posX - meterLength;
p->v[0].pos.y = topY;
p->v[1].pos.x = posX;
p->v[1].pos.y = topY;
p->v[2].pos.x = posX - meterLength;
p->v[2].pos.y = posY;
p->v[3].pos.x = posX;
p->v[3].pos.y = posY;
AddPrimitive(p, gGT->pushBuffer_UI.ptrOT);

// Gray color for Prim #2
colorCode = MakeColorCode(0x80, 0x80, 0x80, primCode);
meterLength = fullWidth;
}
}
#endif
50 changes: 50 additions & 0 deletions decompile/General/AltMods/Mods7.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#ifdef USE_BOOSTBAR
#ifdef USE_ONLINE

Color HsvToRgb(int h, int s, int v)
{
Color rgb;
h = h & 0xFF; // modulo 256
int region, remainder, p, q, t;

if (s == 0)
{
rgb.r = v;
rgb.g = v;
rgb.b = v;
return rgb;
}

region = h / 43;
remainder = (h - (region * 43)) * 6;

p = (v * (255 - s)) >> 8;
q = (v * (255 - ((s * remainder) >> 8))) >> 8;
t = (v * (255 - ((s * (255 - remainder)) >> 8))) >> 8;

switch (region)
{
case 0:
rgb.r = v; rgb.g = t; rgb.b = p;
break;
case 1:
rgb.r = q; rgb.g = v; rgb.b = p;
break;
case 2:
rgb.r = p; rgb.g = v; rgb.b = t;
break;
case 3:
rgb.r = p; rgb.g = q; rgb.b = v;
break;
case 4:
rgb.r = t; rgb.g = p; rgb.b = v;
break;
default:
rgb.r = v; rgb.g = p; rgb.b = q;
break;
}

return rgb;
}
#endif
#endif
27 changes: 14 additions & 13 deletions decompile/General/AltMods/OnlineCTR/states.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,11 @@ void StatePS1_Lobby_WaitForLoading()
FONT_SMALL,JUSTIFY_CENTER|ORANGE);
}

static bool initRace = true;

void StatePS1_Lobby_StartLoading()
{
initRace = true;
PrintCharacterStats();
PrintRecvTrack();

Expand Down Expand Up @@ -295,7 +298,6 @@ static void Ghostify()

extern struct CheckpointTracker checkpointTracker[8];
extern unsigned int checkpointTimes[(MAX_LAPS * CPS_PER_LAP) + 1];
static bool initRace = true;
extern int bestLap;

static void OnRaceInit()
Expand Down Expand Up @@ -348,7 +350,7 @@ void StatePS1_Game_WaitForRace()

DECOMP_RECTMENU_DrawInnerRect(
&drawTimeRECT, 1, gGT->backBuffer->otMem.startPlusFour);

for(i = 0; i < 8; i++)
{
octr->Shoot[i].boolNow = 0;
Expand All @@ -361,26 +363,26 @@ void StatePS1_Game_StartRace()
{
int i;
Ghostify();

for(i = 1; i < 8; i++)
{
if(octr->Shoot[i].boolNow != 0)
{
octr->Shoot[i].boolNow = 0;

struct Driver* d = sdata->gGT->drivers[i];

if(octr->Shoot[i].boolJuiced)
d->numWumpas = 10;

d->heldItemID = octr->Shoot[i].Weapon;

// copy/paste from ShootOnCirclePress
int weapon;
weapon = d->heldItemID;

// Missiles and Bombs share code,
// Change Bomb1x, Bomb3x, Missile3x, to Missile1x
// Change Bomb1x, Bomb3x, Missile3x, to Missile1x
if(
(weapon == 1) ||
(weapon == 10) ||
Expand All @@ -389,16 +391,15 @@ void StatePS1_Game_StartRace()
{
weapon = 2;
}

DECOMP_VehPickupItem_ShootNow(
d,
weapon,
d,
weapon,
octr->Shoot[i].flags);
}
}
}

void StatePS1_Game_EndRace()
{
initRace = true;
}
Loading

0 comments on commit 804b89c

Please sign in to comment.