double test_calculate_chi_bf(void){ rpacket_t rp; storage_model_t sm; init_rpacket(&rp); init_storage_model(&sm); rk_state mt_state; irandom(&mt_state); int64_t j_blue_idx = 0; double D_BOUNDARY = compute_distance2boundary(&rp, &sm); rpacket_set_d_boundary(&rp, D_BOUNDARY); double D_LINE; // FIXME MR: return status of compute_distance2line() is ignored compute_distance2line(&rp, &sm, &D_LINE); rpacket_set_d_line(&rp, D_LINE); move_packet(&rp, &sm, 1e13); double d_line = rpacket_get_d_line(&rp); increment_j_blue_estimator(&rp, &sm, d_line, j_blue_idx); double DISTANCE = 1e13; montecarlo_line_scatter(&rp, &sm, DISTANCE, &mt_state); DISTANCE = 0.95e13; // MR: wrong: move_packet_across_shell_boundary() returns void move_packet_across_shell_boundary(&rp, &sm, DISTANCE, &mt_state); montecarlo_one_packet(&sm, &rp, 1, &mt_state); montecarlo_one_packet_loop(&sm, &rp, 1, &mt_state); DISTANCE = 1e13; montecarlo_thomson_scatter(&rp, &sm, DISTANCE, &mt_state); calculate_chi_bf(&rp, &sm); double res = rpacket_doppler_factor (&rp, &sm); dealloc_storage_model(&sm); return res; }
/* randomly select a move among (nocells * (noparts - 1)) move directions */ int select_cell(int nocells, int noparts, selected_cell_t scell[], allele tchrom[], cells_t cells[], parts_t parts[], cells_info_t cells_info[]) { int cell_no = irandom(0, nocells - 1); int selected = False; /* true if a cell is selected */ int nochecks = 0; /* number of cells tried */ while ((! selected) && (nochecks < nocells)) { nochecks++; int from = tchrom[cell_no]; int to = find_to_part(noparts, cell_no, from, cells, parts); /* no directions for this cell are feasible, so try another */ if ((to < 0) || (parts[from].pmax_cells < 1)) { cell_no = (cell_no + 1) % nocells; } else { selected = True; scell[0].mov_cell_no = cell_no; scell[0].from_part = from; scell[0].to_part = to; scell[0].mov_gain = calculate_gain(scell[0].mov_cell_no, scell[0].from_part, scell[0].to_part, cells_info); } /* else */ } /* while */ if (nochecks < nocells) { return (True); /* a move is found */ } else { return (False); } } /* select_cell */
void CMaiden::Pain (IBaseEntity *Other, sint32 Damage) { if (Entity->Health < (Entity->MaxHealth / 2)) #if XATRIX_FEATURES { if (Entity->State.GetSkinNum() >= 2) Entity->State.GetSkinNum() = 2; else #endif Entity->State.GetSkinNum() = 1; #if XATRIX_FEATURES } #endif if (Level.Frame < PainDebounceTime) return; PainDebounceTime = Level.Frame + 30; Entity->PlaySound (CHAN_VOICE, Sounds[SOUND_PAIN1+irandom(3)]); if (CvarList[CV_SKILL].Integer() == 3) return; // no pain anims in nightmare #if ROGUE_FEATURES // PMM - clear this from blindfire AIFlags &= ~AI_MANUAL_STEERING; // PMM - clear duck flag if (AIFlags & AI_DUCKED) UnDuck(); #endif CurrentMove = (Damage <= 10) ? &ChickMovePain1 : ((Damage <= 25) ? &ChickMovePain2 : &ChickMovePain3); }
void CMaiden::Die (IBaseEntity *Inflictor, IBaseEntity *Attacker, sint32 Damage, vec3f &Point) { sint32 n; // check for gib if (Entity->Health <= Entity->GibHealth) { Entity->PlaySound (CHAN_VOICE, SoundIndex ("misc/udeath.wav")); for (n= 0; n < 2; n++) CGibEntity::Spawn (Entity, GameMedia.Gib_Bone[0], Damage, GIB_ORGANIC); for (n= 0; n < 4; n++) CGibEntity::Spawn (Entity, GameMedia.Gib_SmallMeat, Damage, GIB_ORGANIC); Entity->ThrowHead (GameMedia.Gib_Head[1], Damage, GIB_ORGANIC); Entity->IsDead = true; return; } if (Entity->IsDead == true) return; // regular death Entity->IsDead = true; Entity->CanTakeDamage = true; n = irandom(2); CurrentMove = (!n) ? &ChickMoveDeath1 : &ChickMoveDeath2; Entity->PlaySound (CHAN_VOICE, (!n) ? Sounds[SOUND_DEATH1] : Sounds[SOUND_DEATH2]); }
Nebula::Nebula() : SpaceObject(5000, "Nebula") { setCollisionRadius(1); //Nebula need a big radius to render properly from a distance. But they do not really need collision. So set the collision radius to a tiny range. setRotation(random(0, 360)); radar_visual = irandom(1, 3); registerMemberReplication(&radar_visual); for(int n=0; n<cloud_count; n++) { clouds[n].size = random(1024, 1024 * 4); clouds[n].texture = irandom(1, 3); clouds[n].offset = sf::vector2FromAngle(float(n * 360 / cloud_count)) * random(clouds[n].size / 2.0f, getRadius() - clouds[n].size); } nebula_list.push_back(this); }
// Returns a random team member of ent CItemEntity *CItemEntity::GetRandomTeamMember (CItemEntity *Master) { static std::vector<IBaseEntity*> Team; Team.clear (); for (IBaseEntity *Member = Master; Member; Member = Member->Team.Chain) Team.push_back (Member); return entity_cast<CItemEntity>(Team[irandom(Team.size())]); }
int64_t test_montecarlo_one_packet_loop(void){ rpacket_t rp; storage_model_t sm; init_rpacket(&rp); init_storage_model(&sm); rk_state mt_state; irandom(&mt_state); int64_t res= montecarlo_one_packet_loop(&sm, &rp, 1, &mt_state); dealloc_storage_model(&sm); return res; }
bool test_montecarlo_thomson_scatter(void){ rpacket_t rp; storage_model_t sm; init_rpacket(&rp); init_storage_model(&sm); rk_state mt_state; irandom(&mt_state); double DISTANCE = 1e13; montecarlo_thomson_scatter(&rp, &sm, DISTANCE, &mt_state); dealloc_storage_model(&sm); return true; }
int64_t test_montecarlo_free_free_scatter(void){ rpacket_t rp; storage_model_t sm; init_rpacket(&rp); init_storage_model(&sm); rk_state mt_state; irandom(&mt_state); double DISTANCE = 1e13; montecarlo_free_free_scatter(&rp, &sm, DISTANCE,&mt_state); dealloc_storage_model(&sm); return rpacket_get_status(&rp); }
Artifact::Artifact() : SpaceObject(120, "Artifact") { registerMemberReplication(&model_data_name); setRotation(random(0, 360)); current_model_data_name = "artifact" + string(irandom(1, 8)); model_data_name = current_model_data_name; model_info.setData(current_model_data_name); allow_pickup = false; }
bool test_move_packet_across_shell_boundary(void){ rpacket_t rp; storage_model_t sm; init_rpacket(&rp); init_storage_model(&sm); rk_state mt_state; irandom(&mt_state); double DISTANCE = 0.95e13; // MR: wrong: move_packet_across_shell_boundary() returns void move_packet_across_shell_boundary(&rp, &sm, DISTANCE, &mt_state); dealloc_storage_model(&sm); return true; }
// // this is the smarts for the rocket launcher in coop // // if there is a player behind/below the carrier, and we can shoot, and we can trace a LOS to them .. // pick one of the group, and let it rip void CCarrier::CoopCheck () { // no more than 4 players in coop, so.. static std::vector<CPlayerEntity*> targets; targets.clear(); // if we're not in coop, this is a noop if (!(Game.GameMode & GAME_COOPERATIVE)) return; // if we are, and we have recently fired, bail if (RefireWait > Level.Frame) return; // cycle through players for (int player = 1; player <= Game.MaxClients; player++) { CPlayerEntity *ent = entity_cast<CPlayerEntity>(Game.Entities[player].Entity); if (!ent->GetInUse()) continue; if (IsInBack(Entity, ent) || IsBelow(Entity, ent)) { CTrace tr (Entity->State.GetOrigin(), ent->State.GetOrigin(), Entity, CONTENTS_MASK_SOLID); if (tr.Fraction == 1.0) targets.push_back (ent); } } if (targets.empty()) return; int target = irandom(targets.size()); // make sure to prevent rapid fire rockets RefireWait = Level.Frame + CARRIER_ROCKET_TIME; // save off the real enemy IBaseEntity *OldEnemy = *Entity->Enemy; // set the new guy as temporary enemy Entity->Enemy = targets[target]; Rocket (); // put the real enemy back Entity->Enemy = OldEnemy; // we're done return; }
RepairCrew::RepairCrew() : MultiplayerObject("RepairCrew") { ship_id = -1; position.x = -1; action = RC_Idle; direction = ERepairCrewDirection(irandom(RC_Up, RC_Right + 1)); selected = false; registerMemberReplication(&ship_id); registerMemberReplication(&position, 1.0); registerMemberReplication(&target_position); repairCrewList.push_back(this); }
string GameGlobalInfo::getNextShipCallsign() { callsign_counter += 1; switch(irandom(0, 9)) { case 0: return "S" + string(callsign_counter); case 1: return "NC" + string(callsign_counter); case 2: return "CV" + string(callsign_counter); case 3: return "SS" + string(callsign_counter); case 4: return "VS" + string(callsign_counter); case 5: return "BR" + string(callsign_counter); case 6: return "CSS" + string(callsign_counter); case 7: return "UTI" + string(callsign_counter); case 8: return "VK" + string(callsign_counter); case 9: return "CCN" + string(callsign_counter); } return "SS" + string(callsign_counter); }
GameGlobalInfo::GameGlobalInfo() : MultiplayerObject("GameGlobalInfo") { assert(!gameGlobalInfo); callsign_counter = 0; victory_faction = -1; gameGlobalInfo = this; for(int n=0; n<max_player_ships; n++) { playerShipId[n] = -1; registerMemberReplication(&playerShipId[n]); } for(int n=0; n<max_nebulas; n++) { nebula_info[n].vector = sf::Vector3f(random(-1, 1), random(-1, 1), random(-1, 1)); nebula_info[n].textureName = "Nebula" + string(irandom(1, 3)); registerMemberReplication(&nebula_info[n].vector); registerMemberReplication(&nebula_info[n].textureName); } global_message_timeout = 0.0; player_warp_jump_drive_setting = PWJ_ShipDefault; long_range_radar_range = 30000; use_beam_shield_frequencies = true; use_system_damage = true; allow_main_screen_tactical_radar = true; allow_main_screen_long_range_radar = true; registerMemberReplication(&global_message); registerMemberReplication(&global_message_timeout, 1.0); registerMemberReplication(&victory_faction); registerMemberReplication(&long_range_radar_range); registerMemberReplication(&use_beam_shield_frequencies); registerMemberReplication(&use_system_damage); registerMemberReplication(&allow_main_screen_tactical_radar); registerMemberReplication(&allow_main_screen_long_range_radar); for(unsigned int n=0; n<factionInfo.size(); n++) reputation_points.push_back(0); registerMemberReplication(&reputation_points, 1.0); }
void GuiScanningDialog::setupParameters() { if (!my_spaceship) return; for(int n=0; n<max_sliders; n++) { if (n < my_spaceship->scanning_complexity) sliders[n]->show(); else sliders[n]->hide(); } box->setSize(500, 265 + 70 * my_spaceship->scanning_complexity); for(int n=0; n<max_sliders; n++) { target[n] = random(0.0, 1.0); sliders[n]->setValue(random(0.0, 1.0)); while(fabsf(target[n] - sliders[n]->getValue()) < 0.2) sliders[n]->setValue(random(0.0, 1.0)); } updateSignal(); string label = "[" + string(scan_depth + 1) + "/" + string(my_spaceship->scanning_depth) + "] "; switch(irandom(0, 10)) { default: case 0: label += "Electric signature"; break; case 1: label += "Biomass frequency"; break; case 2: label += "Gravity well signature"; break; case 3: label += "Radiation halftime"; break; case 4: label += "Radio profile"; break; case 5: label += "Ionic phase shift"; break; case 6: label += "Infra-red color shift"; break; case 7: label += "Doppler stability"; break; case 8: label += "Raspberry jam prevention"; break; case 9: label += "Infinity impropability"; break; case 10: label += "Zerospace audio frequency"; break; } signal_label->setText(label); }
cObject Population_Container::selectRandom() { unordered_map<string, cObject>::iterator it; int total=0; for (it=contents.begin();it!=contents.end();++it) { total+=it->second.count; } int ridx = irandom(total); it=contents.begin(); while (ridx>=0) { ridx -= it->second.count; if (ridx>=0) ++it; } return it->second; }
/* return -1 if not found */ int find_to_part(int noparts, int cell_no, int from, cells_t cells[], parts_t parts[]) { int to = irandom(0, noparts - 1); int nochecks = 0; int selected = False; while ((! selected) && (nochecks < noparts)) { nochecks++; if ((to == from) || (! feasible_move(cell_no, from, to, cells, parts))) { to = (to + 1) % noparts; } else { selected = True; } } /* while */ if (selected) { return (to); } else { return (-1); } } /* find_to_part */
void RepairCrew::update(float delta) { P<PlayerSpaceship> ship; if (game_server) ship = game_server->getObjectById(ship_id); else if (game_client) ship = game_client->getObjectById(ship_id); else { destroy(); return; } if (game_server && !ship) { destroy(); return; } if (!ship || !ship->ship_template) return; if (position.x < -0.5) { ship->ship_template->interiorSize(); int n=irandom(0, ship->ship_template->rooms.size() - 1); position = sf::Vector2f(ship->ship_template->rooms[n].position + sf::Vector2i(irandom(0, ship->ship_template->rooms[n].size.x - 1), irandom(0, ship->ship_template->rooms[n].size.y - 1))); target_position = sf::Vector2i(position); } action_delay -= delta; sf::Vector2i pos = sf::Vector2i(position + sf::Vector2f(0.5, 0.5)); switch(action) { case RC_Idle: { action_delay = 1.0 / move_speed; if (pos != target_position) { ERepairCrewDirection new_direction = pathFind(pos, target_position, ship->ship_template); if (new_direction != RC_None) { action = RC_Move; direction = new_direction; } } position = sf::Vector2f(pos); ESystem system = ship->ship_template->getSystemAtRoom(pos); if (system != SYS_None) { ship->systems[system].health += repair_per_second * delta; if (ship->systems[system].health > 1.0) ship->systems[system].health = 1.0; } if (ship->auto_repair_enabled && pos == target_position && (system == SYS_None || !ship->hasSystem(system) || ship->systems[system].health == 1.0)) { int n=irandom(0, SYS_COUNT - 1); if (ship->hasSystem(ESystem(n)) && ship->systems[n].health < 1.0) { for(unsigned int idx=0; idx<ship->ship_template->rooms.size(); idx++) { if (ship->ship_template->rooms[idx].system == ESystem(n)) { target_position = ship->ship_template->rooms[idx].position + sf::Vector2i(irandom(0, ship->ship_template->rooms[idx].size.x - 1), irandom(0, ship->ship_template->rooms[idx].size.y - 1)); } } } } } break; case RC_Move: switch(direction) { case RC_None: break; case RC_Left: position.x -= delta * move_speed; break; case RC_Right: position.x += delta * move_speed; break; case RC_Up: position.y -= delta * move_speed; break; case RC_Down: position.y += delta * move_speed; break; } if (action_delay < 0.0) action = RC_Idle; break; } }
void FX_EnergyGibs(vec3_t origin ) { localEntity_t *le; refEntity_t *re; vec3_t dir; int i, j, k; int chunkModel=0; float baseScale = 0.7f, dist; int numChunks; numChunks = irandom( 10, 15 ); VectorSubtract(cg.snap->ps.origin, origin, dir); dist = VectorLength(dir); if (dist > 512) { numChunks *= 512.0/dist; // 1/2 at 1024, 1/4 at 2048, etc. } for ( i = 0; i < numChunks; i++ ) { chunkModel = cgs.media.chunkModels[MT_METAL][irandom(0,5)]; le = CG_AllocLocalEntity(); re = &le->refEntity; le->leType = LE_FRAGMENT; le->endTime = cg.time + 2000; VectorCopy( origin, re->origin ); for ( j = 0; j < 3; j++ ) { re->origin[j] += crandom() * 12; } VectorCopy( re->origin, le->pos.trBase ); //Velocity VectorSet( dir, crandom(), crandom(), crandom() ); VectorScale( dir, flrandom( 300, 500 ), le->pos.trDelta ); //Angular Velocity VectorSet( le->angles.trBase, crandom() * 360, crandom() * 360, crandom() * 360 ); VectorSet( le->angles.trDelta, crandom() * 90, crandom() * 90, crandom() * 90 ); AxisCopy( axisDefault, re->axis ); le->data.fragment.radius = flrandom(baseScale * 0.4f, baseScale * 0.8f ); re->nonNormalizedAxes = qtrue; re->hModel = chunkModel; re->renderfx |= RF_CAP_FRAMES; re->customShader = cgs.media.quantumDisruptorShader; re->shaderTime = cg.time/1000.0f; le->pos.trType = TR_GRAVITY; le->pos.trTime = cg.time; le->angles.trType = TR_INTERPOLATE; le->angles.trTime = cg.time; le->bounceFactor = 0.2f + random() * 0.2f; le->leFlags |= LEF_TUMBLE; re->shaderRGBA[0] = re->shaderRGBA[1] = re->shaderRGBA[2] = re->shaderRGBA[3] = 255; // Make sure that we have the desired start size set for( k = 0; k < 3; k++) { VectorScale(le->refEntity.axis[k], le->data.fragment.radius, le->refEntity.axis[k]); } } }
/*** Get a random integer from the range of integers defined by and including i and j. @function irandom @param i Number, lower limit. @param j Number, upper limit. @return A random integer from the range of integers defined by and including i and j. */ static int Qmath_Irandom(lua_State * L) { lua_pushnumber(L, irandom(luaL_checkint(L, 1), luaL_checkint(L, 2))); return 1; }
void CMaiden::Slash () { vec3f aim (MELEE_DISTANCE, Entity->GetMins().X, 10); Entity->PlaySound (CHAN_WEAPON, Sounds[SOUND_MELEE_SWING]); CMeleeWeapon::Fire (Entity, aim, (10 + (irandom(6))), 100); }
/* create initial partition */ int create_partition(int nocells, int noparts, int totcellsize, int max_cweight, float *off_ratio, cells_t cells[], nets_t nets[], corn_t cnets[], ind_t *ind) { /* init current size */ for (int i = 0; i < noparts; i++) { ind->parts[i].pratio = 1.0 / noparts; ind->parts[i].pcurr_size = 0; ind->parts[i].pmax_cells = 0; } /* for i */ /* allocate temporary memory */ int *tparts = (int *) calloc(noparts, sizeof(int)); if (tparts == NULL) { printf("Error: Unable to allocate memory for tparts.\n"); exit(1); } /* if */ /* insert cells */ for (int i = 0; i < nocells; i++) { /* find minimum */ int min_inx = 0; int min_size = ind->parts[0].pcurr_size; for (int j = 1; j < noparts; j++) { if (min_size > ind->parts[j].pcurr_size) { min_inx = j; min_size = ind->parts[j].pcurr_size; } /* if */ } /* for j */ /* find a new minimum among the same minimums */ int tcount = -1; /* tparts is used to randomize partitioning */ for (int j = 0; j < noparts; j++) { if (ind->parts[j].pcurr_size == min_size) { tcount++; tparts[tcount] = j; } /* if */ } /* for j */ min_inx = tparts[irandom(0, tcount)]; /* assign cell i to part[min_inx] */ ind->chrom[i] = min_inx; ind->parts[min_inx].pcurr_size += cells[i].cweight; ind->parts[min_inx].pmax_cells++; /* find net info */ int cnets_inx = cells[i].netlist; for (int j = 0; j < cells[i].cno_nets; j++) { int net_no = cnets[cnets_inx + j].corn_no; nets[net_no].npartdeg[min_inx]++; } /* for j */ } /* for i */ free(tparts); /* determine min & max part sizes */ /* also adjust the min & max part sizes */ int part_fit = True; int max_size = -1; while (((*off_ratio) < 1.05) && (part_fit)) { for (int i = 0; i < noparts; i++) { float part_size = ((float) totcellsize) * ind->parts[i].pratio; if (part_size < max_cweight) { printf("\nError: Too small part size.\n"); exit(1); } /* if */ ind->parts[i].pmax_size = (int) (part_size * (1.0 + (*off_ratio)) + 1.0); ind->parts[i].pmin_size = (int) (part_size * (1.0 - (*off_ratio)) - 1.0); if (ind->parts[i].pmax_size > max_size) { max_size = ind->parts[i].pmax_size; } } /* for i */ int i = 0; while ((i < noparts) && (part_fit)) { if (ind->parts[i].pmax_size < ind->parts[i].pcurr_size) part_fit = False; i++; } /* while */ if (part_fit) { part_fit = False; } else { part_fit = True; (*off_ratio) += 0.05; if ((*off_ratio) > 1.0) { printf("\nError: Cannot adjust part sizes.\n"); exit(1); } /* if */ } /* if not fit */ } /* while */ return max_size; } /* create_partition */
sf::Vector3f Mesh::randomPoint() { int idx = irandom(0, vertexCount-1); return sf::Vector3f(vertices[idx].position[0], vertices[idx].position[1], vertices[idx].position[2]); }