From 145e90483b2a30698f917f62e585aa7fa4794588 Mon Sep 17 00:00:00 2001 From: YamaArashi Date: Mon, 2 Jan 2017 00:41:28 -0800 Subject: event_data.c --- src/lottery_corner.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/lottery_corner.c') diff --git a/src/lottery_corner.c b/src/lottery_corner.c index f073688e0..2330d20ff 100644 --- a/src/lottery_corner.c +++ b/src/lottery_corner.c @@ -2,7 +2,7 @@ #include "lottery_corner.h" #include "rng.h" #include "string_util.h" -#include "var.h" +#include "event_data.h" extern u16 gScriptResult; extern u16 gSpecialVar_0x8004; -- cgit v1.2.3 From 370c7f78539698902907f262721fe60e606c774d Mon Sep 17 00:00:00 2001 From: ProjectRevoTPP Date: Wed, 4 Jan 2017 17:31:44 -0500 Subject: more labels (#159) * labels for tv.c and tv.s * match function prologue a little bit better * whoops * label and document lottery_corner.c * gSoftResetDisabled * add labels for main_menu.c * labels for metatile_behavior.c --- src/lottery_corner.c | 72 +++++++++++++++++++++++++++------------------------- 1 file changed, 38 insertions(+), 34 deletions(-) (limited to 'src/lottery_corner.c') diff --git a/src/lottery_corner.c b/src/lottery_corner.c index 2330d20ff..54ba3c46d 100644 --- a/src/lottery_corner.c +++ b/src/lottery_corner.c @@ -3,6 +3,7 @@ #include "rng.h" #include "string_util.h" #include "event_data.h" +#include "species.h" extern u16 gScriptResult; extern u16 gSpecialVar_0x8004; @@ -16,32 +17,30 @@ static EWRAM_DATA u16 sOtIdDigit = 0; static u8 GetMatchingDigits(u16, u16); -void sub_8145A78(void) +void ResetLotteryCorner(void) { u16 rand = Random(); - sub_8145D14((Random() << 16) | rand); + SetLotteryNumber((Random() << 16) | rand); VarSet(0x4045, 0); } -void sub_8145AA4(u16 a) +void SetRandomLotteryNumber(u16 i) { u32 var = Random(); - while(--a != 0xFFFF) - { + while(--i != 0xFFFF) var = var * 1103515245 + 12345; - } - sub_8145D14(var); + + SetLotteryNumber(var); } -void sub_8145AEC(void) +void RetrieveLotteryNumber(void) { - u16 a = sub_8145D3C(); - gScriptResult = a; + u16 lottoNumber = GetLotteryNumber(); + gScriptResult = lottoNumber; } -//Script special function void PickLotteryCornerTicket(void) { u16 i; @@ -57,41 +56,44 @@ void PickLotteryCornerTicket(void) struct Pokemon *pkmn = &gPlayerParty[i]; // UB: Too few arguments for function GetMonData - if(GetMonData(pkmn, MON_DATA_SPECIES) != 0) + if(GetMonData(pkmn, MON_DATA_SPECIES) != SPECIES_NONE) { + // do not calculate ticket values for eggs. if(!GetMonData(pkmn, MON_DATA_IS_EGG)) { u32 otId = GetMonData(pkmn, MON_DATA_OT_ID); - u8 a = GetMatchingDigits(gScriptResult, otId); + u8 numMatchingDigits = GetMatchingDigits(gScriptResult, otId); - if(a > gSpecialVar_0x8004 && a > 1) + if(numMatchingDigits > gSpecialVar_0x8004 && numMatchingDigits > 1) { - gSpecialVar_0x8004 = a - 1; + gSpecialVar_0x8004 = numMatchingDigits - 1; box = 14; slot = i; } } } - else + else // pokemon are always arranged from populated spots first to unpopulated, so the moment a NONE species is found, that's the end of the list. break; } + // player has 14 boxes. for(i = 0; i < 14; i++) { - for(j = 0; j < 0x1E; j++) + // player has 30 slots per box. + for(j = 0; j < 30; j++) { struct BoxPokemon *pkmn = &gPokemonStorage.boxes[i][j]; // UB: Too few arguments for function GetMonData - if(GetBoxMonData(pkmn, MON_DATA_SPECIES) != 0 && + if(GetBoxMonData(pkmn, MON_DATA_SPECIES) != SPECIES_NONE && !GetBoxMonData(pkmn, MON_DATA_IS_EGG)) { u32 otId = GetBoxMonData(pkmn, MON_DATA_OT_ID); - u8 a = GetMatchingDigits(gScriptResult, otId); + u8 numMatchingDigits = GetMatchingDigits(gScriptResult, otId); - if(a > gSpecialVar_0x8004 && a > 1) + if(numMatchingDigits > gSpecialVar_0x8004 && numMatchingDigits > 1) { - gSpecialVar_0x8004 = a - 1; + gSpecialVar_0x8004 = numMatchingDigits - 1; box = i; slot = j; } @@ -120,7 +122,7 @@ void PickLotteryCornerTicket(void) static u8 GetMatchingDigits(u16 winNumber, u16 otId) { u8 i; - u8 matchingDigits = 0; //Why not just use i? + u8 matchingDigits = 0; for(i = 0; i < 5; i++) { @@ -139,24 +141,26 @@ static u8 GetMatchingDigits(u16 winNumber, u16 otId) return matchingDigits; } -void sub_8145D14(u32 a) +// lottery numbers go from 0 to 99999, not 65535 (0xFFFF). interestingly enough, the function that calls GetLotteryNumber shifts to u16, so it cant be anything above 65535 anyway. +void SetLotteryNumber(u32 lotteryNum) { - u16 b = a >> 16; - u16 c = a; - - VarSet(0x404B, c); - VarSet(0x404C, b); + u16 lowNum = lotteryNum >> 16; + u16 highNum = lotteryNum; + + VarSet(0x404B, highNum); + VarSet(0x404C, lowNum); } -u32 sub_8145D3C(void) +u32 GetLotteryNumber(void) { - u16 var1 = VarGet(0x404B); - u16 var2 = VarGet(0x404C); + u16 highNum = VarGet(0x404B); + u16 lowNum = VarGet(0x404C); - return (var2 << 16) | var1; + return (lowNum << 16) | highNum; } -void unref_sub_8145D64(u16 a) +// interestingly, this may have been the original lottery number set function, but GF tried to change it to 32-bit later but didnt finish changing all calls as one GetLotteryNumber still shifts to u16. +void SetLotteryNumber16_Unused(u16 lotteryNum) { - sub_8145D14(a); + SetLotteryNumber(lotteryNum); } -- cgit v1.2.3 From af4845a4a1db74dfdb3668944fc77e3fb4983052 Mon Sep 17 00:00:00 2001 From: YamaArashi Date: Wed, 4 Jan 2017 20:16:15 -0800 Subject: add some vars --- src/lottery_corner.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/lottery_corner.c') diff --git a/src/lottery_corner.c b/src/lottery_corner.c index 54ba3c46d..4d80f86c2 100644 --- a/src/lottery_corner.c +++ b/src/lottery_corner.c @@ -22,7 +22,7 @@ void ResetLotteryCorner(void) u16 rand = Random(); SetLotteryNumber((Random() << 16) | rand); - VarSet(0x4045, 0); + VarSet(VAR_POKELOT_PRIZE, 0); } void SetRandomLotteryNumber(u16 i) @@ -147,14 +147,14 @@ void SetLotteryNumber(u32 lotteryNum) u16 lowNum = lotteryNum >> 16; u16 highNum = lotteryNum; - VarSet(0x404B, highNum); - VarSet(0x404C, lowNum); + VarSet(VAR_POKELOT_RND1, highNum); + VarSet(VAR_POKELOT_RND2, lowNum); } u32 GetLotteryNumber(void) { - u16 highNum = VarGet(0x404B); - u16 lowNum = VarGet(0x404C); + u16 highNum = VarGet(VAR_POKELOT_RND1); + u16 lowNum = VarGet(VAR_POKELOT_RND2); return (lowNum << 16) | highNum; } -- cgit v1.2.3 From eeacf2f835460ce922d53fb5f663fc9831a2c1d3 Mon Sep 17 00:00:00 2001 From: YamaArashi Date: Thu, 5 Jan 2017 20:43:28 -0800 Subject: lottery prize data --- src/lottery_corner.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/lottery_corner.c') diff --git a/src/lottery_corner.c b/src/lottery_corner.c index 4d80f86c2..c18aeef48 100644 --- a/src/lottery_corner.c +++ b/src/lottery_corner.c @@ -4,17 +4,25 @@ #include "string_util.h" #include "event_data.h" #include "species.h" +#include "items.h" extern u16 gScriptResult; extern u16 gSpecialVar_0x8004; extern struct Pokemon gPlayerParty[6]; extern struct PokemonStorage gPokemonStorage; extern u16 gSpecialVar_0x8005; -extern u16 gUnknown_0840CB04[]; extern u16 gSpecialVar_0x8006; static EWRAM_DATA u16 sWinNumberDigit = 0; static EWRAM_DATA u16 sOtIdDigit = 0; +static const u16 sLotteryPrizes[] = +{ + ITEM_PP_UP, + ITEM_EXP_SHARE, + ITEM_MAX_REVIVE, + ITEM_MASTER_BALL, +}; + static u8 GetMatchingDigits(u16, u16); void ResetLotteryCorner(void) @@ -103,7 +111,7 @@ void PickLotteryCornerTicket(void) if(gSpecialVar_0x8004 != 0) { - gSpecialVar_0x8005 = gUnknown_0840CB04[gSpecialVar_0x8004 - 1]; + gSpecialVar_0x8005 = sLotteryPrizes[gSpecialVar_0x8004 - 1]; if(box == 14) { -- cgit v1.2.3 From 648c6c7093f5173694562929f615380f297ad306 Mon Sep 17 00:00:00 2001 From: Marijn van der Werf Date: Tue, 17 Jan 2017 13:41:12 +0100 Subject: Move `gStringVar` declarations to text.h --- src/lottery_corner.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/lottery_corner.c') diff --git a/src/lottery_corner.c b/src/lottery_corner.c index c18aeef48..bfe5998c0 100644 --- a/src/lottery_corner.c +++ b/src/lottery_corner.c @@ -4,6 +4,7 @@ #include "string_util.h" #include "event_data.h" #include "species.h" +#include "text.h" #include "items.h" extern u16 gScriptResult; -- cgit v1.2.3 From c9722602cb47eb5b6ecbccddf13df5f286a8ef7b Mon Sep 17 00:00:00 2001 From: Marijn van der Werf Date: Tue, 17 Jan 2017 14:13:04 +0100 Subject: Sort includes --- src/lottery_corner.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/lottery_corner.c') diff --git a/src/lottery_corner.c b/src/lottery_corner.c index bfe5998c0..ca65edc2e 100644 --- a/src/lottery_corner.c +++ b/src/lottery_corner.c @@ -1,11 +1,11 @@ #include "global.h" #include "lottery_corner.h" -#include "rng.h" -#include "string_util.h" #include "event_data.h" +#include "items.h" +#include "rng.h" #include "species.h" +#include "string_util.h" #include "text.h" -#include "items.h" extern u16 gScriptResult; extern u16 gSpecialVar_0x8004; -- cgit v1.2.3 From 801877553db80267a62c0c3c0b2805b6716d1ef9 Mon Sep 17 00:00:00 2001 From: Marijn van der Werf Date: Tue, 17 Jan 2017 14:38:44 +0100 Subject: Remove trailing whitespace --- src/lottery_corner.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'src/lottery_corner.c') diff --git a/src/lottery_corner.c b/src/lottery_corner.c index ca65edc2e..3d456f372 100644 --- a/src/lottery_corner.c +++ b/src/lottery_corner.c @@ -37,11 +37,11 @@ void ResetLotteryCorner(void) void SetRandomLotteryNumber(u16 i) { u32 var = Random(); - + while(--i != 0xFFFF) var = var * 1103515245 + 12345; - SetLotteryNumber(var); + SetLotteryNumber(var); } void RetrieveLotteryNumber(void) @@ -56,14 +56,14 @@ void PickLotteryCornerTicket(void) u16 j; u32 box; u32 slot; - + gSpecialVar_0x8004 = 0; slot = 0; box = 0; for(i = 0; i < 6; i++) { struct Pokemon *pkmn = &gPlayerParty[i]; - + // UB: Too few arguments for function GetMonData if(GetMonData(pkmn, MON_DATA_SPECIES) != SPECIES_NONE) { @@ -72,7 +72,7 @@ void PickLotteryCornerTicket(void) { u32 otId = GetMonData(pkmn, MON_DATA_OT_ID); u8 numMatchingDigits = GetMatchingDigits(gScriptResult, otId); - + if(numMatchingDigits > gSpecialVar_0x8004 && numMatchingDigits > 1) { gSpecialVar_0x8004 = numMatchingDigits - 1; @@ -84,7 +84,7 @@ void PickLotteryCornerTicket(void) else // pokemon are always arranged from populated spots first to unpopulated, so the moment a NONE species is found, that's the end of the list. break; } - + // player has 14 boxes. for(i = 0; i < 14; i++) { @@ -92,14 +92,14 @@ void PickLotteryCornerTicket(void) for(j = 0; j < 30; j++) { struct BoxPokemon *pkmn = &gPokemonStorage.boxes[i][j]; - + // UB: Too few arguments for function GetMonData if(GetBoxMonData(pkmn, MON_DATA_SPECIES) != SPECIES_NONE && !GetBoxMonData(pkmn, MON_DATA_IS_EGG)) { u32 otId = GetBoxMonData(pkmn, MON_DATA_OT_ID); u8 numMatchingDigits = GetMatchingDigits(gScriptResult, otId); - + if(numMatchingDigits > gSpecialVar_0x8004 && numMatchingDigits > 1) { gSpecialVar_0x8004 = numMatchingDigits - 1; @@ -109,11 +109,11 @@ void PickLotteryCornerTicket(void) } } } - + if(gSpecialVar_0x8004 != 0) { gSpecialVar_0x8005 = sLotteryPrizes[gSpecialVar_0x8004 - 1]; - + if(box == 14) { gSpecialVar_0x8006 = 0; @@ -132,12 +132,12 @@ static u8 GetMatchingDigits(u16 winNumber, u16 otId) { u8 i; u8 matchingDigits = 0; - + for(i = 0; i < 5; i++) { sWinNumberDigit = winNumber % 10; sOtIdDigit = otId % 10; - + if(sWinNumberDigit == sOtIdDigit) { winNumber = winNumber / 10; @@ -164,7 +164,7 @@ u32 GetLotteryNumber(void) { u16 highNum = VarGet(VAR_POKELOT_RND1); u16 lowNum = VarGet(VAR_POKELOT_RND2); - + return (lowNum << 16) | highNum; } -- cgit v1.2.3 From bcaab977727ded65c9eeaef9dbef9e9441d26fb7 Mon Sep 17 00:00:00 2001 From: YamaArashi Date: Sat, 21 Jan 2017 16:48:06 -0800 Subject: formatting --- src/lottery_corner.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'src/lottery_corner.c') diff --git a/src/lottery_corner.c b/src/lottery_corner.c index 3d456f372..66e1238ef 100644 --- a/src/lottery_corner.c +++ b/src/lottery_corner.c @@ -38,7 +38,7 @@ void SetRandomLotteryNumber(u16 i) { u32 var = Random(); - while(--i != 0xFFFF) + while (--i != 0xFFFF) var = var * 1103515245 + 12345; SetLotteryNumber(var); @@ -60,20 +60,20 @@ void PickLotteryCornerTicket(void) gSpecialVar_0x8004 = 0; slot = 0; box = 0; - for(i = 0; i < 6; i++) + for (i = 0; i < 6; i++) { struct Pokemon *pkmn = &gPlayerParty[i]; // UB: Too few arguments for function GetMonData - if(GetMonData(pkmn, MON_DATA_SPECIES) != SPECIES_NONE) + if (GetMonData(pkmn, MON_DATA_SPECIES) != SPECIES_NONE) { // do not calculate ticket values for eggs. - if(!GetMonData(pkmn, MON_DATA_IS_EGG)) + if (!GetMonData(pkmn, MON_DATA_IS_EGG)) { u32 otId = GetMonData(pkmn, MON_DATA_OT_ID); u8 numMatchingDigits = GetMatchingDigits(gScriptResult, otId); - if(numMatchingDigits > gSpecialVar_0x8004 && numMatchingDigits > 1) + if (numMatchingDigits > gSpecialVar_0x8004 && numMatchingDigits > 1) { gSpecialVar_0x8004 = numMatchingDigits - 1; box = 14; @@ -86,21 +86,21 @@ void PickLotteryCornerTicket(void) } // player has 14 boxes. - for(i = 0; i < 14; i++) + for (i = 0; i < 14; i++) { // player has 30 slots per box. - for(j = 0; j < 30; j++) + for (j = 0; j < 30; j++) { struct BoxPokemon *pkmn = &gPokemonStorage.boxes[i][j]; // UB: Too few arguments for function GetMonData - if(GetBoxMonData(pkmn, MON_DATA_SPECIES) != SPECIES_NONE && + if (GetBoxMonData(pkmn, MON_DATA_SPECIES) != SPECIES_NONE && !GetBoxMonData(pkmn, MON_DATA_IS_EGG)) { u32 otId = GetBoxMonData(pkmn, MON_DATA_OT_ID); u8 numMatchingDigits = GetMatchingDigits(gScriptResult, otId); - if(numMatchingDigits > gSpecialVar_0x8004 && numMatchingDigits > 1) + if (numMatchingDigits > gSpecialVar_0x8004 && numMatchingDigits > 1) { gSpecialVar_0x8004 = numMatchingDigits - 1; box = i; @@ -110,11 +110,11 @@ void PickLotteryCornerTicket(void) } } - if(gSpecialVar_0x8004 != 0) + if (gSpecialVar_0x8004 != 0) { gSpecialVar_0x8005 = sLotteryPrizes[gSpecialVar_0x8004 - 1]; - if(box == 14) + if (box == 14) { gSpecialVar_0x8006 = 0; GetMonData(&gPlayerParty[slot], MON_DATA_NICKNAME, gStringVar1); @@ -133,12 +133,12 @@ static u8 GetMatchingDigits(u16 winNumber, u16 otId) u8 i; u8 matchingDigits = 0; - for(i = 0; i < 5; i++) + for (i = 0; i < 5; i++) { sWinNumberDigit = winNumber % 10; sOtIdDigit = otId % 10; - if(sWinNumberDigit == sOtIdDigit) + if (sWinNumberDigit == sOtIdDigit) { winNumber = winNumber / 10; otId = otId / 10; -- cgit v1.2.3 From 4d2b22a899c11dfcacfec6889968ab01655a3fe3 Mon Sep 17 00:00:00 2001 From: Marijn van der Werf Date: Fri, 26 May 2017 14:53:51 +0200 Subject: Add headers --- src/lottery_corner.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/lottery_corner.c') diff --git a/src/lottery_corner.c b/src/lottery_corner.c index 66e1238ef..c2c25b9ac 100644 --- a/src/lottery_corner.c +++ b/src/lottery_corner.c @@ -9,7 +9,6 @@ extern u16 gScriptResult; extern u16 gSpecialVar_0x8004; -extern struct Pokemon gPlayerParty[6]; extern struct PokemonStorage gPokemonStorage; extern u16 gSpecialVar_0x8005; extern u16 gSpecialVar_0x8006; -- cgit v1.2.3