void sample_random_loose_floor (int room) { switch (prandom (2)) { case 0: play_sample (loose_floor_00_sample, room); case 1: play_sample (loose_floor_01_sample, room); case 2: play_sample (loose_floor_02_sample, room); } }
// seg000:1009 void __pascal far check_fall_flo() { // Special event: falling floors if (current_level == 13 && (drawn_room == 23 || drawn_room == 16)) { get_room_address(curr_room = room_A); for (curr_tilepos = 22; curr_tilepos <= 27; ++curr_tilepos) { make_loose_fall(-(prandom(0xFF) & 0x0F)); } } }
const rect& tile::overlay_texture_area() const { if(terrain_->overlay_texture_areas().empty()) { static const rect r(0,0,0,0); return r; } return terrain_->overlay_texture_areas()[prandom(loc_)%terrain_->overlay_texture_areas().size()]; }
int main (int argc, char **argv) { if (argc < 2) { printf("Usage: %s [kb]\n",argv[0]); printf(" kb is an int for KB of data output\n"); return 2; } else { return prandom(atol(argv[1])); } }
static int rankselect(int popsize) { int num = int( prandom() * popsize * (popsize + 1) * 0.5 ); for (int i = 0; i < popsize; i++) { if (num < (popsize - i)) { return i; } num -= (popsize - i); } return 0; // <- this shouldn't happen }
enum dir random_dir (void) { switch (prandom (3)) { case 0: return LEFT; case 1: return RIGHT; case 2: return ABOVE; case 3: return BELOW; default: assert (false); return LEFT; } }
static void draw_stars (ALLEGRO_BITMAP *bitmap, struct star s[], struct stars_bitmap *sb, size_t count, enum vm vm) { if (anim_cycle % 4) { draw_bitmapc (sb->b, bitmap, &sb->c, 0); return; } int i = prandom (count - 1); s[i].color = next_color (s[i].color); draw_star (&s[i], sb, vm); draw_bitmapc (sb->b, bitmap, &sb->c, 0); }
static void draw_stars (ALLEGRO_BITMAP *bitmap, struct stars *stars, enum vm vm) { if (! stars->count) return; if (anim_cycle % 4 || game_paused) { draw_bitmapc (stars->b, bitmap, &stars->c, 0); return; } int i = prandom (stars->count - 1); stars->s[i].color = next_color (stars->s[i].color); draw_star (stars, i, vm); draw_bitmapc (stars->b, bitmap, &stars->c, 0); }
void AgentSet::init(int agent, int trail_num) { if (m_release_locations.size()) { int which = pafrand() % m_release_locations.size(); at(agent).onInit( m_release_locations[which], trail_num ); } else { const PointMap& map = at(agent).getPointMap(); PixelRef pix; do { pix = map.pickPixel(prandom()); } while (!map.getPoint(pix).filled()); at(agent).onInit(pix, trail_num); } }
// seg001:00E6 void __pascal far draw_proom_drects() { draw_princess_room_bg(); #ifdef USE_FADE if (!is_global_fading) { #endif while (drects_count--) { copy_screen_rect(&drects[drects_count]); } #ifdef USE_FADE } #endif drects_count = 0; if (cutscene_wait_frames & 1) { draw_star(prandom(N_STARS - 1), 1); } }
//********************************************************************************************************************** vector<string> ParsimonyCommand::setParameters(){ try { CommandParameter ptree("tree", "InputTypes", "", "", "none", "none", "none","parsimony-psummary",false,true,true); parameters.push_back(ptree); CommandParameter pname("name", "InputTypes", "", "", "NameCount", "none", "none","",false,false,true); parameters.push_back(pname); CommandParameter pcount("count", "InputTypes", "", "", "NameCount-CountGroup", "none", "none","",false,false,true); parameters.push_back(pcount); CommandParameter pgroup("group", "InputTypes", "", "", "CountGroup", "none", "none","",false,false,true); parameters.push_back(pgroup); CommandParameter pgroups("groups", "String", "", "", "", "", "","",false,false); parameters.push_back(pgroups); CommandParameter prandom("random", "String", "", "", "", "", "","",false,false); parameters.push_back(prandom); CommandParameter piters("iters", "Number", "", "1000", "", "", "","",false,false); parameters.push_back(piters); CommandParameter pprocessors("processors", "Number", "", "1", "", "", "","",false,false,true); parameters.push_back(pprocessors); CommandParameter pseed("seed", "Number", "", "0", "", "", "","",false,false); parameters.push_back(pseed); CommandParameter pinputdir("inputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(pinputdir); CommandParameter poutputdir("outputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(poutputdir); vector<string> myArray; for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { m->errorOut(e, "ParsimonyCommand", "setParameters"); exit(1); } }
struct pos * random_pos (struct level *l, struct pos *p) { return new_pos (p, l, prandom (ROOMS - 2) + 1, prandom (FLOORS - 1), prandom (PLACES - 1)); }
void fight_mechanics (struct anim *k) { if (k->sword_immune > 0) k->sword_immune--; /* 'ke' is the attacking part */ struct anim *ke = get_anim_by_id (k->enemy_id); if (! ke || ke->enemy_id != k->id) return; fight_inversion_mechanics (k, ke); if (! is_attacking (ke) || is_sword_hit (k)) return; if (! ke->attack_range_far) ke->attack_range_far = (is_in_range (k, ke, ATTACK_RANGE + 16) && ke->i == 0); if (! ke->attack_range_near) ke->attack_range_near = (is_in_range (k, ke, ATTACK_RANGE) && ke->i == 0); if (! ke->enemy_defended_my_attack) ke->enemy_defended_my_attack = (ke->i < 4 && k->key.up && ke->attack_range_far) || (ke->attack_range_far && ! ke->attack_range_near); if (is_walkingf (k) || is_attacking (k) || ! is_in_fight_mode (k)) ke->enemy_defended_my_attack = 0; bool walkb = ((k->f.dir == RIGHT) && k->key.left) || ((k->f.dir == LEFT) && k->key.right); if (! ke->enemy_counter_attacked_myself) ke->enemy_counter_attacked_myself = (ke->enemy_defended_my_attack && k->key.shift && prandom (99) <= k->skill.counter_attack_prob && (ke->attack_range_near || k->attack_range_near) && ! walkb); if (! ke->i_counter_defended) ke->i_counter_defended = (ke->enemy_counter_attacked_myself && ke->key.up && prandom (99) <= ke->skill.counter_defense_prob); if (! k->hurt_enemy_in_counter_attack) k->hurt_enemy_in_counter_attack = (ke->enemy_counter_attacked_myself && ! ke->i_counter_defended); /* printf ("ke->attack_range_near: %i\n", ke->attack_range_near); */ /* printf ("ke->enemy_defended_my_attack = %i, ke->i = %i, k->key.up = %i\n", */ /* ke->enemy_defended_my_attack, ke->i, k->key.up); */ if (! ke->enemy_defended_my_attack && is_at_hit_frame (ke) && ! is_on_back (ke, k) && (ke->attack_range_far || ! is_in_fight_mode (k)) && ((is_in_range (k, ke, HIT_RANGE + 4) && is_in_fight_mode (k)) || (is_in_range (k, ke, ATTACK_RANGE) && ! is_in_fight_mode (k)))) fight_hit (k, ke); else if (ke->hurt_enemy_in_counter_attack && is_at_hit_frame (ke) && ! is_on_back (ke, k)) fight_hit (k, ke); else if (ke->enemy_defended_my_attack == 1 && is_at_defendable_attack_frame (ke)) { if (is_in_range (k, ke, HIT_RANGE + 8) || is_defending (k)) { backoff_from_range (ke, k, ATTACK_RANGE - 20, false, false); get_in_range (ke, k, ATTACK_RANGE - 6, false, false); put_at_attack_frame (ke); put_at_defense_frame (k); } else ke->enemy_defended_my_attack = false; } /* printf ("id: %i, ad: %i, ca: %i, cd: %i, i: %i, hurt: %i\n\ */ /* id: %i, ad: %i, ca: %i, cd: %i, i: %i, hurt: %i\n\ */ /* -------------------------------\n", */ /* k->id, k->enemy_defended_my_attack, k->enemy_counter_attacked_myself, k->i_counter_defended, k->i, k->hurt, */ /* ke->id, ke->enemy_defended_my_attack, ke->enemy_counter_attacked_myself, ke->i_counter_defended, ke->i, ke->hurt); */ }
void fight_ai (struct anim *k) { /* non-fightable characters don't fight */ if (! is_fightable_anim (k)) return; /* controllables and non-fighters doesn't need AI to fight */ if (k->controllable || ! k->fight) return; /* if forgetting about an enemy, no need to fight */ if (k->enemy_refraction > 0) return; /* without an enemy or awareness, no need to fight */ if (k->enemy_id == -1) { if (is_in_fight_mode (k)) leave_fight_mode (k); return; } /* first thing, enter in fight mode */ if (! is_in_fight_mode (k)) { enter_fight_mode (k); return; } /* who's the enemy? */ struct anim *ke = get_anim_by_id (k->enemy_id); /* what's the facing opposite direction? */ enum dir odir = (k->f.dir == LEFT) ? RIGHT : LEFT; /* get positions */ struct pos p, pe; survey (_m, pos, &k->f, NULL, &p, NULL); survey ((k->f.dir != ke->f.dir) ? _m : _mba, pos, &ke->f, NULL, &pe, NULL); pos2room (&pe, p.room, &pe); /* remember the place the enemy was last seen */ if (pe.room == p.room && pe.floor == p.floor) k->enemy_pos = pe; else if (pe.floor > p.floor && is_valid_pos (&k->enemy_pos) && ! is_strictly_traversable (&k->enemy_pos)) k->enemy_pos.place = pe.place; if (is_valid_pos (&k->enemy_pos) && is_strictly_traversable (&k->enemy_pos)) { struct pos pp; int d = (p.place < k->enemy_pos.place) ? -1 : +1; while (is_strictly_traversable (prel (&k->enemy_pos, &pp, +0, d))) k->enemy_pos = pp; } /* prevent enemy from passing through */ if (ke->type == KID && is_in_range (k, ke, ATTACK_RANGE) && ! is_in_fight_mode (ke) && ! ke->immortal && ! (is_kid_climb (&ke->f) && ke->i <= 7) && ke->f.dir != k->f.dir && ke->current_lives > 0 && ke->has_sword && ! is_kid_fall (&ke->f) && ! is_kid_hang (&ke->f) && ! is_kid_jump_air (&ke->f) && ! is_kid_run_jump_air (&ke->f) && is_safe_to_attack (ke)) { place_on_the_ground (&ke->f, &ke->f.c); kid_take_sword (ke); ke->auto_taken_sword = true; } /* prevent enemy from hiding near */ if (ke->type == KID && is_in_range (k, ke, INVERSION_RANGE) && ! is_in_fight_mode (ke) && ke->current_lives > 0) { if (is_safe_to_walkb (k)) fight_walkb (k); else if (is_safe_to_turn (k)) fight_turn (k); return; } /* if the enemy is on the back, turn */ if (is_on_back (k, ke) && is_anim_seeing (k, ke, odir) && p.floor == pe.floor && ! is_in_range (k, ke, INVERSION_RANGE)) { if (is_safe_to_turn (k)) fight_turn (k); else if (is_safe_to_walkb (k)) fight_walkb (k); return; } /* if too near to a wall, back off to have room for an attack */ if (fight_crel (k, +0, +1) == WALL && is_safe_to_walkb (k)) { fight_walkb (k); return; } /* /\* if the enemy can be followed in the opposite direction, turn *\/ */ /* if (! is_safe_to_follow (k, ke, k->f.dir) */ /* && is_safe_to_follow (k, ke, odir)) { */ /* fight_turn (k); */ /* return; */ /* } */ /* if the enemy is trying to bypass, attack him */ if (! is_in_fight_mode (ke) && ! ke->has_sword && ! is_kid_stairs (&ke->f) && ke->f.dir != k->f.dir && ke->current_lives > 0 && ! is_on_back (k, ke) && ((is_kid_run (&ke->f) && is_in_range (k, ke, 3 * PLACE_WIDTH - 4)) || (is_kid_run_jump (&ke->f) && is_in_range (k, ke, 4 * PLACE_WIDTH - 4)) || (is_kid_jump_air (&ke->f) && ke->i < 9 && is_in_range (k, ke, 4 * PLACE_WIDTH)))) { if (is_safe_to_attack (k)) fight_attack (k); else if (is_safe_to_walkb (k)) fight_walkb (k); return; } /* stays at least in the fight range. Advance, unless the enemy is not running towards you */ if (! is_in_range (k, ke, FIGHT_RANGE + 10) && ! is_kid_stairs (&ke->f) && (ke->f.dir == k->f.dir || p.room != pe.room || p.floor != pe.floor || ! (is_kid_run (&ke->f) || is_kid_run_jump (&ke->f) || is_kid_jump (&ke->f))) && is_safe_to_follow (k, ke, k->f.dir)) { fight_walkf (k); return; } /* if the enemy is not targeting you, do nothing more */ if (ke->enemy_id != -1 && ke->enemy_id != k->id) return; /* in fight range, if the enemy is not attacking, go towards attack range (with probability, unless the enemy is not in fight mode, then go immediately) */ if (is_in_range (k, ke, FIGHT_RANGE + 10) && ! is_in_range (k, ke, ATTACK_RANGE) && ! is_kid_stairs (&ke->f) && is_safe_to_follow (k, ke, k->f.dir) && (prandom (99) <= k->skill.advance_prob || ! is_in_fight_mode (ke)) && ! is_attacking (ke) && (! is_in_fight_mode (ke) || is_walking (ke) || ke->i >= 6 + prandom (24))) { fight_walkf (k); return; } /* in attack range, if being attacked, defend yourself (with probability) and counter attack (with probability handled elsewhere) */ if (is_in_range (k, ke, ATTACK_RANGE + 16) && ! is_on_back (k, ke) && (is_attacking (ke) && ke->i == 0) && (prandom (99) <= k->skill.defense_prob || k->refraction > 0) && ke->current_lives > 0) { fight_defense (k); fight_attack (k); return; } /* if attacking, counter defend (with probability handled elsewhere) */ if (is_in_range (k, ke, ATTACK_RANGE + 16) && is_attacking (k)) { fight_defense (k); fight_attack (k); return; } /* in attack range, if not being attacked, attack (with probability, unless the enemy is not in fight mode, then attack immediately) */ if (is_in_range (k, ke, ATTACK_RANGE) && ! is_attacking (ke) && ! is_on_back (k, ke) && ! is_kid_stairs (&ke->f) && ! ((is_kid_climb (&ke->f) || is_kid_successfully_climbing (&ke->f)) && ke->i >= 1) && ke->current_lives > 0 && (prandom (99) <= k->skill.attack_prob || ! is_in_fight_mode (ke))) { if (is_safe_to_attack (k)) fight_attack (k); else if (is_safe_to_walkb (k)) fight_walkb (k); return; } /* in hit range, back off (with probability) */ if (is_in_range (k, ke, HIT_RANGE - 10) && is_safe_to_walkb (k) && ! k->refraction && ! is_walkingb (ke) && prandom (99) <= k->skill.return_prob) { fight_walkb (k); return; } }
void draw_randomization (ALLEGRO_BITMAP *bitmap, struct pos *p, enum em em, enum vm vm) { ALLEGRO_BITMAP *wall_narrow_divider = NULL, *wall_wide_divider = NULL; if (vm == VGA) { wall_narrow_divider = apply_hue_palette (dv_wall_narrow_divider); wall_wide_divider = apply_hue_palette (dv_wall_wide_divider); } else if (em == DUNGEON) { wall_narrow_divider = de_wall_narrow_divider; wall_wide_divider = de_wall_wide_divider; } else { wall_narrow_divider = pe_wall_narrow_divider; wall_wide_divider = pe_wall_wide_divider; } if (peq (p, &mouse_pos)) { wall_narrow_divider = apply_palette (wall_narrow_divider, selection_palette); wall_wide_divider = apply_palette (wall_wide_divider, selection_palette); } seedp (p); prandom (1); r0 = prandom(1); r1 = prandom(4); r2 = prandom(1); r3 = prandom(4); wall_divider_00 = r2 ? wall_narrow_divider : wall_wide_divider; wall_divider_01 = r0 ? wall_narrow_divider : wall_wide_divider; enum wall_correlation wc = wall_correlation (p); switch (wc) { case WWW: if (prandom (4) == 0) draw_random_block (bitmap, p, em, vm); draw_divider_01 (bitmap, p, em, vm); draw_divider_00 (bitmap, p, em, vm); if (em == DUNGEON) { if (prandom(4) == 0) draw_right_mark (bitmap, p, prandom (3), vm); if (prandom(4) == 0) draw_left_mark (bitmap, p, prandom (4), vm); } break; case SWS: if (em == DUNGEON && prandom (6) == 0) draw_left_mark (bitmap, p, prandom (1), vm); break; case SWW: if (prandom (4) == 0) draw_random_block (bitmap, p, em, vm); draw_divider_01 (bitmap, p, em, vm); if (em == DUNGEON) { if (prandom(4) == 0) draw_right_mark (bitmap, p, prandom (3), vm); if (prandom(4) == 0) draw_left_mark (bitmap, p, prandom (3), vm); } break; case WWS: draw_divider_01 (bitmap, p, em, vm); draw_divider_00 (bitmap, p, em, vm); if (em == DUNGEON) { if (prandom(4) == 0) draw_right_mark (bitmap, p, prandom (1) + 2, vm); if (prandom(4) == 0) draw_left_mark (bitmap, p, prandom (4), vm); } break; default: error (-1, 0, "%s: unknown wall correlation (%i)", __func__, wc); } unseedp (); }