Rephrase eight matched functions; drop index casts and magic numbers

Re-land eight already-matching functions in more idiomatic C. Every one was
verified at score 0 in each region it has a target for BEFORE landing, and by
a matching US build AFTER landing, one function at a time.

  CreateGridCellConnections  320 -> 278   eight (u32) index casts removed
  GenerateExtraHallways      170 -> 161   terrain_flags & 3 -> GetTerrainType
  ActivateEndOfTurnEffects   538 -> 533   MAX_HP_LIMIT for the 999 literals
  ApplyDamageAndEffects      316 -> 314
  CalcDamage                 635 -> 631   one volatile local dropped
  ApplyDamage                807 -> 818
  ov11_022ED69C              242 -> 240   const void * -> typed pointers
  ov11_02307334              733 -> 735   three redundant (u8 *) casts dropped

The CreateGridCellConnections index casts had been recorded as load-bearing.
They are not. MWCC keys common-subexpression elimination on the address
expression INCLUDING integer conversion nodes, so an `int` alias of an `s32`
index splits the use-set exactly as a cast does, while a same-type copy is
erased by copy propagation. An identity (s32) cast is byte-identical to the
(u32) one, and casting every site is byte-identical to casting none, which is
what shows the lever is the split rather than the cast.

overlay_29_0233C9E8.c gains #include "dungeon.h" and "dungeon_util_static.h"
for TERRAIN_TYPE_*, DUNGEON_MAX_SIZE_* and GetTerrainType. All three were
already in the tree; no name is introduced here.

Three candidate rephrasings were rejected on measurement and are not included:
one scored 1195 in EUROPE against a landed baseline of 10, one carried an
artificial `damage_data++; damage_data--;` pair, and one did not match at all.

Authored by Claude (Opus 5) under human direction. Confirmed by a matching
build after each individual change: build/pmdsky.us/pmdsky.us.nds: OK.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
cecilarmitais
2026-09-12 00:47:37 -07:00
parent 4c7fe63636
commit dae72255ff
7 changed files with 582 additions and 631 deletions

View File

