void FireflyEmitter::EmitParticle( Particle& particle ) { float inclination = glm::radians( RandRange( MinInclination, MaxInclination ) ); float azimuth = glm::radians( RandRange( MinAzimuth, MaxAzimuth ) ); float radius = RandRange( MinimumRadius, MaximumRadius ); //float speed = RandRange( MinSpeed, MaxSpeed ); float lifetime = RandRange( MinLifetime, MaxLifetime ); float sInclination = sinf( inclination ); float X = sInclination * cosf( azimuth ); float Y = sInclination * sinf( azimuth ); float Z = cosf( inclination ); glm::vec3 vector( X, Y, Z ); // particle.m_Position = ( vector * radius ) + Origin; particle.m_Position = (vector * radius ) + Position; particle.m_Velocity = glm::vec3(0, 0, 0); // particle.m_Velocity = RandFireflyUnitVec() * speed; particle.m_fLifeTime = lifetime; particle.m_fAge = 0; particle.m_fRotate = (RandRange(40,180)); }
/*ParticleWander execute The following code causes the ParticleGroup to steer. Thanks to programming source AI by mat buckland. It basically locates the next position using the current velocity, and from there, randomizes to a location. This creates a smoooth steering, rather then a constant chaos of particles */ void ParticleWander::execute(ParticleGroup * ParticleGroup) { // :^: This value Expands the radius of roaming // :^: These values controls the fluidity of changing direction ParticleGroup->velocityX =ParticleGroup->velocityX * 0.99f + RandRange(-.25f, .25f); ParticleGroup->velocityY =ParticleGroup->velocityY * 0.99f + RandRange(-.25f, .25f); }
Water::Water(int setsize) { /* Entity * ent = new Entity; ENTLIST->AddEntity(ent); //GraphicsComponent * gcp = (new Water(15)); ent->AddComponent(this); // NonTexInstances[ent->ID] = this;*/ masked = 0; speed = 0; size = setsize; angle = 0; coordincr = 900/(float)size; angleYincr = 1.0f*(360.0f/(float)size)*3.14159265359f/180.0f; velocityX = 0; velocityY = 0; scalePerlin = 3.0f; perlin = new PerlinNoise(size, scalePerlin); for (int i = 0; i < size; ++i) { for (int j = 0; j< size; ++j) { for (int k = 0; k < 4; ++k) { color[i][j][k].a = RandRange(0.95f, 1.0f); if (j == 0) { if (k == 0 || k==3) { color[i][j][k].a = 0; } } else if (j==(size-1)) { if (k==2 || k == 1) { color[i][j][k].a = 0; } } color[i][j][k].b = RandRange(0.4f, 0.5f); color[i][j][k].g = RandRange(0.3f, 0.4f); color[i][j][k].r = RandRange(0.0f, 0.1f); } } } }
double RandRangeBias(double mmin, double mmax, double biasRatio, double randomAmount) { double span = mmax - mmin; double lower_rat = biasRatio * (1.0 - randomAmount); double upper_rat = lower_rat + randomAmount; return RandRange(mmin + span * lower_rat,mmin + span * upper_rat); }
void glColor4fWrap(color4 &temp) { float scale = 1.0f; glColor4f(temp.r, temp.g, temp.b, temp.a); // temp.r += sf::Randomizer::Random(-0.05f, 0.05f); if (temp.g >= 0.3f) temp.g += RandRange(0.0f, -0.050f)*scale; else temp.g +=RandRange(-0.05f, 0.05f)*scale; if (temp.r >= 0.05f) temp.r += RandRange(0.0f, -0.02f)*scale; else temp.r += RandRange(-0.02f, 0.02f)*scale; }
void FlashEmitter::EmitParticle( Particle& particle ) { float inclination = glm::radians( RandRange( MinInclination, MaxInclination ) ); float azimuth = glm::radians( RandRange( MinAzimuth, MaxAzimuth ) ); float radius = RandRange( MinimumRadius, MaximumRadius ); float speed = RandRange( MinSpeed, MaxSpeed ); float lifetime = RandRange( MinLifetime, MaxLifetime ); float sInclination = sinf( inclination ); float X = sInclination * cosf( azimuth ); float Y = sInclination * sinf( azimuth ); float Z = cosf( inclination ); glm::vec3 vector( X, Y, Z ); particle.m_Position = ( vector * radius ) + Origin; particle.m_Velocity = RandFlashUnitVec() * speed; particle.m_fLifeTime = lifetime; particle.m_fAge = 0; float f = RandRange(1.0f, 2.0f); if (f > 1.5f) particle.m_ClockRot = 1; else particle.m_ClockRot = -1; }
void Particle_SphereSpread(ParticleSystem* psystem, float maxRadius, Vec3 emitterPos) { u16 n = psystem->n_particles; for (u16 i = 0; i < n; i++) { float altitude = RandRange(0, M_PI); float azimuth = RandRange(0, 2*M_PI); float radius = RandRange(0.1f, maxRadius); float sinAlt = sin(altitude); float x = sinAlt * cos(azimuth); float y = sinAlt * sin(azimuth); float z = cos(altitude); Vec3 pointOnSphere(x, y, z); Vec3 pos = pointOnSphere*radius + emitterPos; f32 speed = RandRange(3, 6); Vec3 vel = pointOnSphere * speed; psystem->positions[i] = pos; psystem->velocities[i] = vel; } }
void CIcqProto::InitMessageCookie(cookie_message_data *pCookie) { DWORD dwMsgID1; DWORD dwMsgID2; do { // ensure that message ids are unique dwMsgID1 = time(NULL); dwMsgID2 = RandRange(0, 0x0FFFF); } while (FindMessageCookie(dwMsgID1, dwMsgID2, NULL, NULL, NULL)); if (pCookie) { pCookie->dwMsgID1 = dwMsgID1; pCookie->dwMsgID2 = dwMsgID2; } }
void FireflyEmitter::Update(float fDeltaTime) { Age += fDeltaTime; if (Age >= ForceTime) { if (Collided) CollisionTime++; if (CollisionTime == 1) Collided = false; Age = 0; if (!Collided) { Force = RandomNewForce(); Velocity.x /= 4; Velocity.y /= 4; Velocity.z /= 4; CollisionTime = 0; Collided = false; } } float Pos = sqrt(pow(Position.x, 2) + pow(Position.y, 2) + pow(Position.z, 2)); if (Pos > SphereRadius) { Collided = true; Velocity = -Position * RandRange(50, 75); // Force = -Position * RandRange(2000, 3000); } Velocity += Force * fDeltaTime; Position += Velocity * fDeltaTime; // Position = glm::vec3(0, 0, 0); }
static void NewYearScreen(void) { /* Update year. */ year++; /* Update weather. */ weather = RandRange(ArraySize(weatherList)); /* Reset screen. */ clear(); move(0, 0); /* Display the year. */ printw("YEAR %d\n\n", year); /* Display the weather. */ printw("%s\n", weatherList[weather - 1]); /* Refresh screen. */ refresh(); /* Delay. */ sleep(DELAY_TIME); }
void PopulationScreen(Player *aPlayer) { char input[80]; Country *country; int population; int populationGain; int born; int immigrated; int merchantsImmigrated; int noblesImmigrated; int diedDisease; int diedMalnutrition; int diedStarvation; int armyDiedStarvation; int armyDeserted; /* Get the player country. */ country = aPlayer->country; /* Reset screen. */ clear(); move(0, 0); /* Display the ruler and country. */ printw("%s %s OF %s:\n", aPlayer->title, aPlayer->name, country->name); /* Display the year. */ printw("IN YEAR %d,\n\n", year); /* Determine the total population. */ population = aPlayer->serfCount + aPlayer->merchantCount + aPlayer->nobleCount; /* Determine the number of babies born. */ born = RandRange(((int) (((float) population) / 9.5))); /* Determine the number of people who died from disease. */ diedDisease = RandRange(population / 22); /* Determine the number of people who died of starvation and */ /* malnutrition. */ diedStarvation = 0; diedMalnutrition = 0; if (aPlayer->peopleGrainNeed > (2 * aPlayer->peopleGrainFeed)) { diedMalnutrition = RandRange(population/12 + 1); diedStarvation = RandRange(population/16 + 1); } else if (aPlayer->peopleGrainNeed > aPlayer->peopleGrainFeed) { diedMalnutrition = RandRange(population/15 + 1); } aPlayer->diedStarvation = diedStarvation; /* Determine the number of people who immigrated. */ if (((float) aPlayer->peopleGrainFeed) > (1.5 * ((float) aPlayer->peopleGrainNeed))) { immigrated = ((int) sqrt(aPlayer->peopleGrainFeed - aPlayer->peopleGrainNeed)) - RandRange((int) (1.5 * ((float) aPlayer->customsTax))); if (immigrated > 0) immigrated = RandRange(((2 * immigrated) + 1)); else immigrated = 0; } else { immigrated = 0; } aPlayer->immigrated = immigrated; /* Determine the number of merchants and nobles who immigrated. */ merchantsImmigrated = 0; noblesImmigrated = 0; if ((immigrated / 5) > 0) merchantsImmigrated = RandRange(immigrated / 5); if ((immigrated / 25) > 0) noblesImmigrated = RandRange(immigrated / 25); /* Determine the number of soldiers who died of starvation or deserted. */ armyDiedStarvation = 0; armyDeserted = 0; if (aPlayer->armyGrainNeed > (2 * aPlayer->armyGrainFeed)) { armyDiedStarvation = RandRange(aPlayer->soldierCount/2 + 1); aPlayer->soldierCount -= armyDiedStarvation; armyDeserted = RandRange(aPlayer->soldierCount / 5); aPlayer->soldierCount -= armyDeserted; } /* Determine the army's efficiency. */ aPlayer->armyEfficiency = (10 * aPlayer->armyGrainFeed) / aPlayer->armyGrainNeed; if (aPlayer->armyEfficiency < 5) aPlayer->armyEfficiency = 5; else if (aPlayer->armyEfficiency > 15) aPlayer->armyEfficiency = 15; /* Display the number of babies born. */ printw(" %d BABIES WERE BORN\n", born); /* Display the number of people who died of disease. */ printw(" %d PEOPLE DIED OF DISEASE\n", diedDisease); /* Display the number of people who immigrated. */ if (immigrated > 0) printw(" %d PEOPLE IMMIGRATED INTO YOUR COUNTRY.\n", immigrated); /* Display the number of people who died of starvation and malnutrition. */ if (diedMalnutrition > 0) printw(" %d PEOPLE DIED OF MALNUTRITION.\n", diedMalnutrition); if (diedStarvation > 0) printw(" %d PEOPLE STARVED TO DEATH.\n", diedStarvation); /* Display the number of soldiers who starved to death. */ if (armyDiedStarvation > 0) printw(" %d SOLDIERS STARVED TO DEATH.\n", armyDiedStarvation); /* Display the army efficiency. */ printw("YOUR ARMY WILL FIGHT AT %d%% EFFICIENCY.\n", 10 * aPlayer->armyEfficiency); /* Display the population gain or loss. */ populationGain = born + immigrated - diedDisease - diedMalnutrition - diedStarvation; if (populationGain >= 0) printw("YOUR POPULATION GAINED %d CITIZENS.\n", populationGain); else printw("YOUR POPULATION LOST %d CITIZENS.\n", -populationGain); /* Update population. */ aPlayer->serfCount += populationGain - merchantsImmigrated - noblesImmigrated; aPlayer->merchantCount += merchantsImmigrated; aPlayer->nobleCount += noblesImmigrated; /* Wait for player to be done. */ printw("\n\n<ENTER>? "); getnstr(input, 80); /* Check if player died. */ PlayerDeath(aPlayer); }
static void PlayerDeath(Player *aPlayer) { Country *country; /* Get the player country. */ country = aPlayer->country; /* If anyone starved to death, their mother might assassinate the ruler. */ if ((aPlayer->diedStarvation > 0) && (RandRange(aPlayer->diedStarvation) > RandRange(110))) { aPlayer->dead = TRUE; clear(); move(0, 0); printw("VERY SAD NEWS ...\n\n"); printw("%s %s OF %s HAS BEEN ASSASSINATED\n", aPlayer->title, aPlayer->name, country->name); printw("BY A CRAZED MOTHER WHOSE CHILD HAD STARVED TO DEATH. . .\n\n"); } /* Check if the player died for any other reason. */ if (RandRange(100) == 1) { aPlayer->dead = TRUE; clear(); move(0, 0); printw("VERY SAD NEWS ...\n\n"); printw("%s %s ", aPlayer->title, aPlayer->name); switch(RandRange(4)) { case 1 : printw("HAS BEEN ASSASSINATED BY AN AMBITIOUS\nNOBLE\n\n"); break; case 2 : printw("HAS BEEN KILLED FROM A FALL DURING\n" "THE ANNUAL FOX-HUNT.\n\n"); break; case 3 : printw("DIED OF ACUTE FOOD POISONING.\n" "THE ROYAL COOK WAS SUMMARILY EXECUTED.\n\n"); break; case 4 : default : printw("PASSED AWAY THIS WINTER FROM A WEAK HEART.\n\n"); break; } } /* If the player died, display the funeral. */ if (aPlayer->dead) { printw("THE OTHER NATION-STATES HAVE SENT REPRESENTATIVES TO THE\n"); printw("FUNERAL\n"); refresh(); sleep(2 * DELAY_TIME); } }
static void UpdateCPUPlayerHoldings(Player *aPlayer) { Player *humanPlayer; int cpuSerfCount = 0; int cpuGrainForSale = 0; float cpuGrainPrice = 0.0; int cpuTreasury = 0; int cpuMerchantCount = 0; int cpuMarketplaceCount = 0; int cpuGrainMillCount = 0; int cpuFoundryCount = 0; int cpuShipyardCount = 0; int cpuPalaceCount = 0; int cpuNobleCount = 0; int cpuArmyEfficiency = 0; int livingHumanPlayerCount = 0; int i; /* * Determine the average human player holdings. If there are no human * players, treat the first living player as a human player. */ for (i = 0; (i < playerCount) || (livingHumanPlayerCount == 0); i++) { /* Get the player record. */ humanPlayer = &(playerList[i]); /* Skip dead players. */ if (humanPlayer->dead) continue; /* Increment total human player holdings. */ livingHumanPlayerCount++; cpuSerfCount += humanPlayer->serfCount; cpuGrainForSale += humanPlayer->grainForSale; cpuGrainPrice += humanPlayer->grainPrice; cpuTreasury += humanPlayer->treasury; cpuMerchantCount += humanPlayer->merchantCount; cpuMarketplaceCount += humanPlayer->marketplaceCount; cpuGrainMillCount += humanPlayer->grainMillCount; cpuFoundryCount += humanPlayer->foundryCount; cpuShipyardCount += humanPlayer->shipyardCount; cpuPalaceCount += humanPlayer->palaceCount; cpuNobleCount += humanPlayer->nobleCount; cpuArmyEfficiency += humanPlayer->armyEfficiency; } cpuSerfCount /= livingHumanPlayerCount; cpuGrainForSale /= livingHumanPlayerCount; cpuGrainPrice /= livingHumanPlayerCount; cpuTreasury /= livingHumanPlayerCount; cpuMerchantCount /= livingHumanPlayerCount; cpuMarketplaceCount /= livingHumanPlayerCount; cpuGrainMillCount /= livingHumanPlayerCount; cpuFoundryCount /= livingHumanPlayerCount; cpuShipyardCount /= livingHumanPlayerCount; cpuPalaceCount /= livingHumanPlayerCount; cpuNobleCount /= livingHumanPlayerCount; cpuArmyEfficiency /= livingHumanPlayerCount; /* Update serf count. */ cpuSerfCount += RandRange(200) - RandRange(200); aPlayer->serfCount = cpuSerfCount; /* Update grain for sale. Charge more in bad weather. */ cpuGrainForSale += RandRange(1000) - RandRange(1000); while (1) { cpuGrainPrice += RandRange(100)/100.0 - RandRange(100)/100.0; if (cpuGrainPrice < 0.0) cpuGrainPrice = 0.0; else break; } if ((cpuGrainForSale > aPlayer->grainForSale) && (RandRange(9) > 6)) { aPlayer->grainForSale = cpuGrainForSale; aPlayer->grainPrice = cpuGrainPrice; if (weather < 3) aPlayer->grainPrice += RandRange(100) / 150.0; } /* Update treasury. */ cpuTreasury += RandRange(1500) - RandRange(1500); aPlayer->treasury = cpuTreasury; /* Update merchant count. */ cpuMerchantCount += RandRange(25) - RandRange(25); aPlayer->merchantCount = MAX(aPlayer->merchantCount, cpuMerchantCount); /* Update marketplace count. */ cpuMarketplaceCount += RandRange(4) - RandRange(4); aPlayer->marketplaceCount = MAX(aPlayer->marketplaceCount, cpuMarketplaceCount); /* Update grain mill count. */ cpuGrainMillCount += RandRange(2) - RandRange(2); aPlayer->grainMillCount = MAX(aPlayer->grainMillCount, cpuGrainMillCount); /* Update foundry count. */ if (RandRange(100) > 30) cpuFoundryCount += RandRange(2) - RandRange(2); aPlayer->foundryCount = MAX(aPlayer->foundryCount, cpuFoundryCount); /* Update shipyard count. */ if (RandRange(100) > 30) cpuShipyardCount += RandRange(2) - RandRange(2); aPlayer->shipyardCount = MAX(aPlayer->shipyardCount, cpuShipyardCount); /* Update palace count. */ if ((RandRange(100) > 30) && (RandRange(100) > 50)) cpuPalaceCount += RandRange(2) - RandRange(2); aPlayer->palaceCount = MAX(aPlayer->palaceCount, cpuPalaceCount); /* Update noble count. */ if ((RandRange(100) > 30) && (RandRange(100) > 50)) cpuNobleCount += RandRange(2) - RandRange(2); aPlayer->nobleCount = MAX(aPlayer->nobleCount, cpuNobleCount); /* Update army efficiency. */ aPlayer->armyEfficiency = cpuArmyEfficiency; /* Update soldier count. */ aPlayer->soldierCount = (10 * aPlayer->nobleCount) + RandRange(10 * aPlayer->nobleCount); if (aPlayer->serfCount > 0) { while (( ((float) aPlayer->soldierCount) / ((float) aPlayer->serfCount)) > ((0.01 * ((float) aPlayer->foundryCount)) + 0.05)) { aPlayer->soldierCount /= 2; } } else { aPlayer->soldierCount = 0; } }
static void GameSetupScreen(void) { Country *country; Player *player; char input[80]; int i, j; /* Reset screen. */ clear(); move(0, 0); /* Get the number of players. */ do { printw("HOW MANY PEOPLE ARE PLAYING? "); refresh(); getnstr(input, sizeof(input)); playerCount = strtol(input, NULL, 0); } while (playerCount > COUNTRY_COUNT); /* Get the player names. */ for (i = 0; i < playerCount; i++) { /* Get the country and player records. */ country = &(countryList[i]); player = &(playerList[i]); /* Player is human. */ player->human = TRUE; /* Get the country's ruler's name. */ printw("WHO IS THE RULER OF %s? ", country->name); getnstr(player->name, sizeof(player->name)); for (j = 0; j < strlen(player->name); j++) { player->name[j] = toupper(player->name[j]); } } for (; i < COUNTRY_COUNT; i++) { /* Get the country and player records. */ country = &(countryList[i]); player = &(playerList[i]); /* Player is not human. */ player->human = FALSE; /* Get the country's ruler's name. */ snprintf(player->name, sizeof(player->name), "%s", country->rulerName); } /* Initialize the player records. */ for (i = 0; i < COUNTRY_COUNT; i++) { /* Get the country and player records. */ country = &(countryList[i]); player = &(playerList[i]); /* Initialize the player's number. */ player->number = i + 1; /* Initialize the player's country. */ player->country = country; /* Initialize the player's level and title. */ player->level = 0; snprintf(player->title, sizeof(player->title), "%s", country->titleList[player->level]); /* Initialize the player's state. */ player->dead = FALSE; player->land = 10000; player->grain = 15000 + RandRange(10000); player->treasury = 1000; player->serfCount = 2000; player->soldierCount = 20; player->nobleCount = 1; player->merchantCount = 25; player->armyEfficiency = 15; player->customsTax = 20; player->salesTax = 5; player->incomeTax = 35; player->marketplaceCount = 0; player->grainMillCount = 0; player->foundryCount = 0; player->shipyardCount = 0; player->palaceCount = 0; player->grainForSale = 0; player->grainPrice = 0.0; } }
Point3 RandSphere() { float alpha = RandRange(-M_PI, M_PI); float beta = RandRange(-M_PI, M_PI); return AlphaBetaRotation(alpha, beta) * Point3(0.0, 0.0, 1.0); }
void EG_AllLights::initPointLightWall() { // EG_PointLight::EG_PointLight( glm::vec3 Color, float AmbientIntensity, float DiffuseIntensity, // glm::vec3 Position, float Constant, float Linear, float Exp) EG_PointLight pLight; int iterations = 25; float interval = 50/(float)iterations; /// -z side for (int i=0; i<iterations; i++) // for (int i=0; i<6; i++) { // if(i!=3) // continue; glm::vec3 col = ColorList[i%6]; // glm::vec3 pos(-25.0f+i*4, 10.0f, -24.0f); // glm::vec3 pos(-25.0f+i*10 - 0.5, 5.0f, -24.0f); /* float amount = -25.0f+i*10 - 0.5; glm::vec3 pos(amount, 5.0f, -25.0f + amount-2); // float DiffuseInt = RandRange(1.0f, 30.0f); // float DiffuseInt = RandRange(1.0f, 30.0f); float DiffuseInt = 10.0f; pLight = EG_PointLight(col, 0.0f, DiffuseInt, pos, 0.5f, 0.5f, 0.5f); pointLights.push_back(pLight); */ // float amount = -25.0f+i*10 - 0.5; float amount = -25.0f+i*interval - 0.5; glm::vec3 pos(amount, 5.0f, -24.0f); // glm::vec3 pos(amount, 5.0f, -25.0f + amount-2); // float DiffuseInt = 10.0f; // float DiffuseInt = RandRange(1.0f, 30.0f); float DiffuseInt = RandRange(1.0f, 5.0f); pLight = EG_PointLight(col, 0.0f, DiffuseInt, pos, 0.5f, 0.5f, 0.5f); pointLights.push_back(pLight); } /// +z side for (int i=0; i<25; i++) { glm::vec3 col = ColorList[i%6]; float amount = -25.0f+i*2 - 0.5; glm::vec3 pos(amount, 1.0f, 24.0f); // glm::vec3 pos(amount, 5.0f, -25.0f + amount-2); // float DiffuseInt = 10.0f; // float DiffuseInt = RandRange(1.0f, 30.0f); float DiffuseInt = RandRange(1.0f, 5.0f); pLight = EG_PointLight(col, 0.0f, DiffuseInt, pos, 0.5f, 0.5f, 0.5f); pointLights.push_back(pLight); } /// +x Side for (int i=0; i<25; i++) { glm::vec3 col = ColorList[i%6]; // float amount = -25.0f+i*10 - 0.5; // float amount = glm::vec3 pos(24.5f, 5.0f, (-25.0f+i*2 - 0.5)); // glm::vec3 pos(amount, 5.0f, -25.0f + amount-2); // float DiffuseInt = 10.0f; // float DiffuseInt = RandRange(1.0f, 30.0f); float DiffuseInt = RandRange(1.0f, 5.0f); pLight = EG_PointLight(col, 0.0f, DiffuseInt, pos, 0.5f, 0.5f, 0.5f); pointLights.push_back(pLight); } /// -x side for (int i=0; i<25; i++) { glm::vec3 col = ColorList[i%6]; // float amount = -25.0f+i*10 - 0.5; // float amount = glm::vec3 pos(-24.5f, 1.0f, (-25.0f+i*2 - 0.5)); // glm::vec3 pos(amount, 5.0f, -25.0f + amount-2); // float DiffuseInt = 10.0f; // float DiffuseInt = RandRange(1.0f, 30.0f); float DiffuseInt = RandRange(1.0f, 5.0f); pLight = EG_PointLight(col, 0.0f, DiffuseInt, pos, 0.5f, 0.5f, 0.5f); pointLights.push_back(pLight); } }