Ejemplo n.º 1
0
pid_t pokemon_new_pid() {
	pid_t p;
	p.fields.ability = (u8)(rnd16() & 1);
	p.fields.form = 0;
	p.fields.gender_partial = (u8)(rnd16() & 127);
	p.fields.nature = (u8)((rnd16() % 25) & 31);

	// Use slash count to increase the shiny rate
	int splash_cnt = min(99, save_get_key(0x1A));

	if (rnd16() % 1000 <= splash_cnt / 10) {
		// Shiny rate of exactly 0.1% + (#Splash used) * 0.01% and maximum at 1%
		p.fields.is_shiny = 1;
	} else {
		p.fields.is_shiny = 0;
	}

	// Force shinyness via variable
	u16 *next_shiny_pokemon = var_access(NEXT_POKEMON_SHINY);
	dprintf("Next shinies %d\n", *next_shiny_pokemon);
	if(*next_shiny_pokemon > 0){
		p.fields.is_shiny = 1;
		(*next_shiny_pokemon)--;
	}
	return p;
}
static void inval(NPP instance, const ANPRectF& r, bool doAA) {
    const int inset = doAA ? -1 : 0;

    PluginObject *obj = reinterpret_cast<PluginObject*>(instance->pdata);
    NPRect inval;
    inval.left = rnd16(r.left, inset);
    inval.top = rnd16(r.top, inset);
    inval.right = rnd16(r.right, -inset);
    inval.bottom = rnd16(r.bottom, -inset);
    browser->invalidaterect(instance, &inval);
}
Ejemplo n.º 3
0
int wildbattle_sample_from_pdf(u8 *pdf, int size) {
	int p = rnd16() % 100;
	for (int i = 0; i < size; i++) {
		if (p < pdf[i]) return i;
		p -= pdf[i];
	}
	derrf("Pdf @x, size %d does not sum up to 100\n", pdf, size);
	return -1;
}
Ejemplo n.º 4
0
int map_wildbattle_init(bdata current, u16 behaviour_previous_tile) {
  u8 *byte_20386DC = (u8*)0x20386DC;
  if(*byte_20386DC == 1) return 0; // TODO: investigate
  if (*var_access(TRAINERSCHOOL_PROGRESS) <= 5) return 0; // Can not encounter until >= 6
  wild_pokemon_data *wild_pokemon_header = map_wild_pokemon_get_current();
  u8 pdf_type;
  u32 triggers_wildbattle = block_get_field(current, BDATA_TRIGGERS_WILDBATTLE);
  wild_pokemon_habitat *habitat = NULL;
  switch(triggers_wildbattle) {
    case TRIGGERS_WILDBATTLE_GRASS: {
      habitat = wild_pokemon_header->grass;
      pdf_type = 0;
      break;
    }
    case TRIGGERS_WILDBATTLE_WATER: {
      if(!overworld_flag_get(8)) return 0;
      habitat = wild_pokemon_header->water;
      pdf_type = 1;
      break;
    }
    default:
      return 0;
  }

  if(!habitat) return 0;
  u32 behaviour = block_get_field(current, BDATA_BEHAVIOUR);
  // With 40% entering a new "patch" does not provide an encounter
  if(behaviour != behaviour_previous_tile && (rnd16() % 100) >= 60) return 0;
  if(!wildbattle_does_pokemon_appear_by_frequency(habitat->frequency, 0)) {
    wildbattle_increase_chance(habitat->frequency);
    return 0;
  }
  if(!wildbattle_initialize_by_habitat(habitat, pdf_type, 1)) {
    wildbattle_increase_chance(habitat->frequency);
    return 0;
  }
  if (*var_access(TRAINERSCHOOL_PROGRESS) <= 6) {
	  // Start a wildbattle script instead
	  dprintf("Started script\n");
	  overworld_script_init(ow_script_trainerschool_wildbattle);
  } else {
	  wildbattle_start();
  }
  return 1;
}
Ejemplo n.º 5
0
static unsigned int rnd(void) { return (rnd16() << 16) | rnd16(); }