@@ -14,9 +14,8 @@ bool8 ov11_022ED69C(GroundBg *dst, GroundBg *src)
u16 *p1;
s32 i2;
s32 j2;
s32 idx;
struct UnkStruct_2324CBC_Sub98 *unkSubPtr;
const void *data1;
const u8 *data1;
const RGB_Array *rgb;
const AnimationSpecification *spec;
MapRender *render1;
@@ -25,7 +24,6 @@ bool8 ov11_022ED69C(GroundBg *dst, GroundBg *src)
BplHeader *bpl2;
BmaHeader *bma1;
BmaHeader *bma2;
u16 v1;
if (src->unk1BE == -1) {
ov11_022EC08C(dst);
@@ -69,8 +67,8 @@ bool8 ov11_022ED69C(GroundBg *dst, GroundBg *src)
bma1->hasCollision = bma2->hasCollision;
unkSubPtr = &ov11_02324CBC->unk98[dst->unk2BC.unk0];
v1 = dst->unk2BC.unk6 * 16;
rgb = data1 + 4;
u16 v1 = dst->unk2BC.unk6 * 16;
rgb = (const RGB_Array *)(data1 + 4);
for (i = 0; i < bpl1->numPalettes && i < dst->unk2BC.unk8; i++) {
CopyColorToPaletteDataRgba(unkSubPtr, v1++, &ov11_02320BF4);
FillPaletteDataRgba(unkSubPtr, v1, rgb, 15);
@@ -93,11 +91,9 @@ bool8 ov11_022ED69C(GroundBg *dst, GroundBg *src)
if (bpl1->hasPalAnimations) {
s32 v2 = bpl1->numPalettes * 15;
const void *data2;
spec = data1 + 4 + v2 * 4;
data2 = spec + bpl1->numPalettes;
rgb = data2;
spec = (const AnimationSpecification *)(data1 + 4 + v2 * 4);
rgb = (const RGB_Array *)(spec + bpl1->numPalettes);
dst->animationSpecifications = spec;
dst->unk1FB = 1;
dst->unk1BC = 0;
@@ -173,7 +169,7 @@ bool8 ov11_022ED69C(GroundBg *dst, GroundBg *src)
if (bpaName[0] != 0) {
struct BpaHeader *bpa;
s32 *p3;
void *p4;
u16 *p4;
s32 v6;
dstC4->bpaFile = srcC4->bpaFile;
@@ -183,9 +179,11 @@ bool8 ov11_022ED69C(GroundBg *dst, GroundBg *src)
dstC4->unk10 = bpa;
p3 = &bpa->durationPerFrame[0];
v6 = bpa->numFrames;
dstC4->unk14 = dstC4->unk18 = p3;
p4 = p3 + v6;
dstC4->unk1C = dstC4->unk20 = p4;
dstC4->unk18 = p3;
dstC4->unk14 = p3;
p4 = (u16 *)(p3 + v6);
dstC4->unk20 = p4;
dstC4->unk1C = p4;
dstC4->unk2 = 0;
dstC4->unk4 = *dstC4->unk18;
dstC4->unk24 = p1;
@@ -221,7 +219,7 @@ bool8 ov11_022ED69C(GroundBg *dst, GroundBg *src)
render2 = dst->mapRender;
for (i = 0; i < dst->unk1FC; i++, render2++, render1++) {
*render2 = *render1;
idx = render2->unk2;
s32 idx = render2->unk2;
for (j = 0; j < render2->numBgs && idx < dst->unk2BC.numLayers;
j++, idx++) {

View File

@@ -166,15 +166,10 @@ s32 ov11_02307334(void)
struct struct_2 menu_b;
struct struct_2 menu_a;
struct preprocessor_args args;
char buf[0x400];
struct unk_02309DAC sel_18;
struct unk_02309DAC sel_10;
u16 btn_e;
u16 btn_c;
switch (ov11_02324D8C->field_0x0) {
case 0: {
ov11_02324D8C->field_0x4 = CreateInventoryMenuOuter(GetNbItemsInBag(), 0, ov11_02324D8C->field_0x10, ov11_02324D8C->field_0x104, (void *)ov11_02307300, ov11_02324D8C->field_0x31c, 0);
ov11_02324D8C->field_0x4 = CreateInventoryMenuOuter(GetNbItemsInBag(), 0, ov11_02324D8C->field_0x10, ov11_02324D8C->field_0x104, ov11_02307300, ov11_02324D8C->field_0x31c, 0);
ov11_02324D8C->field_0x5 = CreateTextBox(&ov11_02322C88, 0);
ov11_02324D8C->field_0x18 = -1;
ov11_02324D8C->field_0x0 = 1;
@@ -191,11 +186,13 @@ s32 ov11_02307334(void)
break;
}
case 1: {
u8 v1;
u8 v1;
char buf[0x400];
u16 buttons;
GetPressedButtons(0, &btn_e);
GetPressedButtons(0, &buttons);
v1 = PopInventoryMenuField0x1A3(ov11_02324D8C->field_0x4);
if ((btn_e & 4) || (btn_e & 0x800) || v1) {
if ((buttons & 4) || (buttons & 0x800) || v1) {
if (!v1) {
PlaySeVolumeWrapper(5);
}
@@ -217,14 +214,14 @@ s32 ov11_02307334(void)
sub_02027B1C(v2);
if ((bool8)((v4->flags & 1) != 0)) {
#ifdef EUROPE
strcpy((u8 *)buf, StringFromId((u16)(v4->id + 0x2f4b)));
strcpy(buf, StringFromId((u16)(v4->id + 0x2f4b)));
#elif defined(JAPAN)
strcpy((u8 *)buf, StringFromId((u16)(v4->id + 0x1d41)));
strcpy(buf, StringFromId((u16)(v4->id + 0x1d41)));
#else
strcpy((u8 *)buf, StringFromId((u16)(v4->id + 0x2f49)));
strcpy(buf, StringFromId((u16)(v4->id + 0x2f49)));
#endif
} else {
strcpy((u8 *)buf, ov11_02322DB0);
strcpy(buf, ov11_02322DB0);
}
DrawTextInWindow(v2, 2, 2, buf);
UpdateWindow(v2);
@@ -235,13 +232,15 @@ s32 ov11_02307334(void)
if (v5 >= 0) {
struct item *v6;
bool8 v6f;
s32 v7;
s32 v8;
ov11_02324D8C->field_0x10 = v5;
v6 = GetItemAtIdx(ov11_02324D8C->field_0x10);
ov11_02324D8C->field_0x24e = v6->id;
if ((bool8)((v6->flags & 1) != 0)) {
v6f = (v6->flags & 1) != 0;
if (v6f) {
ov11_02324D8C->field_0x24e = v6->id;
} else {
ov11_02324D8C->field_0x24e = 0;
@@ -259,6 +258,8 @@ s32 ov11_02307334(void)
ov11_02324D8C->field_0x276[i] = 3;
}
break;
default:
break;
}
}
menu_a.c = ov11_02324D8C->field_0x276;
@@ -276,8 +277,10 @@ s32 ov11_02307334(void)
ov11_02324D8C->field_0x0 = 0xe;
}
} else {
GetPressedButtons(0, &btn_c);
if (btn_c & 8) {
u16 pressed;
GetPressedButtons(0, &pressed);
if (pressed & 8) {
PlaySeVolumeWrapper(0);
ov10_022BCDF4(ov11_02324D8C->field_0x4);
ov11_02324D8C->field_0x10 = ov10_022BCDA8(ov11_02324D8C->field_0x4);
@@ -334,6 +337,7 @@ s32 ov11_02307334(void)
break;
}
case 18: {
struct unk_02309DAC sel;
struct unk_02308F4C *v2;
s16 v3;
s32 v4;
@@ -343,8 +347,8 @@ s32 ov11_02307334(void)
}
if (ov11_02309E24() != -1) {
v2 = &ov11_02324D8C->field_0x238;
ov11_02309DAC(&sel_18);
ov11_02308F4C(v2, &sel_18);
ov11_02309DAC(&sel);
ov11_02308F4C(v2, &sel);
ov11_02324D8C->field_0x30c = GetLearnableIqSkills(ov11_02324D8C->field_0x280, v2->field_0x8, *v2->field_0x10);
ov11_02324D8C->field_0x250 = -1;
ov11_02324D8C->field_0x318 = *v2->field_0x10;
@@ -446,7 +450,7 @@ s32 ov11_02307334(void)
ov11_02324D8C->field_0xb4.id_vals[0] = ov11_02324D8C->field_0x314;
sub_02017C50(4);
ov11_02308EDC();
ShowStringIdInDialogueBox(ov11_02324D8C->field_0x8, 0x18, 0x2BF + OV11_02307334_OFFSET, &ov11_02324D8C->field_0xb4);
ShowStringIdInDialogueBox(ov11_02324D8C->field_0x8, 0x18, 0x2bf + OV11_02307334_OFFSET, &ov11_02324D8C->field_0xb4);
EnableIqSkill(ov11_02324D8C->field_0x238.field_0xc, (u8)ov11_02324D8C->field_0x314);
ov11_02308FD0(&ov11_02324D8C->field_0x238);
ov11_02324D8C->field_0x314++;
@@ -468,19 +472,19 @@ s32 ov11_02307334(void)
v1 = 0;
break;
case 1:
v1 = 0x2C1 + OV11_02307334_OFFSET;
v1 = 0x2c1 + OV11_02307334_OFFSET;
break;
case 2:
v1 = 0x2C2 + OV11_02307334_OFFSET;
v1 = 0x2c2 + OV11_02307334_OFFSET;
break;
case 4:
v1 = 0x2C3 + OV11_02307334_OFFSET;
v1 = 0x2c3 + OV11_02307334_OFFSET;
break;
case 8:
v1 = 0x2C4 + OV11_02307334_OFFSET;
v1 = 0x2c4 + OV11_02307334_OFFSET;
break;
default:
v1 = 0x2C0 + OV11_02307334_OFFSET;
v1 = 0x2c0 + OV11_02307334_OFFSET;
break;
}
if (v1 == 0) {
@@ -488,7 +492,7 @@ s32 ov11_02307334(void)
break;
}
ov11_02308EDC();
ShowStringIdInDialogueBox(ov11_02324D8C->field_0x8, 0x18, 0x2BF + OV11_02307334_OFFSET, &ov11_02324D8C->field_0xb4);
ShowStringIdInDialogueBox(ov11_02324D8C->field_0x8, 0x18, 0x2bf + OV11_02307334_OFFSET, &ov11_02324D8C->field_0xb4);
ov11_02324D8C->field_0x314++;
ov11_02324D8C->field_0x0 = 0x17;
break;
@@ -513,9 +517,10 @@ s32 ov11_02307334(void)
}
if (ov11_02309E24() != -1) {
struct unk_02324D8C *v1 = ov11_02324D8C;
struct unk_02309DAC sel;
ov11_02309DAC(&sel_10);
ov11_02308F4C(&v1->field_0x238, &sel_10);
ov11_02309DAC(&sel);
ov11_02308F4C(&v1->field_0x238, &sel);
ov11_02308FEC(&v1->field_0x238);
if (sub_020415BC()) {
ov11_02324D8C->field_0x0 = 0x1d;
@@ -614,10 +619,8 @@ s32 ov11_02307334(void)
{
s32 v1 = 0x8d7 + OV11_02307334_OFFSET_2;
if (ov11_02324D8C->field_0x24c < 3) {
if (sub_02041364(ov11_02324D8C->field_0x24c)) {
v1--;
}
if (ov11_02324D8C->field_0x24c < 3 && sub_02041364(ov11_02324D8C->field_0x24c)) {
v1 = 0x8d6 + OV11_02307334_OFFSET_2;
}
ov11_02308EDC();
ShowStringIdInDialogueBox(ov11_02324D8C->field_0x8, 0x18, v1, &ov11_02324D8C->field_0xb4);
@@ -879,7 +882,7 @@ s32 ov11_02307334(void)
ov11_02324D8C->field_0x0 = 0xf;
break;
}
case 15: {
case 15:
if (!IsInventoryMenuActive(ov11_02324D8C->field_0x4)) {
CloseTextBox2(ov11_02324D8C->field_0x5);
ov11_02324D8C->field_0x5 = -2;
@@ -887,7 +890,6 @@ s32 ov11_02307334(void)
ov11_02324D8C->field_0x4 = -2;
ov11_02324D8C->field_0x0 = 0x10;
}
}
case 16:
return 1;
}

View File

@@ -222,13 +222,13 @@ int ApplyDamageAndEffects(struct entity *attacker, struct entity *defender,
struct unk_02308FE0 unk1;
struct entity *arr[8];
struct monster *mon1;
s32 v1;
s32 result;
s32 i;
s32 k;
s32 n;
s32 v1;
s32 v2;
bool8 f1;
s32 result;
s32 k;
if ((result = ApplyDamage(attacker, defender, damage_data, a4, a5, a6, a8)) != 0
|| (result = damage_data->field_0x10) != 0) {
@@ -240,11 +240,12 @@ int ApplyDamageAndEffects(struct entity *attacker, struct entity *defender,
if ((result = EntityIsValid__02308FBC(defender)) == 0) {
return result;
}
if ((result = attacker->type) != 1 || (result = defender->type) != 1) {
if ((result = attacker->type) != ENTITY_MONSTER
|| (result = defender->type) != ENTITY_MONSTER) {
return result;
}
if (((struct monster *)defender->info)->bide_class_status.bide == 0xC) {
if (((struct monster *)defender->info)->bide_class_status.bide == STATUS_TWO_TURN_ENRAGED) {
BoostOffensiveStat(attacker, defender, ATK_STAT_IDX, 1);
}
@@ -253,7 +254,7 @@ int ApplyDamageAndEffects(struct entity *attacker, struct entity *defender,
}
if (ov29_02300D50(defender)
|| ((struct monster *)defender->info)->bide_class_status.bide != 0) {
|| ((struct monster *)defender->info)->bide_class_status.bide != STATUS_TWO_TURN_NONE) {
result = FALSE;
} else if (IqSkillIsEnabled(attacker, IQ_HIT_AND_RUNNER)
&& DungeonRandInt(100) < ov10_022C442C) {
@@ -265,7 +266,7 @@ int ApplyDamageAndEffects(struct entity *attacker, struct entity *defender,
result = FALSE;
} else {
if (((struct monster *)defender->info)->reflect_class_status.reflect
== 0xD) {
== STATUS_REFLECT_VITAL_THROW) {
ov29_022E5E84(defender, attacker);
TryHurl(defender, attacker);
}
@@ -283,75 +284,75 @@ int ApplyDamageAndEffects(struct entity *attacker, struct entity *defender,
|| abs(attacker->pos.y - defender->pos.y) > 1) {
result = FALSE;
} else {
ResetDamageData(&unk1);
mon1 = defender->info;
ResetDamageData(&unk1);
mon1 = defender->info;
if (!v2) {
if (mon1->reflect_class_status.reflect == 4) {
ov29_022E3F24(defender);
if (!v2) {
if (mon1->reflect_class_status.reflect == STATUS_REFLECT_COUNTER) {
ov29_022E3F24(defender);
v1 += 4;
}
if (((struct monster *)defender->info)->reflect_class_status.reflect
== STATUS_REFLECT_MINI_COUNTER) {
ov29_022E3F24(defender);
v1 += 1;
}
if (ExclusiveItemEffectIsActive__0230A9B8(defender, EXCLUSIVE_EFF_COUNTER_PHYSICAL_DAMAGE)) {
v1 += 4;
}
if (ExclusiveItemEffectIsActive__0230A9B8(defender, EXCLUSIVE_EFF_COUNTER_25_PCT_PHYSICAL_DAMAGE)) {
v1 += 1;
}
if (IqSkillIsEnabled(defender, IQ_COUNTER_BASHER)
&& ov10_022C44C0 > (s16)DungeonRandInt(100)) {
v1 += 4;
}
if (IqSkillIsEnabled(defender, IQ_COUNTER_HITTER)
&& ov10_022C4464 > (s16)DungeonRandInt(100)) {
v1 += 1;
}
} else if (mon1->reflect_class_status.reflect == STATUS_REFLECT_MIRROR_COAT) {
ov29_022E40C0(defender);
v1 += 4;
}
if (((struct monster *)defender->info)->reflect_class_status.reflect
== 0xA) {
ov29_022E3F24(defender);
v1 += 1;
== STATUS_REFLECT_METAL_BURST) {
ov29_022E57D4(defender);
v1 += 2;
}
if (ExclusiveItemEffectIsActive__0230A9B8(defender, EXCLUSIVE_EFF_COUNTER_PHYSICAL_DAMAGE)) {
v1 += 4;
}
if (ExclusiveItemEffectIsActive__0230A9B8(defender, EXCLUSIVE_EFF_COUNTER_25_PCT_PHYSICAL_DAMAGE)) {
v1 += 1;
}
if (IqSkillIsEnabled(defender, IQ_COUNTER_BASHER)
&& ov10_022C44C0 > (s16)DungeonRandInt(100)) {
v1 += 4;
}
if (IqSkillIsEnabled(defender, IQ_COUNTER_HITTER)
&& ov10_022C4464 > (s16)DungeonRandInt(100)) {
v1 += 1;
}
} else if (mon1->reflect_class_status.reflect == 8) {
ov29_022E40C0(defender);
v1 += 4;
}
if (((struct monster *)defender->info)->reflect_class_status.reflect
== 0xF) {
ov29_022E57D4(defender);
v1 += 2;
}
#ifdef JAPAN
if (DefenderAbilityIsActive__0230A940(attacker, defender, ABILITY_ROUGH_SKIN)) {
if (DefenderAbilityIsActive__0230A940(attacker, defender, ABILITY_ROUGH_SKIN)) {
#else
if (DefenderAbilityIsActive__0230A940(attacker, defender, ABILITY_ROUGH_SKIN, TRUE)) {
if (DefenderAbilityIsActive__0230A940(attacker, defender, ABILITY_ROUGH_SKIN, TRUE)) {
#endif
v1 += 2;
}
if (v1 != 0) {
LogMessageByIdWithPopupCheckUserTarget(attacker, defender, MESSAGE_C3F);
unk1.field_0x0 = damage_data->field_0x0 * v1 / 4;
unk1.field_0xc = damage_data->field_0xc;
unk1.field_0x4 = 6;
unk1.field_0x8 = 2;
unk1.field_0xd = damage_data->field_0xd;
unk1.field_0xe = 0;
unk1.field_0xf = 0;
unk1.field_0x10 = 0;
if (((struct monster *)defender->info)->reflect_class_status.reflect
== 0xF) {
unk1.field_0xd = 1;
n = ov29_023380FC(defender, arr);
for (k = 0; k < n; k = (s16)(k + 1)) {
ApplyDamage(defender, arr[k], &unk1, 0, a5, (s16)a6, a8);
}
} else {
ApplyDamage(defender, attacker, &unk1, 0, a5, (s16)a6, a8);
v1 += 2;
}
if (v1 != 0) {
LogMessageByIdWithPopupCheckUserTarget(attacker, defender, MESSAGE_C3F);
unk1.field_0x0 = damage_data->field_0x0 * v1 / 4;
unk1.field_0xc = damage_data->field_0xc;
unk1.field_0x4 = 6;
unk1.field_0x8 = MATCHUP_NEUTRAL;
unk1.field_0xd = damage_data->field_0xd;
unk1.field_0xe = FALSE;
unk1.field_0xf = FALSE;
unk1.field_0x10 = FALSE;
if (((struct monster *)defender->info)->reflect_class_status.reflect
== STATUS_REFLECT_METAL_BURST) {
unk1.field_0xd = 1;
n = ov29_023380FC(defender, arr);
for (k = 0; k < n; k = (s16)(k + 1)) {
ApplyDamage(defender, arr[k], &unk1, 0, a5, (s16)a6, a8);
}
} else {
ApplyDamage(defender, attacker, &unk1, 0, a5, (s16)a6, a8);
}
}
}
result = IsEitherMonsterInvalid(attacker, defender);
}
@@ -364,141 +365,138 @@ int ApplyDamageAndEffects(struct entity *attacker, struct entity *defender,
|| abs(attacker->pos.y - defender->pos.y) > 1) {
result = FALSE;
} else {
{
s32 v3 = CategoryIsNotPhysical(damage_data->field_0xd);
struct unk_023535DC *ptr1;
struct monster *mon2 = attacker->info;
s32 v3 = CategoryIsNotPhysical(damage_data->field_0xd);
struct unk_023535DC *ptr1;
struct monster *mon2 = attacker->info;
if (ExclusiveItemEffectIsActive__0230A9B8(defender, EXCLUSIVE_EFF_MAY_POISON_PARALYZE_SLEEP_ATTACKERS) && !v3
&& DungeonRandInt(100) < ov10_022C45B4) {
i = DungeonRandInt(300);
if (i < 100) {
ov29_0230F728(attacker, defender, EXCLUSIVE_EFF_MAY_POISON_PARALYZE_SLEEP_ATTACKERS, 0x40);
} else if (i < 200) {
ov29_0230F728(attacker, defender, EXCLUSIVE_EFF_MAY_POISON_PARALYZE_SLEEP_ATTACKERS, 0x10);
} else {
ov29_0230F728(attacker, defender, EXCLUSIVE_EFF_MAY_POISON_PARALYZE_SLEEP_ATTACKERS, 0x80);
}
}
for (ptr1 = ov29_023535DC; *(u8 *)ptr1 != 0; ptr1++) {
if (ExclusiveItemEffectIsActive__0230A9B8(defender, (enum exclusive_item_effect_id)ptr1->field_0x0)
&& ptr1->field_0x8(attacker, defender, v3)) {
ov29_0230F728(attacker, defender, (enum exclusive_item_effect_id)ptr1->field_0x0,
ptr1->field_0x4);
}
}
if (ExclusiveItemEffectIsActive__0230A9B8(defender, EXCLUSIVE_EFF_MAY_WARP_WHEN_ATTACKED)
&& DungeonRandInt(100) < ov10_022C45B0 && HasLowHealth(defender)) {
ov29_0230F728(attacker, defender, EXCLUSIVE_EFF_MAY_WARP_WHEN_ATTACKED, 0x40000);
}
#ifdef JAPAN
if (DefenderAbilityIsActive__0230A940(attacker, defender, ABILITY_ARENA_TRAP)) {
#else
if (DefenderAbilityIsActive__0230A940(attacker, defender, ABILITY_ARENA_TRAP, TRUE)) {
#endif
f1 = FALSE;
if (mon2->magnet_rise == 1
|| HasTypeAffectedByGravity(attacker, TYPE_FLYING)
|| LevitateIsActive(attacker)) {
if (!GravityIsActive()) {
f1 = TRUE;
if (ExclusiveItemEffectIsActive__0230A9B8(defender, EXCLUSIVE_EFF_MAY_POISON_PARALYZE_SLEEP_ATTACKERS) && !v3
&& DungeonRandInt(100) < ov10_022C45B4) {
i = DungeonRandInt(300);
if (i < 100) {
ov29_0230F728(attacker, defender, EXCLUSIVE_EFF_MAY_POISON_PARALYZE_SLEEP_ATTACKERS, 0x40);
} else if (i < 200) {
ov29_0230F728(attacker, defender, EXCLUSIVE_EFF_MAY_POISON_PARALYZE_SLEEP_ATTACKERS, 0x10);
} else {
ov29_0230F728(attacker, defender, EXCLUSIVE_EFF_MAY_POISON_PARALYZE_SLEEP_ATTACKERS, 0x80);
}
}
if (!f1 && DungeonRandInt(100) < ARENA_TRAP_ACTIVATION_CHANCE) {
mon2->contact_ability_trigger_bitflags |= 1;
for (ptr1 = ov29_023535DC; *(u8 *)ptr1 != 0; ptr1++) {
if (ExclusiveItemEffectIsActive__0230A9B8(defender, (enum exclusive_item_effect_id)ptr1->field_0x0)
&& ptr1->field_0x8(attacker, defender, v3)) {
ov29_0230F728(attacker, defender, (enum exclusive_item_effect_id)ptr1->field_0x0, ptr1->field_0x4);
}
}
}
#ifdef JAPAN
if (DefenderAbilityIsActive__0230A940(attacker, defender, ABILITY_SHADOW_TAG)
#else
if (DefenderAbilityIsActive__0230A940(attacker, defender, ABILITY_SHADOW_TAG, TRUE)
#endif
&& DungeonRandInt(100) < SHADOW_TAG_ACTIVATION_CHANCE) {
mon2->contact_ability_trigger_bitflags |= 2;
RAPID_SPIN_BINDING_REMOVAL = 0;
}
#ifdef JAPAN
if (DefenderAbilityIsActive__0230A940(attacker, defender, ABILITY_MAGNET_PULL)
#else
if (DefenderAbilityIsActive__0230A940(attacker, defender, ABILITY_MAGNET_PULL, TRUE)
#endif
&& MonsterIsType(attacker, TYPE_STEEL)
&& DungeonRandInt(100) < MAGNET_PULL_ACTIVATION_CHANCE) {
mon2->contact_ability_trigger_bitflags |= 4;
}
#ifdef JAPAN
if (DefenderAbilityIsActive__0230A940(attacker, defender, ABILITY_STATIC)
#else
if (DefenderAbilityIsActive__0230A940(attacker, defender, ABILITY_STATIC, TRUE)
#endif
&& !v3 && DungeonRandInt(100) < ov10_022C4550) {
mon2->contact_ability_trigger_bitflags |= 8;
}
#ifdef JAPAN
if (DefenderAbilityIsActive__0230A940(attacker, defender, ABILITY_POISON_POINT)
#else
if (DefenderAbilityIsActive__0230A940(attacker, defender, ABILITY_POISON_POINT, TRUE)
#endif
&& DungeonRandInt(100) < ov10_022C45C0) {
mon2->contact_ability_trigger_bitflags |= 0x20;
}
#ifdef JAPAN
if (DefenderAbilityIsActive__0230A940(attacker, defender, ABILITY_EFFECT_SPORE)
#else
if (DefenderAbilityIsActive__0230A940(attacker, defender, ABILITY_EFFECT_SPORE, TRUE)
#endif
&& !v3 && DungeonRandInt(100) < ov10_022C45AC) {
i = DungeonRandInt(3);
if (i < 1) {
mon2->contact_ability_trigger_bitflags |= 0x40;
} else if (i < 2) {
mon2->contact_ability_trigger_bitflags |= 0x10;
} else {
mon2->contact_ability_trigger_bitflags |= 0x80;
if (ExclusiveItemEffectIsActive__0230A9B8(defender, EXCLUSIVE_EFF_MAY_WARP_WHEN_ATTACKED)
&& DungeonRandInt(100) < ov10_022C45B0 && HasLowHealth(defender)) {
ov29_0230F728(attacker, defender, EXCLUSIVE_EFF_MAY_WARP_WHEN_ATTACKED, 0x40000);
}
}
#ifdef JAPAN
if (DefenderAbilityIsActive__0230A940(attacker, defender, ABILITY_FLAME_BODY)
if (DefenderAbilityIsActive__0230A940(attacker, defender, ABILITY_ARENA_TRAP)) {
#else
if (DefenderAbilityIsActive__0230A940(attacker, defender, ABILITY_FLAME_BODY, TRUE)
if (DefenderAbilityIsActive__0230A940(attacker, defender, ABILITY_ARENA_TRAP, TRUE)) {
#endif
&& DungeonRandInt(100) < ov10_022C467C) {
mon2->contact_ability_trigger_bitflags |= 0x100;
}
f1 = FALSE;
if (mon2->magnet_rise == 1
|| HasTypeAffectedByGravity(attacker, TYPE_FLYING)
|| LevitateIsActive(attacker)) {
if (!GravityIsActive()) {
f1 = TRUE;
}
}
if (!f1 && DungeonRandInt(100) < ARENA_TRAP_ACTIVATION_CHANCE) {
mon2->contact_ability_trigger_bitflags |= 1;
}
}
#ifdef JAPAN
if (DefenderAbilityIsActive__0230A940(attacker, defender, ABILITY_CUTE_CHARM)
if (DefenderAbilityIsActive__0230A940(attacker, defender, ABILITY_SHADOW_TAG)
#else
if (DefenderAbilityIsActive__0230A940(attacker, defender, ABILITY_CUTE_CHARM, TRUE)
if (DefenderAbilityIsActive__0230A940(attacker, defender, ABILITY_SHADOW_TAG, TRUE)
#endif
&& GendersNotEqualNotGenderless(
mon2->id, ((struct monster *)defender->info)->id)
&& !v3 && DungeonRandInt(100) < CUTE_CHARM_INFATUATE_CHANCE) {
mon2->contact_ability_trigger_bitflags |= 0x200;
}
&& DungeonRandInt(100) < SHADOW_TAG_ACTIVATION_CHANCE) {
mon2->contact_ability_trigger_bitflags |= 2;
RAPID_SPIN_BINDING_REMOVAL = 0;
}
#ifdef JAPAN
if (DefenderAbilityIsActive__0230A940(attacker, defender, ABILITY_STENCH)
if (DefenderAbilityIsActive__0230A940(attacker, defender, ABILITY_MAGNET_PULL)
#else
if (DefenderAbilityIsActive__0230A940(attacker, defender, ABILITY_STENCH, TRUE)
if (DefenderAbilityIsActive__0230A940(attacker, defender, ABILITY_MAGNET_PULL, TRUE)
#endif
&& DungeonRandInt(100) < ov10_022C4638) {
mon2->contact_ability_trigger_bitflags |= 0x400;
}
&& MonsterIsType(attacker, TYPE_STEEL)
&& DungeonRandInt(100) < MAGNET_PULL_ACTIVATION_CHANCE) {
mon2->contact_ability_trigger_bitflags |= 4;
}
#ifdef JAPAN
if (DefenderAbilityIsActive__0230A940(attacker, defender, ABILITY_STATIC)
#else
if (DefenderAbilityIsActive__0230A940(attacker, defender, ABILITY_STATIC, TRUE)
#endif
&& !v3 && DungeonRandInt(100) < ov10_022C4550) {
mon2->contact_ability_trigger_bitflags |= 8;
}
#ifdef JAPAN
if (DefenderAbilityIsActive__0230A940(attacker, defender, ABILITY_POISON_POINT)
#else
if (DefenderAbilityIsActive__0230A940(attacker, defender, ABILITY_POISON_POINT, TRUE)
#endif
&& DungeonRandInt(100) < ov10_022C45C0) {
mon2->contact_ability_trigger_bitflags |= 0x20;
}
#ifdef JAPAN
if (DefenderAbilityIsActive__0230A940(attacker, defender, ABILITY_EFFECT_SPORE)
#else
if (DefenderAbilityIsActive__0230A940(attacker, defender, ABILITY_EFFECT_SPORE, TRUE)
#endif
&& !v3 && DungeonRandInt(100) < ov10_022C45AC) {
i = DungeonRandInt(3);
if (i < 1) {
mon2->contact_ability_trigger_bitflags |= 0x40;
} else if (i < 2) {
mon2->contact_ability_trigger_bitflags |= 0x10;
} else {
mon2->contact_ability_trigger_bitflags |= 0x80;
}
}
#ifdef JAPAN
if (DefenderAbilityIsActive__0230A940(attacker, defender, ABILITY_FLAME_BODY)
#else
if (DefenderAbilityIsActive__0230A940(attacker, defender, ABILITY_FLAME_BODY, TRUE)
#endif
&& DungeonRandInt(100) < ov10_022C467C) {
mon2->contact_ability_trigger_bitflags |= 0x100;
}
#ifdef JAPAN
if (DefenderAbilityIsActive__0230A940(attacker, defender, ABILITY_CUTE_CHARM)
#else
if (DefenderAbilityIsActive__0230A940(attacker, defender, ABILITY_CUTE_CHARM, TRUE)
#endif
&& GendersNotEqualNotGenderless(
mon2->id, ((struct monster *)defender->info)->id)
&& !v3 && DungeonRandInt(100) < CUTE_CHARM_INFATUATE_CHANCE) {
mon2->contact_ability_trigger_bitflags |= 0x200;
}
#ifdef JAPAN
if (DefenderAbilityIsActive__0230A940(attacker, defender, ABILITY_STENCH)
#else
if (DefenderAbilityIsActive__0230A940(attacker, defender, ABILITY_STENCH, TRUE)
#endif
&& DungeonRandInt(100) < ov10_022C4638) {
mon2->contact_ability_trigger_bitflags |= 0x400;
}
result = IsEitherMonsterInvalid(attacker, defender);
}
}
if (result) {
result = TRUE;
} else {
@@ -516,8 +514,8 @@ int ApplyDamageAndEffects(struct entity *attacker, struct entity *defender,
mon1->leech_seed_class_status.leech_seed = STATUS_LEECH_SEED_NONE;
} else {
ov29_022E45D0(ent1, defender);
ApplyDamageAndEffectsWrapper(ent1, damage_data->field_0x0, 0xC,
0x238);
ApplyDamageAndEffectsWrapper(ent1, damage_data->field_0x0,
0xC, DAMAGE_SOURCE_DESTINY_BOND);
}
}
@@ -549,14 +547,12 @@ bool8 ApplyDamage(struct entity *attacker, struct entity *defender,
struct unk_02308FE0 *damage_data, int a4, int a5,
s16 damage_source, int a7)
{
bool8 f1;
bool8 f1 = FALSE;
struct unk_023528A4 *ptr1;
struct tile *tile;
struct tile *tile = NULL;
struct team_member *member;
struct item *item1;
struct item *item2;
bool8 f2;
bool8 f3;
bool8 f3 = FALSE;
bool8 f4;
bool8 f5;
s32 v1;
@@ -569,10 +565,8 @@ bool8 ApplyDamage(struct entity *attacker, struct entity *defender,
s32 i;
struct entity *ent1;
s32 j;
struct item *item3;
struct item *item4;
s16 v6;
u16 v7;
struct position pos;
u8 buf[0x48];
#ifdef EUROPE
@@ -580,9 +574,6 @@ bool8 ApplyDamage(struct entity *attacker, struct entity *defender,
#endif
damage_data->field_0x10 = FALSE;
f1 = FALSE;
tile = NULL;
f3 = FALSE;
if (defender->type != 1
|| IsSecretBazaarNpcBehavior(
@@ -685,7 +676,7 @@ bool8 ApplyDamage(struct entity *attacker, struct entity *defender,
TryIncreaseHp(attacker, defender, damage_data->field_0x0, 0, 0);
damage_data->field_0x10 = TRUE;
return FALSE;
}
} else
#ifdef JAPAN
if (DefenderAbilityIsActive__0230A940(attacker, defender,
ABILITY_WATER_ABSORB)
@@ -697,7 +688,7 @@ bool8 ApplyDamage(struct entity *attacker, struct entity *defender,
TryIncreaseHp(attacker, defender, damage_data->field_0x0, 0, 0);
damage_data->field_0x10 = TRUE;
return FALSE;
}
} else
#ifdef JAPAN
if (DefenderAbilityIsActive__0230A940(attacker, defender,
ABILITY_DRY_SKIN)
@@ -709,7 +700,7 @@ bool8 ApplyDamage(struct entity *attacker, struct entity *defender,
TryIncreaseHp(attacker, defender, damage_data->field_0x0, 0, 0);
damage_data->field_0x10 = TRUE;
return FALSE;
}
} else
#ifdef JAPAN
if (DefenderAbilityIsActive__0230A940(attacker, defender,
ABILITY_MOTOR_DRIVE)
@@ -820,6 +811,8 @@ negation_checked:
}
mon1->bide_damage_tally = 0x3E7;
} else {
u16 v7;
SetMessageLogPreprocessorArgsNumberVal(0, damage_data->field_0x0);
if (damage_data->field_0x4 >= 0x1B) {
@@ -855,10 +848,16 @@ negation_checked:
|| attacker->pos.y != defender->pos.y)
&& attacker->type == 1) {
f4 = FALSE;
if (mon1->is_team_leader && GetDamageTurnOption()
&& !ov29_022F9AF4(defender)
&& CanSeeTarget(defender, attacker)) {
f4 = TRUE;
if (mon1->is_team_leader) {
if (GetDamageTurnOption() && !ov29_022F9AF4(defender)) {
if (CanSeeTarget(defender, attacker)) {
f4 = TRUE;
} else {
f4 = FALSE;
}
}
} else {
f4 = FALSE;
}
if (mon1->blinker_class_status.blinded == 2
|| IsBlinded(defender, TRUE)) {
@@ -888,8 +887,8 @@ negation_checked:
}
v2 = mon1->hp;
if (v2 > damage_data->field_0x0) {
mon1->hp = v2 - damage_data->field_0x0;
if (mon1->hp > damage_data->field_0x0) {
mon1->hp -= damage_data->field_0x0;
} else {
mon1->hp = 0;
}
@@ -1032,9 +1031,10 @@ negation_checked:
}
item4 = &mon1->held_item;
if (GetFlag(item4->flags, 1) && !GetFlag(item4->flags, 8)
if (GetFlag(item4->flags, 1))
if (!GetFlag(item4->flags, 8)
&& !(mon1->held_item.flags & 2)
&& item4->id == 0x153) {
&& (u32)item4->id == 0x153) {
ov29_022E550C(defender);
defender->transparent = 0;
v3 = mon1->max_hp_stat + mon1->max_hp_boost;
@@ -1070,7 +1070,7 @@ negation_checked:
if (mon1->is_team_leader
&& GetFlag(mon1->held_item.flags, 1)
&& !GetFlag(mon1->held_item.flags, 8)
&& mon1->held_item.id == 0x159) {
&& (u32)mon1->held_item.id == 0x159) {
ent1 = NULL;
for (i = 0; i < 4; i++) {
ent1 = DUNGEON_PTR->monster_slot_ptrs[i];
@@ -1123,14 +1123,16 @@ negation_checked:
}
if (IqSkillIsEnabled(defender, IQ_ITEM_MASTER)) {
item1 = NULL;
item2 = NULL;
struct item *item1 = NULL;
struct item *item2 = NULL;
struct item *item3;
if (GetFlag(mon1->held_item.flags, 1)
&& !AbilityIsActiveVeneer(defender, ABILITY_KLUTZ)
&& !GetFlag(mon1->held_item.flags, 8)) {
if (mon1->held_item.id == 0x49) {
if ((u32)mon1->held_item.id == 0x49) {
item1 = &mon1->held_item;
} else if (mon1->held_item.id == 0x69) {
} else if ((u32)mon1->held_item.id == 0x69) {
item2 = &mon1->held_item;
}
}
@@ -1138,15 +1140,21 @@ negation_checked:
if (item1 == NULL && !mon1->is_not_team_member) {
for (j = 0; j < 0x32; j++) {
item3 = &BAG_ITEMS_PTR_MIRROR->bag_items->bag_items[j];
if (GetFlag(item3->flags, 1) && !GetFlag(item3->flags, 8)
&& item3->held_by == 0) {
if (item3->id == 0x49) {
item1 = item3;
break;
}
if (item2 == NULL && item3->id == 0x69) {
item2 = item3;
}
if (!GetFlag(item3->flags, 1)) {
continue;
}
if (GetFlag(item3->flags, 8)) {
continue;
}
if (item3->held_by != 0) {
continue;
}
if ((u32)item3->id == 0x49) {
item1 = item3;
break;
}
if (item2 == NULL && (u32)item3->id == 0x69) {
item2 = item3;
}
}
}
@@ -1287,9 +1295,10 @@ negation_checked:
v4 = ov10_022C593C[mon1->field_0x168].field_0x0;
} else {
if (mon1->exp_yield == 0) {
v4 = v4 / 2;
v4 /= 2;
} else if (mon1->exp_yield == 2) {
v4 = (v4 * 3) / 2;
v4 *= 3;
v4 /= 2;
}
if (v4 == 0) {
v4 = 1;

View File

@@ -127,7 +127,6 @@ void CalcDamage(struct entity *attacker, struct entity *defender, enum type_id a
s32 v5;
s32 v6;
s32 v7;
s32 v8;
s32 v9;
struct monster *mon3;
struct monster *mon4;
@@ -144,7 +143,6 @@ void CalcDamage(struct entity *attacker, struct entity *defender, enum type_id a
s32 v19;
s32 v20;
volatile s32 *p1;
volatile s32 *p2;
volatile s32 *p3;
struct damage_calc_diag *diag;
@@ -457,7 +455,6 @@ void CalcDamage(struct entity *attacker, struct entity *defender, enum type_id a
}
p1 = &arr[0];
p2 = &arr[0];
FixedPoint32To64(&fp4,
MultiplyByFixedPoint(MultiplyByFixedPoint(power << 8,
OFFENSIVE_STAT_STAGE_MULTIPLIERS[v1]),
@@ -476,7 +473,7 @@ void CalcDamage(struct entity *attacker, struct entity *defender, enum type_id a
f1 = MonsterHasNegativeStatus(attacker, TRUE);
f4 = UpdateStateFlags(mon3, 1, f1);
if (f1) {
v14 <<= 1;
v14 *= 2;
}
if (f4) {
PlayEffectAnimation0x1A9__022E6130(attacker);
@@ -490,8 +487,8 @@ void CalcDamage(struct entity *attacker, struct entity *defender, enum type_id a
f2 = (v2 < 0x21 && v5 == 0);
f4 = UpdateStateFlags(mon3, 0x100, f2);
if (f2) {
v14 += v14 * 2;
v15 <<= 1;
v14 *= 3;
v15 *= 2;
}
if (f4) {
PlayEffectAnimation0x1A9__022E617C(attacker);
@@ -500,19 +497,19 @@ void CalcDamage(struct entity *attacker, struct entity *defender, enum type_id a
}
if (AbilityIsActiveVeneer(attacker, ABILITY_HUSTLE) && v5 == 0) {
v14 += v14 * 2;
v15 <<= 1;
v14 *= 3;
v15 *= 2;
}
v12 = !((struct monster *)attacker->info)->is_not_team_member;
if (AbilityIsActiveVeneer(attacker, ABILITY_PLUS) && v5 == 1
&& DUNGEON_PTR->minus_is_active[v12]) {
v14 = v14 * 16 - v14;
v14 *= 15;
v15 *= 10;
}
if (AbilityIsActiveVeneer(attacker, ABILITY_MINUS) && v5 == 1
&& DUNGEON_PTR->plus_is_active[v12]) {
v14 = v14 * 16 - v14;
v14 *= 15;
v15 *= 10;
}
@@ -523,8 +520,8 @@ void CalcDamage(struct entity *attacker, struct entity *defender, enum type_id a
if (DefenderAbilityIsActive__0230A940(attacker, defender, ABILITY_INTIMIDATE, TRUE)
&& v5 == 0) {
#endif
v14 <<= 2;
v15 += v15 * 4;
v14 *= 4;
v15 *= 5;
}
#ifdef JAPAN
if (DefenderAbilityIsActive__0230A940(attacker, defender, ABILITY_MARVEL_SCALE)
@@ -537,8 +534,8 @@ void CalcDamage(struct entity *attacker, struct entity *defender, enum type_id a
f3 = MonsterHasNegativeStatus(defender, TRUE);
f4 = UpdateStateFlags(mon4, 8, f3);
if (f3) {
v7 = v7 * 3;
v6 <<= 1;
v7 *= 3;
v6 *= 2;
}
if (f4) {
PlayEffectAnimation0x18E(defender);
@@ -548,11 +545,10 @@ void CalcDamage(struct entity *attacker, struct entity *defender, enum type_id a
p3 = &arr[1];
v9 = *p1 * v14;
v8 = *p3;
*p3 = v8 * v7;
*p2 = v9;
*p3 = *p3 * v7;
*p1 = v9;
if (v15 != 1) {
*p2 = v9 / v15;
*p1 = v9 / v15;
}
if (v6 != 1) {
p3 = &arr[1];

View File

@@ -109,6 +109,12 @@ void ActivateEndOfTurnEffects(struct entity *entity)
s32 v1;
s32 v2;
s32 v3;
s32 v4;
s32 v5;
s32 v6;
s32 v7;
s32 v8;
s32 v9;
struct fixed_point_64 f2;
struct fixed_point_64 f1;
struct fixed_point f3;
@@ -116,6 +122,7 @@ void ActivateEndOfTurnEffects(struct entity *entity)
s16 i;
struct monster *monster;
bool8 b1;
bool8 b2;
struct monster *mon1;
struct move mv;
@@ -199,7 +206,7 @@ void ActivateEndOfTurnEffects(struct entity *entity)
v3 = 0;
}
TryEndPetrifiedOrSleepStatus(entity, entity);
ApplyDamageAndEffectsWrapper(entity, 1, 0xE, 0x250);
ApplyDamageAndEffectsWrapper(entity, 1, 0xE, DAMAGE_SOURCE_HUNGER);
monster->famished = TRUE;
if (CeilFixedPoint(monster->belly) != 0)
v2 = 0;
@@ -215,7 +222,9 @@ void ActivateEndOfTurnEffects(struct entity *entity)
if (v3 != 0 && !DUNGEON_PTR->end_floor_no_death_check_flag &&
EntityIsValid__02311010(entity))
#endif
{
PlaySeByIdIfNotSilence(0x1303);
}
LogMessageByIdWithPopupCheckUser(entity, v2);
ov29_022EA370(0x1E, 0x32);
}
@@ -265,9 +274,9 @@ void ActivateEndOfTurnEffects(struct entity *entity)
if (IsFloorOver())
return;
}
v1 = DungeonRandInt(100);
v4 = DungeonRandInt(100);
if (AbilityIsActiveVeneer(entity, ABILITY_SHED_SKIN) &&
v1 < SHED_SKIN_ACTIVATION_CHANCE &&
v4 < SHED_SKIN_ACTIVATION_CHANCE &&
MonsterHasNegativeStatus(entity, FALSE)) {
DisplayActions(0);
if (!EntityIsValid__02311010(entity))
@@ -288,72 +297,72 @@ void ActivateEndOfTurnEffects(struct entity *entity)
EndNegativeStatusCondition(entity, entity, TRUE, FALSE, FALSE);
}
if (AbilityIsActiveVeneer(entity, ABILITY_SPEED_BOOST)) {
monster->field_0x11f++;
if (monster->field_0x11f >= SPEED_BOOST_TURNS) {
monster->field_0x11f = 0;
BoostSpeedOneStage(entity, entity, 0x7f, FALSE);
}
if (AbilityIsActiveVeneer(entity, ABILITY_SPEED_BOOST)) {
monster->field_0x11f++;
if (monster->field_0x11f >= SPEED_BOOST_TURNS) {
monster->field_0x11f = 0;
BoostSpeedOneStage(entity, entity, 0x7f, FALSE);
}
}
if (monster->sleep_class_status.sleep == STATUS_SLEEP_YAWNING) {
if (monster->sleep_class_status.sleep == STATUS_SLEEP_YAWNING) {
DisplayActions(0);
if (!EntityIsValid__02311010(entity))
return;
if (IsFloorOver())
return;
ov29_022E53F0(entity);
}
if (monster->burn_class_status.burn == STATUS_BURN_BURN) {
if (monster->burn_class_status.burn_damage_countdown != 0)
monster->burn_class_status.burn_damage_countdown--;
if (monster->burn_class_status.burn_damage_countdown == 0) {
DisplayActions(0);
if (!EntityIsValid__02311010(entity))
return;
if (IsFloorOver())
return;
ov29_022E53F0(entity);
monster->burn_class_status.burn_damage_countdown = BURN_DAMAGE_COOLDOWN;
TryEndPetrifiedOrSleepStatus(entity, entity);
ApplyDamageAndEffectsWrapper(entity, BURN_DAMAGE, 1, DAMAGE_SOURCE_BURN);
}
if (!EntityIsValid__02311010(entity))
return;
if (IsFloorOver())
return;
}
if (monster->burn_class_status.burn == STATUS_BURN_BURN) {
if (monster->burn_class_status.burn_damage_countdown != 0)
monster->burn_class_status.burn_damage_countdown--;
if (monster->burn_class_status.burn_damage_countdown == 0) {
DisplayActions(0);
if (!EntityIsValid__02311010(entity))
return;
if (IsFloorOver())
return;
monster->burn_class_status.burn_damage_countdown = BURN_DAMAGE_COOLDOWN;
TryEndPetrifiedOrSleepStatus(entity, entity);
ApplyDamageAndEffectsWrapper(entity, BURN_DAMAGE, 1, 0x247);
}
if (!EntityIsValid__02311010(entity))
return;
if (IsFloorOver())
return;
if (GravityIsActive()) {
if (IsFloating(entity)) {
EndMagnetRiseStatus(entity, entity);
EnsureCanStandCurrentTile(entity);
}
if (!EntityIsValid__02311010(entity))
return;
if (IsFloorOver())
return;
}
if (GravityIsActive()) {
if (IsFloating(entity)) {
EndMagnetRiseStatus(entity, entity);
EnsureCanStandCurrentTile(entity);
}
if (!EntityIsValid__02311010(entity))
return;
if (IsFloorOver())
return;
}
if (AbilityIsActiveVeneer(entity, ABILITY_BAD_DREAMS)) {
TryActivateBadDreams(entity);
if (!EntityIsValid__02311010(entity))
return;
if (IsFloorOver())
return;
}
if (AbilityIsActiveVeneer(entity, ABILITY_BAD_DREAMS)) {
TryActivateBadDreams(entity);
if (!EntityIsValid__02311010(entity))
return;
if (IsFloorOver())
return;
}
if (!IsTileGround(GetTileAtEntity(entity))) {
v1 = monster->max_hp_stat + monster->max_hp_boost;
if (v1 > 999)
v1 = 999;
if (monster->hp < v1 &&
ExclusiveItemEffectIsActive__02311064(entity, EXCLUSIVE_EFF_RECOVER_HP_FROM_WATERY_TERRAIN)) {
TryIncreaseHp(entity, entity, ov10_022C4664, 0, FALSE);
}
if (ExclusiveItemEffectIsActive__02311064(entity, EXCLUSIVE_EFF_HEAL_STATUS_FROM_WATERY_TERRAIN))
EndNegativeStatusConditionWrapper(entity, entity, TRUE, TRUE);
if (!IsTileGround(GetTileAtEntity(entity))) {
v5 = monster->max_hp_stat + monster->max_hp_boost;
if (v5 > MAX_HP_LIMIT)
v5 = MAX_HP_LIMIT;
if (monster->hp < v5 &&
ExclusiveItemEffectIsActive__02311064(entity, EXCLUSIVE_EFF_RECOVER_HP_FROM_WATERY_TERRAIN)) {
TryIncreaseHp(entity, entity, ov10_022C4664, 0, FALSE);
}
if (ExclusiveItemEffectIsActive__02311064(entity, EXCLUSIVE_EFF_HEAL_STATUS_FROM_WATERY_TERRAIN))
EndNegativeStatusConditionWrapper(entity, entity, TRUE, TRUE);
}
if (ExclusiveItemEffectIsActive__02311064(entity, EXCLUSIVE_EFF_ABSORB_TEAMMATE_POISON)) {
b1 = FALSE;
@@ -404,17 +413,17 @@ void ActivateEndOfTurnEffects(struct entity *entity)
monster->burn_class_status.burn_damage_countdown--;
if (monster->burn_class_status.burn_damage_countdown == 0) {
v1 = monster->burn_class_status.badly_poisoned_damage_count;
v6 = monster->burn_class_status.badly_poisoned_damage_count;
if (monster->burn_class_status.badly_poisoned_damage_count < 0x1d)
monster->burn_class_status.badly_poisoned_damage_count++;
monster->burn_class_status.burn_damage_countdown = BAD_POISON_DAMAGE_COOLDOWN;
if (v1 >= 0x1d)
v1 = 0x1d;
if (v1 < 0)
v1 = 0;
if (v6 >= 0x1d)
v6 = 0x1d;
if (v6 < 0)
v6 = 0;
DisplayActions(0);
@@ -426,9 +435,9 @@ void ActivateEndOfTurnEffects(struct entity *entity)
TryEndPetrifiedOrSleepStatus(entity, entity);
if (AbilityIsActiveVeneer(entity, ABILITY_POISON_HEAL))
TryIncreaseHp(entity, entity, BAD_POISON_DAMAGE_TABLE[v1], 0, TRUE);
TryIncreaseHp(entity, entity, BAD_POISON_DAMAGE_TABLE[v6], 0, TRUE);
else
ApplyDamageAndEffectsWrapper(entity, BAD_POISON_DAMAGE_TABLE[v1], 3,
ApplyDamageAndEffectsWrapper(entity, BAD_POISON_DAMAGE_TABLE[v6], 3,
DAMAGE_SOURCE_POISON);
}
@@ -450,7 +459,7 @@ void ActivateEndOfTurnEffects(struct entity *entity)
monster->frozen_class_status.freeze_damage_countdown = ov10_022C4454;
TryEndPetrifiedOrSleepStatus(entity, entity);
PlayEffectAnimationEntityStandard(entity, monster->frozen_class_status.constriction_animation);
ApplyDamageAndEffectsWrapper(entity, CONSTRICTION_DAMAGE, 2, 0x248);
ApplyDamageAndEffectsWrapper(entity, CONSTRICTION_DAMAGE, 2, DAMAGE_SOURCE_CONSTRICTION);
}
if (!EntityIsValid__02311010(entity))
return;
@@ -467,7 +476,7 @@ void ActivateEndOfTurnEffects(struct entity *entity)
return;
monster->frozen_class_status.freeze_damage_countdown = WRAP_DAMAGE_COOLDOWN;
TryEndPetrifiedOrSleepStatus(entity, entity);
ApplyDamageAndEffectsWrapper(entity, WRAP_DAMAGE, 5, 0x24A);
ApplyDamageAndEffectsWrapper(entity, WRAP_DAMAGE, 5, DAMAGE_SOURCE_WRAP);
}
if (!EntityIsValid__02311010(entity))
return;
@@ -487,19 +496,17 @@ void ActivateEndOfTurnEffects(struct entity *entity)
}
}
if (monster->curse_class_status.curse == STATUS_CURSE_CURSED)
{
if (monster->curse_class_status.curse == STATUS_CURSE_CURSED) {
if (monster->curse_class_status.curse_damage_countdown != 0)
monster->curse_class_status.curse_damage_countdown--;
if (monster->curse_class_status.curse_damage_countdown == 0)
{
v1 = monster->max_hp_stat + monster->max_hp_boost;
if (v1 > 999)
v1 = 999;
v2 = v1 / 4;
if (v2 == 0)
v2++;
if (monster->curse_class_status.curse_damage_countdown == 0) {
v7 = monster->max_hp_stat + monster->max_hp_boost;
if (v7 > MAX_HP_LIMIT)
v7 = MAX_HP_LIMIT;
v8 = v7 / 4;
if (v8 == 0)
v8++;
monster->curse_class_status.curse_damage_countdown = CURSE_DAMAGE_COOLDOWN;
DisplayActions(0);
@@ -509,7 +516,7 @@ void ActivateEndOfTurnEffects(struct entity *entity)
return;
TryEndPetrifiedOrSleepStatus(entity, entity);
ApplyDamageAndEffectsWrapper(entity, v2, 7, 0x24B);
ApplyDamageAndEffectsWrapper(entity, v8, 7, DAMAGE_SOURCE_CURSE);
}
if (!EntityIsValid__02311010(entity))
@@ -518,34 +525,26 @@ void ActivateEndOfTurnEffects(struct entity *entity)
return;
}
if (monster->leech_seed_class_status.leech_seed == STATUS_LEECH_SEED_LEECH_SEED)
{
if (monster->leech_seed_class_status.leech_seed == STATUS_LEECH_SEED_LEECH_SEED) {
if (monster->leech_seed_class_status.leech_seed_damage_countdown != 0)
monster->leech_seed_class_status.leech_seed_damage_countdown--;
if (monster->leech_seed_class_status.leech_seed_damage_countdown == 0)
{
if (monster->leech_seed_class_status.leech_seed_damage_countdown == 0) {
e1 = DUNGEON_PTR->active_monster_ptrs[monster->leech_seed_class_status.leech_seed_source_monster_index];
v2 = LEECH_SEED_DAMAGE_COOLDOWN;
v3 = LEECH_SEED_HP_DRAIN;
v9 = LEECH_SEED_HP_DRAIN;
monster->leech_seed_class_status.leech_seed_damage_countdown = v2;
if (e1 == NULL)
{
monster->leech_seed_class_status.leech_seed_damage_countdown = LEECH_SEED_DAMAGE_COOLDOWN;
if (e1 == NULL) {
monster->leech_seed_class_status.leech_seed = STATUS_LEECH_SEED_NONE;
}
else if (monster->leech_seed_class_status.statuses_applier_id != GetEntInfo(e1)->unique_id)
{
} else if (monster->leech_seed_class_status.statuses_applier_id != GetEntInfo(e1)->unique_id) {
monster->leech_seed_class_status.leech_seed = STATUS_LEECH_SEED_NONE;
}
else
{
} else {
if (e1 != entity &&
(e1 == NULL ? FALSE : (bool8)(GetEntityType(e1) == ENTITY_MONSTER)) &&
AbilityIsActiveVeneer(e1, ABILITY_MOLD_BREAKER))
b1 = FALSE;
b2 = FALSE;
else
b1 = AbilityIsActiveVeneer(entity, ABILITY_LIQUID_OOZE);
b2 = AbilityIsActiveVeneer(entity, ABILITY_LIQUID_OOZE);
ov29_022EC62C(entity);
DisplayActions(0);
@@ -556,18 +555,14 @@ void ActivateEndOfTurnEffects(struct entity *entity)
if (IsFloorOver())
return;
if (monster->frozen_class_status.freeze != STATUS_FROZEN_FROZEN)
{
if (monster->frozen_class_status.freeze != STATUS_FROZEN_FROZEN) {
TryEndPetrifiedOrSleepStatus(entity, entity);
ApplyDamageAndEffectsWrapper(entity, v3, 9, 0x24C);
if (b1)
{
ApplyDamageAndEffectsWrapper(entity, v9, 9, DAMAGE_SOURCE_LEECH_SEED);
if (b2) {
TryEndPetrifiedOrSleepStatus(e1, e1);
ApplyDamageAndEffectsWrapper(e1, v3, 0xD, 0x239);
}
else if (!AbilityIsActiveVeneer(entity, ABILITY_MAGIC_GUARD))
{
TryIncreaseHp(e1, e1, v3, 0, TRUE);
ApplyDamageAndEffectsWrapper(e1, v9, 0xD, DAMAGE_SOURCE_SLUDGE);
} else if (!AbilityIsActiveVeneer(entity, ABILITY_MAGIC_GUARD)) {
TryIncreaseHp(e1, e1, v9, 0, TRUE);
}
}
}
@@ -593,7 +588,7 @@ void ActivateEndOfTurnEffects(struct entity *entity)
if (monster->reflect_class_status.reflect == STATUS_REFLECT_PROTECT) {
LogMessageByIdWithPopupCheckUser(entity, MESSAGE_DEC);
} else {
ApplyDamageAndEffectsWrapper(entity, 9999, 0xB, 0x24D);
ApplyDamageAndEffectsWrapper(entity, 9999, 0xB, DAMAGE_SOURCE_PERISH_SONG);
}
if (!EntityIsValid__02311010(entity))
return;

View File

@@ -1,7 +1,9 @@
#include "overlay_29_0233C9E8.h"
#include "dg_random.h"
#include "dungeon.h"
#include "dungeon_map_access.h"
#include "dungeon_util.h"
#include "dungeon_util_static.h"
void GenerateExtraHallways(struct unk_0233C9E8 (*grid)[15], s32 grid_size_x, s32 grid_size_y, s32 n_extra_hallways)
{
@@ -10,7 +12,6 @@ void GenerateExtraHallways(struct unk_0233C9E8 (*grid)[15], s32 grid_size_x, s32
s32 dir;
s32 k;
s32 oob;
s32 d;
if (n_extra_hallways == 0) {
return;
@@ -28,10 +29,8 @@ void GenerateExtraHallways(struct unk_0233C9E8 (*grid)[15], s32 grid_size_x, s32
x = DungeonRandInt(grid_size_x);
y = DungeonRandInt(grid_size_y);
cell = &grid[x][y];
if (cell->field_0xa == 0 || cell->field_0xb == 0) {
continue;
}
if (cell->field_0x8 != 0 || cell->field_0x10 != 0) {
if (cell->field_0xa == 0 || cell->field_0xb == 0
|| cell->field_0x8 != 0 || cell->field_0x10 != 0) {
continue;
}
tx = DungeonRandRange(cell->field_0x0, cell->field_0x4);
@@ -60,19 +59,19 @@ void GenerateExtraHallways(struct unk_0233C9E8 (*grid)[15], s32 grid_size_x, s32
ty += DIRECTIONS_XY[dir].y;
}
for (;;) {
if ((GetTile(tx, ty)->terrain_flags & 3) != 1) {
if (GetTerrainType(GetTile(tx, ty)) != TERRAIN_TYPE_NORMAL) {
break;
}
tx += DIRECTIONS_XY[dir].x;
ty += DIRECTIONS_XY[dir].y;
}
if ((GetTile(tx, ty)->terrain_flags & 3) == 2) {
if (GetTerrainType(GetTile(tx, ty)) == TERRAIN_TYPE_SECONDARY) {
continue;
}
oob = 0;
for (bx = tx - 2; bx <= tx + 2; bx++) {
for (by = ty - 2; by <= ty + 2; by++) {
if (bx < 0 || bx >= 56 || by < 0 || by >= 32) {
if (bx < 0 || bx >= DUNGEON_MAX_SIZE_X || by < 0 || by >= DUNGEON_MAX_SIZE_Y) {
oob = 1;
break;
}
@@ -84,72 +83,66 @@ void GenerateExtraHallways(struct unk_0233C9E8 (*grid)[15], s32 grid_size_x, s32
if (oob) {
continue;
}
d = (dir + 2) & 6;
if ((GetTile(tx + DIRECTIONS_XY[d].x, ty + DIRECTIONS_XY[d].y)->terrain_flags & 3) == 1) {
if (GetTerrainType(GetTile(tx + DIRECTIONS_XY[(dir + 2) & 6].x, ty + DIRECTIONS_XY[(dir + 2) & 6].y)) == TERRAIN_TYPE_NORMAL) {
continue;
}
d = (dir - 2) & 6;
if ((GetTile(tx + DIRECTIONS_XY[d].x, ty + DIRECTIONS_XY[d].y)->terrain_flags & 3) == 1) {
if (GetTerrainType(GetTile(tx + DIRECTIONS_XY[(dir - 2) & 6].x, ty + DIRECTIONS_XY[(dir - 2) & 6].y)) == TERRAIN_TYPE_NORMAL) {
continue;
}
seg = DungeonRandInt(3) + 3;
for (;;) {
int flag;
s32 flag;
if (tx <= 1 || ty <= 1) {
break;
}
if (tx >= 0x37 || ty >= 0x1f) {
if (tx >= DUNGEON_MAX_SIZE_X - 1 || ty >= DUNGEON_MAX_SIZE_Y - 1) {
break;
}
if ((GetTile(tx, ty)->terrain_flags & 3) == 1) {
if (GetTerrainType(GetTile(tx, ty)) == TERRAIN_TYPE_NORMAL) {
break;
}
if (GetTile(tx, ty)->terrain_flags & 0x10) {
if (GetTile(tx, ty)->terrain_flags & TERRAIN_TYPE_IMPASSABLE_WALL) {
break;
}
flag = 1;
if ((GetTile(tx + 1, ty)->terrain_flags & 3) == 1
&& (GetTile(tx + 1, ty + 1)->terrain_flags & 3) == 1
&& (GetTile(tx, ty + 1)->terrain_flags & 3) == 1) {
if (GetTerrainType(GetTile(tx + 1, ty)) == TERRAIN_TYPE_NORMAL
&& GetTerrainType(GetTile(tx + 1, ty + 1)) == TERRAIN_TYPE_NORMAL
&& GetTerrainType(GetTile(tx, ty + 1)) == TERRAIN_TYPE_NORMAL) {
flag = 0;
}
if ((GetTile(tx + 1, ty)->terrain_flags & 3) == 1) {
if (GetTerrainType(GetTile(tx + 1, ty)) == TERRAIN_TYPE_NORMAL) {
s32 ym = ty - 1;
if ((GetTile(tx + 1, ym)->terrain_flags & 3) == 1
&& (GetTile(tx, ym)->terrain_flags & 3) == 1) {
if (GetTerrainType(GetTile(tx + 1, ym)) == TERRAIN_TYPE_NORMAL
&& GetTerrainType(GetTile(tx, ym)) == TERRAIN_TYPE_NORMAL) {
flag = 0;
}
}
{
s32 xm = tx - 1;
if ((GetTile(xm, ty)->terrain_flags & 3) == 1
&& (GetTile(xm, ty + 1)->terrain_flags & 3) == 1
&& (GetTile(tx, ty + 1)->terrain_flags & 3) == 1) {
if (GetTerrainType(GetTile(xm, ty)) == TERRAIN_TYPE_NORMAL
&& GetTerrainType(GetTile(xm, ty + 1)) == TERRAIN_TYPE_NORMAL
&& GetTerrainType(GetTile(tx, ty + 1)) == TERRAIN_TYPE_NORMAL) {
flag = 0;
}
if ((GetTile(xm, ty)->terrain_flags & 3) == 1) {
if (GetTerrainType(GetTile(xm, ty)) == TERRAIN_TYPE_NORMAL) {
s32 ym = ty - 1;
if ((GetTile(xm, ym)->terrain_flags & 3) == 1
&& (GetTile(tx, ym)->terrain_flags & 3) == 1) {
if (GetTerrainType(GetTile(xm, ym)) == TERRAIN_TYPE_NORMAL
&& GetTerrainType(GetTile(tx, ym)) == TERRAIN_TYPE_NORMAL) {
flag = 0;
}
}
}
if (flag) {
struct tile *t = GetTileSafe(tx, ty);
t->terrain_flags &= ~3;
t->terrain_flags |= 1;
t->terrain_flags &= ~(TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY);
t->terrain_flags |= TERRAIN_TYPE_NORMAL;
}
d = (dir + 2) & 6;
if ((GetTile(tx + DIRECTIONS_XY[d].x, ty + DIRECTIONS_XY[d].y)->terrain_flags & 3) == 1) {
if (GetTerrainType(GetTile(tx + DIRECTIONS_XY[(dir + 2) & 6].x, ty + DIRECTIONS_XY[(dir + 2) & 6].y)) == TERRAIN_TYPE_NORMAL) {
break;
}
d = (dir - 2) & 6;
if ((GetTile(tx + DIRECTIONS_XY[d].x, ty + DIRECTIONS_XY[d].y)->terrain_flags & 3) == 1) {
if (GetTerrainType(GetTile(tx + DIRECTIONS_XY[(dir - 2) & 6].x, ty + DIRECTIONS_XY[(dir - 2) & 6].y)) == TERRAIN_TYPE_NORMAL) {
break;
}
if (--seg == 0) {

View File

@@ -7,6 +7,7 @@ void CreateGridCellConnections(struct unk_0233C9E8 (*grid)[15], s32 grid_size_x,
{
s32 i;
s32 j;
int jj;
for (i = 0; i < grid_size_x; i++) {
for (j = 0; j < grid_size_y; j++) {
@@ -16,51 +17,51 @@ void CreateGridCellConnections(struct unk_0233C9E8 (*grid)[15], s32 grid_size_x,
grid[i][j].field_0x11[7] = 0;
grid[i][j].field_0x11[8] = 0;
grid[i][j].field_0x11[9] = 0;
continue;
} else {
if (i <= 0) {
grid[i][j].field_0x11[4] = 0;
}
if (j <= 0) {
grid[i][j].field_0x11[2] = 0;
}
if (i >= grid_size_x - 1) {
grid[i][j].field_0x11[5] = 0;
}
if (j >= grid_size_y - 1) {
grid[i][j].field_0x11[3] = 0;
}
grid[i][j].field_0x11[6] = grid[i][j].field_0x11[2];
grid[i][j].field_0x11[7] = grid[i][j].field_0x11[3];
grid[i][j].field_0x11[8] = grid[i][j].field_0x11[4];
grid[i][j].field_0x11[9] = grid[i][j].field_0x11[5];
}
if (i <= 0) {
grid[i][j].field_0x11[4] = 0;
}
if (j <= 0) {
grid[i][j].field_0x11[2] = 0;
}
if (i >= grid_size_x - 1) {
grid[i][j].field_0x11[5] = 0;
}
if (j >= grid_size_y - 1) {
grid[i][j].field_0x11[3] = 0;
}
grid[i][j].field_0x11[6] = grid[i][j].field_0x11[2];
grid[i][j].field_0x11[7] = grid[i][j].field_0x11[3];
grid[i][j].field_0x11[8] = grid[i][j].field_0x11[4];
grid[i][j].field_0x11[9] = grid[i][j].field_0x11[5];
}
}
for (i = 0; i < grid_size_x; i++) {
for (j = 0; j < grid_size_y; j++) {
s32 v0;
s32 v1;
s32 v0, v1, t0, t1;
jj = j;
if (grid[i][j].field_0x8 != 0) {
continue;
}
if (grid[i][j].field_0xa == 0) {
v0 = grid[i][j].field_0x0;
v1 = grid[i][j].field_0x2;
} else {
if (grid[i][j].field_0xa != 0) {
v0 = DungeonRandRange(grid[i][j].field_0x0 + 1, grid[i][j].field_0x4 - 1);
v1 = DungeonRandRange(grid[i][j].field_0x2 + 1, grid[i][j].field_0x6 - 1);
} else {
v0 = grid[i][j].field_0x0;
v1 = grid[i][j].field_0x2;
}
if (grid[i][j].field_0x11[6] != 0) {
if (grid[i][j - 1].field_0x8 == 0) {
s32 t;
if (grid[i][j - 1].field_0xa == 0) {
t = grid[i][j - 1].field_0x0;
if (grid[i][j - 1].field_0xa != 0) {
t0 = DungeonRandRange(grid[i][j - 1].field_0x0 + 1, grid[i][j - 1].field_0x4 - 1);
} else {
t = DungeonRandRange(grid[i][j - 1].field_0x0 + 1, grid[i][j - 1].field_0x4 - 1);
t0 = grid[i][j - 1].field_0x0;
}
CreateHallway(v0, grid[i][(u32)j].field_0x2, t, grid[i][(u32)j - 1].field_0x6 - 1, TRUE,
CreateHallway(v0, grid[i][jj].field_0x2, t0, grid[i][jj - 1].field_0x6 - 1, TRUE,
arg4[i], arg5[j]);
}
grid[i][j].field_0x11[6] = 0;
@@ -71,13 +72,12 @@ void CreateGridCellConnections(struct unk_0233C9E8 (*grid)[15], s32 grid_size_x,
if (grid[i][j].field_0x11[7] != 0) {
if (grid[i][j + 1].field_0x8 == 0) {
s32 t;
if (grid[i][j + 1].field_0xa == 0) {
t = grid[i][j + 1].field_0x0;
if (grid[i][j + 1].field_0xa != 0) {
t0 = DungeonRandRange(grid[i][j + 1].field_0x0 + 1, grid[i][j + 1].field_0x4 - 1);
} else {
t = DungeonRandRange(grid[i][j + 1].field_0x0 + 1, grid[i][j + 1].field_0x4 - 1);
t0 = grid[i][j + 1].field_0x0;
}
CreateHallway(v0, grid[i][(u32)j].field_0x6 - 1, t, grid[i][(u32)j + 1].field_0x2, TRUE,
CreateHallway(v0, grid[i][jj].field_0x6 - 1, t0, grid[i][jj + 1].field_0x2, TRUE,
arg4[i], arg5[j + 1] - 1);
}
grid[i][j].field_0x11[7] = 0;
@@ -88,13 +88,12 @@ void CreateGridCellConnections(struct unk_0233C9E8 (*grid)[15], s32 grid_size_x,
if (grid[i][j].field_0x11[8] != 0) {
if (grid[i - 1][j].field_0x8 == 0) {
s32 t;
if (grid[i - 1][j].field_0xa == 0) {
t = grid[i - 1][j].field_0x2;
if (grid[i - 1][j].field_0xa != 0) {
t1 = DungeonRandRange(grid[i - 1][j].field_0x2 + 1, grid[i - 1][j].field_0x6 - 1);
} else {
t = DungeonRandRange(grid[i - 1][j].field_0x2 + 1, grid[i - 1][j].field_0x6 - 1);
t1 = grid[i - 1][j].field_0x2;
}
CreateHallway(grid[i][(u32)j].field_0x0, v1, grid[i - 1][(u32)j].field_0x0 - 1, t, FALSE,
CreateHallway(grid[i][jj].field_0x0, v1, grid[i - 1][jj].field_0x0 - 1, t1, FALSE,
arg4[i], arg5[j]);
}
grid[i][j].field_0x11[8] = 0;
@@ -105,13 +104,12 @@ void CreateGridCellConnections(struct unk_0233C9E8 (*grid)[15], s32 grid_size_x,
if (grid[i][j].field_0x11[9] != 0) {
if (grid[i + 1][j].field_0x8 == 0) {
s32 t;
if (grid[i + 1][j].field_0xa == 0) {
t = grid[i + 1][j].field_0x2;
if (grid[i + 1][j].field_0xa != 0) {
t1 = DungeonRandRange(grid[i + 1][j].field_0x2 + 1, grid[i + 1][j].field_0x6 - 1);
} else {
t = DungeonRandRange(grid[i + 1][j].field_0x2 + 1, grid[i + 1][j].field_0x6 - 1);
t1 = grid[i + 1][j].field_0x2;
}
CreateHallway(grid[i][(u32)j].field_0x4 - 1, v1, grid[i + 1][(u32)j].field_0x0, t, FALSE,
CreateHallway(grid[i][jj].field_0x4 - 1, v1, grid[i + 1][jj].field_0x0, t1, FALSE,
arg4[i + 1] - 1, arg5[j]);
}
grid[i][j].field_0x11[9] = 0;
@@ -126,198 +124,158 @@ void CreateGridCellConnections(struct unk_0233C9E8 (*grid)[15], s32 grid_size_x,
}
for (i = 0; i < grid_size_x; i++) {
for (j = 0; j < grid_size_y; j++) {
struct unk_0233C9E8 *cell;
s32 chance = DungeonRandInt(100);
if (DungeonRandInt(100) >= 5) {
continue;
}
cell = &grid[i][j];
if (cell->field_0x8 != 0) {
continue;
}
if (cell->field_0xb == 0) {
continue;
}
if (cell->field_0x11[1] != 0 || cell->field_0x9 != 0) {
continue;
}
if (cell->field_0xa == 0) {
continue;
}
if (chance < 5 &&
grid[i][j].field_0x8 == 0 &&
grid[i][j].field_0xb != 0 &&
grid[i][j].field_0x11[1] == 0 &&
grid[i][j].field_0x9 == 0 &&
grid[i][j].field_0xa != 0)
{
switch (DungeonRandInt(4)) {
case 0: {
s32 x0, y0, y1;
int x1;
s32 y, x;
s32 room;
if (i < 1) {
break;
}
if (cell[-15].field_0xb == 0) {
break;
}
if (cell[-15].field_0x8 != 0) {
break;
}
if (cell[-15].field_0xa == 0) {
break;
}
if (cell[-15].field_0x9 != 0 || cell[-15].field_0x11[1] != 0) {
break;
}
x0 = cell[-15].field_0x0;
y0 = cell[-15].field_0x2 < cell->field_0x2 ? cell[-15].field_0x2 : cell->field_0x2;
x1 = cell->field_0x4;
y1 = cell[-15].field_0x6 > cell->field_0x6 ? cell[-15].field_0x6 : cell->field_0x6;
room = GetTile(cell->field_0x0, cell->field_0x2)->room;
for (x = x0; x < x1; x++) {
for (y = y0; y < y1; y++) {
struct tile *t = GetTileSafe(x, y);
t->terrain_flags &= ~3;
t->terrain_flags |= 1;
t->room = room;
if (i >= 1 &&
grid[i - 1][j].field_0xb &&
!grid[i - 1][j].field_0x8 &&
grid[i - 1][j].field_0xa &&
!grid[i - 1][j].field_0x9 &&
!grid[i - 1][j].field_0x11[1]) {
s32 y, x;
s32 x0 = grid[i - 1][j].field_0x0;
s32 y0 = grid[i - 1][j].field_0x2 < grid[i][j].field_0x2 ? grid[i - 1][j].field_0x2 : grid[i][j].field_0x2;
s32 x1 = grid[i][j].field_0x4;
s32 y1 = grid[i - 1][j].field_0x6 > grid[i][j].field_0x6 ? grid[i - 1][j].field_0x6 : grid[i][j].field_0x6;
s32 room = GetTile(grid[i][j].field_0x0, grid[i][j].field_0x2)->room;
for (x = x0; x < x1; x++) {
for (y = y0; y < y1; y++) {
struct tile *t = GetTileSafe(x, y);
t->terrain_flags &= ~3;
t->terrain_flags |= 1;
t->room = room;
}
}
grid[i - 1][j].field_0x0 = x0;
grid[i - 1][j].field_0x4 = x1;
grid[i - 1][j].field_0x2 = y0;
grid[i - 1][j].field_0x6 = y1;
grid[i][j].field_0x11[1] = 1;
grid[i - 1][j].field_0x11[1] = 1;
grid[i][j].field_0xb = 0;
grid[i][j].field_0x11[0] = 1;
}
cell[-15].field_0x0 = x0;
cell[-15].field_0x4 = x1;
cell[-15].field_0x2 = y0;
cell[-15].field_0x6 = y1;
cell->field_0x11[1] = 1;
cell[-15].field_0x11[1] = 1;
cell->field_0xb = 0;
cell->field_0x11[0] = 1;
break;
}
case 1: {
s32 x0, y0, y1;
int x1;
s32 y, x;
s32 room;
if (j < 1) {
break;
}
if (cell[-1].field_0xb == 0) {
break;
}
if (cell[-1].field_0x8 != 0) {
break;
}
if (cell[-1].field_0xa == 0) {
break;
}
if (cell[-1].field_0x9 != 0 || cell[-1].field_0x11[1] != 0) {
break;
}
x0 = cell[-1].field_0x0 < cell->field_0x0 ? cell[-1].field_0x0 : cell->field_0x0;
y0 = cell[-1].field_0x2;
x1 = cell[-1].field_0x4 > cell->field_0x4 ? cell[-1].field_0x4 : cell->field_0x4;
y1 = cell->field_0x6;
room = GetTile(cell->field_0x0, cell->field_0x2)->room;
for (x = x0; x < x1; x++) {
for (y = y0; y < y1; y++) {
struct tile *t = GetTileSafe(x, y);
t->terrain_flags &= ~3;
t->terrain_flags |= 1;
t->room = room;
if (j >= 1 &&
grid[i][j - 1].field_0xb &&
!grid[i][j - 1].field_0x8 &&
grid[i][j - 1].field_0xa &&
!grid[i][j - 1].field_0x9 &&
!grid[i][j - 1].field_0x11[1]) {
s32 y, x;
s32 x0 = grid[i][j - 1].field_0x0 < grid[i][j].field_0x0 ? grid[i][j - 1].field_0x0 : grid[i][j].field_0x0;
s32 y0 = grid[i][j - 1].field_0x2;
s32 x1 = grid[i][j - 1].field_0x4 > grid[i][j].field_0x4 ? grid[i][j - 1].field_0x4 : grid[i][j].field_0x4;
s32 y1 = grid[i][j].field_0x6;
s32 room = GetTile(grid[i][j].field_0x0, grid[i][j].field_0x2)->room;
for (x = x0; x < x1; x++) {
for (y = y0; y < y1; y++) {
struct tile *t = GetTileSafe(x, y);
t->terrain_flags &= ~3;
t->terrain_flags |= 1;
t->room = room;
}
}
grid[i][j - 1].field_0x0 = x0;
grid[i][j - 1].field_0x4 = x1;
grid[i][j - 1].field_0x2 = y0;
grid[i][j - 1].field_0x6 = y1;
grid[i][j].field_0x11[1] = 1;
grid[i][j - 1].field_0x11[1] = 1;
grid[i][j].field_0xb = 0;
grid[i][j].field_0x11[0] = 1;
}
cell[-1].field_0x0 = x0;
cell[-1].field_0x4 = x1;
cell[-1].field_0x2 = y0;
cell[-1].field_0x6 = y1;
cell->field_0x11[1] = 1;
cell[-1].field_0x11[1] = 1;
cell->field_0xb = 0;
cell->field_0x11[0] = 1;
break;
}
case 2: {
s32 x0, y0, x1, y1, y, x;
s32 room;
if (i > grid_size_x - 2) {
break;
}
if (grid[i + 1][j].field_0xb == 0) {
break;
}
if (grid[i + 1][j].field_0x8 != 0) {
break;
}
if (grid[i + 1][j].field_0xa == 0) {
break;
}
if (grid[i + 1][j].field_0x9 != 0 || grid[i + 1][j].field_0x11[1] != 0) {
break;
}
x0 = cell->field_0x0;
y0 = cell->field_0x2 < grid[i + 1][j].field_0x2 ? cell->field_0x2 : grid[i + 1][j].field_0x2;
x1 = grid[i + 1][j].field_0x4;
y1 = cell->field_0x6 > grid[i + 1][j].field_0x6 ? cell->field_0x6 : grid[i + 1][j].field_0x6;
room = GetTile(cell->field_0x0, cell->field_0x2)->room;
for (x = x0; x < x1; x++) {
for (y = y0; y < y1; y++) {
struct tile *t = GetTileSafe(x, y);
t->terrain_flags &= ~3;
t->terrain_flags |= 1;
t->room = room;
if (i <= grid_size_x - 2 &&
grid[i + 1][j].field_0xb &&
!grid[i + 1][j].field_0x8 &&
grid[i + 1][j].field_0xa &&
!grid[i + 1][j].field_0x9 &&
!grid[i + 1][j].field_0x11[1]) {
s32 y, x;
s32 x0 = grid[i][j].field_0x0;
s32 y0 = grid[i][j].field_0x2 < grid[i + 1][j].field_0x2 ? grid[i][j].field_0x2 : grid[i + 1][j].field_0x2;
s32 x1 = grid[i + 1][j].field_0x4;
s32 y1 = grid[i][j].field_0x6 > grid[i + 1][j].field_0x6 ? grid[i][j].field_0x6 : grid[i + 1][j].field_0x6;
s32 room = GetTile(grid[i][j].field_0x0, grid[i][j].field_0x2)->room;
for (x = x0; x < x1; x++) {
for (y = y0; y < y1; y++) {
struct tile *t = GetTileSafe(x, y);
t->terrain_flags &= ~3;
t->terrain_flags |= 1;
t->room = room;
}
}
grid[i][j].field_0x0 = x0;
grid[i][j].field_0x4 = x1;
grid[i][j].field_0x2 = y0;
grid[i][j].field_0x6 = y1;
grid[i + 1][j].field_0x11[1] = 1;
grid[i][j].field_0x11[1] = 1;
grid[i + 1][j].field_0xb = 0;
grid[i + 1][j].field_0x11[0] = 1;
}
cell->field_0x0 = x0;
cell->field_0x4 = x1;
cell->field_0x2 = y0;
cell->field_0x6 = y1;
grid[i + 1][j].field_0x11[1] = 1;
cell->field_0x11[1] = 1;
grid[i + 1][j].field_0xb = 0;
grid[i + 1][j].field_0x11[0] = 1;
break;
}
case 3: {
s32 x0, y0, x1, y1, y, x;
s32 room;
if (j > grid_size_y - 2) {
break;
}
if (grid[i][j + 1].field_0xb == 0) {
break;
}
if (grid[i][j + 1].field_0x8 != 0) {
break;
}
if (grid[i][j + 1].field_0xa == 0) {
break;
}
if (grid[i][j + 1].field_0x9 != 0 || grid[i][j + 1].field_0x11[1] != 0) {
break;
}
x0 = cell->field_0x0 < grid[i][j + 1].field_0x0 ? cell->field_0x0 : grid[i][j + 1].field_0x0;
y0 = cell->field_0x2;
x1 = cell->field_0x4 > grid[i][j + 1].field_0x4 ? cell->field_0x4 : grid[i][j + 1].field_0x4;
y1 = grid[i][j + 1].field_0x6;
room = GetTile(cell->field_0x0, cell->field_0x2)->room;
for (x = x0; x < x1; x++) {
for (y = y0; y < y1; y++) {
struct tile *t = GetTileSafe(x, y);
t->terrain_flags &= ~3;
t->terrain_flags |= 1;
t->room = room;
if (j <= grid_size_y - 2 &&
grid[i][j + 1].field_0xb &&
!grid[i][j + 1].field_0x8 &&
grid[i][j + 1].field_0xa &&
!grid[i][j + 1].field_0x9 &&
!grid[i][j + 1].field_0x11[1]) {
s32 y, x;
s32 x0 = grid[i][j].field_0x0 < grid[i][j + 1].field_0x0 ? grid[i][j].field_0x0 : grid[i][j + 1].field_0x0;
s32 y0 = grid[i][j].field_0x2;
s32 x1 = grid[i][j].field_0x4 > grid[i][j + 1].field_0x4 ? grid[i][j].field_0x4 : grid[i][j + 1].field_0x4;
s32 y1 = grid[i][j + 1].field_0x6;
s32 room = GetTile(grid[i][j].field_0x0, grid[i][j].field_0x2)->room;
for (x = x0; x < x1; x++) {
for (y = y0; y < y1; y++) {
struct tile *t = GetTileSafe(x, y);
t->terrain_flags &= ~3;
t->terrain_flags |= 1;
t->room = room;
}
}
grid[i][j].field_0x0 = x0;
grid[i][j].field_0x4 = x1;
grid[i][j].field_0x2 = y0;
grid[i][j].field_0x6 = y1;
grid[i][j + 1].field_0x11[1] = 1;
grid[i][j].field_0x11[1] = 1;
grid[i][j + 1].field_0xb = 0;
grid[i][j + 1].field_0x11[0] = 1;
}
cell->field_0x0 = x0;
cell->field_0x4 = x1;
cell->field_0x2 = y0;
cell->field_0x6 = y1;
grid[i][j + 1].field_0x11[1] = 1;
cell->field_0x11[1] = 1;
grid[i][j + 1].field_0xb = 0;
grid[i][j + 1].field_0x11[0] = 1;
break;
}
}
}
}
}