Advertisement
Bond697

XFR Pokerus

Feb 4th, 2012
908
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.32 KB | None | 0 0
  1. /**
  2. Infection chance is 3 in 65536
  3. 1-7 have 14% chance (7 a bit less)
  4. 9-F less than 0.5%
  5.  
  6. Initial duration for strain i is 1+i%4
  7.  
  8. Consequence: the following strains are illegal:
  9. 0x, 13, 14, 24, 42, 43, 44, 53, 54, 64,
  10. 8x, 93, 94, A4, C2, C3, C4, D3, D4, E4
  11.  
  12. The infected Pokémon is chosen randomly in the party.
  13. You can't infect an egg from a wild battle.
  14. An infected/cured Pokémon can't get a different strain.
  15. Strain 0x will always transform into 10 regardless of duration
  16.  
  17. xfr
  18. **/
  19.  
  20. typedef enum {
  21.  DexNumber=0x05,
  22.  PokerusByte=0x97,
  23.  IsEgg=0x4C,
  24.  Happiness=0x09,
  25.  ...
  26. } Stat;
  27.  
  28. typedef struct {
  29.  PartyPkm *target;
  30.  Stat stat;
  31.  uint value;
  32. } PartyPkmStat;
  33.  
  34. PartyPkm *GetPartyPkm(void *PartyStart, uint position)
  35. {
  36.  return (PartyPkm*)(PartyStart+8+position*220);
  37. }
  38.  
  39. // @0201B054
  40. void GeneratePokerus(void *PartyStart)
  41. {
  42.  PartyPkmStat s;
  43.  uint i, party_count, pkrs_bitmask, dex, isEgg;
  44.  
  45.  party_count = (uint)*(PartyStart+4);
  46.  pkrs_bitmask = 0;
  47.  
  48.  for(i=0; i<=party_count; i++)
  49.  {
  50.   s.target = GetPartyPkm(PartyStart, i);
  51.   s.stat = PokerusByte;
  52.   GetPokemonStat(&s);
  53.  
  54.   if(s.value) pkrs_bitmask |= 1<<i;
  55.  }
  56.  
  57.  // 3 in 0x10000 chance
  58.  if((MTRand()>>16) & 0x3FFF == 0)
  59.  {
  60.   do
  61.   {
  62.    i = (MTRand()*party_count)>>32;
  63.    s.target = GetPartyPkm(PartyStart, i);
  64.  
  65.    s.stat = DexNumber;
  66.    GetPokemonStat(&s);
  67.    dex = s.value;
  68.  
  69.    s.stat = IsEgg;
  70.    GetPokemonStat(&s);
  71.    isEgg = s.value;
  72.   }
  73.   while(!dex || isEgg);
  74.  
  75.   // Do nothing if it already has it
  76.   if(pkrs_bitmask & (1<<i)) return;
  77.  
  78.   do
  79.   {
  80.    // Generate strain and duration
  81.    i = MTRand()>>24;
  82.   }
  83.   while(!(i&7));
  84.  
  85.   if(i>>4) i &= 7;
  86.   i = ((i | i<<4)&0xF3)+1; // duration (1-4 days)
  87.  
  88.   s.stat = PokerusByte;
  89.   s.value = i;
  90.   SetPokemonStat(&s);  
  91.  }
  92. }
  93.  
  94. // @0201B11C
  95. void DecayPokerus(void *PartyStart, uint8 days)
  96. {
  97.  PartyPkmStat s;
  98.  uint i, party_count, dex, pkr;
  99.  
  100.  party_count = (uint)*(PartyStart+4);
  101.  for(i=0; i<=party_count; i++)
  102.  {
  103.   s.target = GetPartyPkm(PartyStart, i);
  104.  
  105.   s.stat = DexNumber;
  106.   GetPokemonStat(&s);
  107.   dex = s.value;
  108.  
  109.   s.stat = PokerusByte;
  110.   GetPokemonStat(&s);
  111.   pkr = s.value & 0xFF;
  112.  
  113.   if(!dex || !(pkr & 0xF)) continue;
  114.   else if(!(pkr>>4)) pkr = 0x10;
  115.   else if((pkr & 0xF)<days && days<=4) pkr -= days;
  116.   else pkr &= 0xF0;
  117.  
  118.   s.value = pkr;
  119.   SetPokemonStat(&s);
  120.  }
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement