void CEffects::Fallout2(vec2 Pos) { vec3 FalloutColor(0.0f, 0.4f, 0.0f); CParticle p; p.SetDefault(); p.m_Spr = SPRITE_PART_BALL; p.m_Pos = Pos; p.m_Vel = RandomDir() * ((frandom()+0.1f)*200.0f); p.m_LifeSpan = 5.0f + frandom()*5.0f; p.m_StartSize = 16.0f + frandom()*8; p.m_EndSize = p.m_StartSize; p.m_Rot = frandom()*pi*2; p.m_Rotspeed = (frandom()-0.5f) * pi; p.m_Gravity = 800.0f; p.m_Friction = 0.9f; vec3 c = FalloutColor * (0.75f + frandom()*0.25f); p.m_Color = vec4(c.r, c.g, c.b, 0.75f); m_pClient->m_pParticles->Add(CParticles::GROUP_GENERAL, &p); }
void CEffects::Explosion(vec2 Pos) { // add to flow for(int y = -8; y <= 8; y++) for(int x = -8; x <= 8; x++) { if(x == 0 && y == 0) continue; float a = 1 - (length(vec2(x,y)) / length(vec2(8,8))); m_pClient->m_pFlow->Add(Pos+vec2(x,y)*16, normalize(vec2(x,y))*5000.0f*a, 10.0f); } // add the explosion CParticle p; p.SetDefault(); p.m_Spr = SPRITE_PART_EXPL01; p.m_Pos = Pos; p.m_LifeSpan = 0.4f; p.m_StartSize = 150.0f; p.m_EndSize = 0; p.m_Rot = frandom()*pi*2; m_pClient->m_pParticles->Add(CParticles::GROUP_EXPLOSIONS, &p); // add the smoke for(int i = 0; i < 24; i++) { CParticle p; p.SetDefault(); p.m_Spr = SPRITE_PART_SMOKE; p.m_Pos = Pos; p.m_Vel = RandomDir() * ((1.0f + frandom()*0.2f) * 1000.0f); p.m_LifeSpan = 0.5f + frandom()*0.4f; p.m_StartSize = 32.0f + frandom()*8; p.m_EndSize = 0; p.m_Gravity = frandom()*-800.0f; p.m_Friction = 0.4f; p.m_Color = mix(vec4(0.75f,0.75f,0.75f,1.0f), vec4(0.5f,0.5f,0.5f,1.0f), frandom()); m_pClient->m_pParticles->Add(CParticles::GROUP_GENERAL, &p); } }
void CEffects::WeaponShine(vec2 Pos, vec2 Size) { if(!m_Add100hz && g_Config.m_GfxEyeCandy) return; CParticle p; p.SetDefault(); p.m_Spr = SPRITE_PART_SLICE; p.m_Pos = Pos + vec2((frandom()-0.5f) * Size.x, (frandom()-0.5f) * Size.y); p.m_Vel = vec2(0, 0); p.m_Gravity = -100; p.m_LifeSpan = 7.0f / 10.0f; p.m_Color = vec4(frandom()*0.5f + 0.5f,frandom()*0.5f + 0.5f,frandom()*0.5f + 0.5f,0.5f); p.m_StartSize = 18.0f; p.m_EndSize = 0; p.m_Rot = frandom()*pi*2; p.m_Rotspeed = pi*2; p.m_Friction = 0.9f; p.m_FlowAffected = 0.0f; m_pClient->m_pParticles->Add(CParticles::GROUP_GENERAL, &p); }
void CBlood::Bounce(vec2 Pos, vec2 Dir) { CBlooddrop b; b.SetDefault(); b.m_Pos = Pos; b.m_Spr = SPRITE_BLOOD01; b.m_LifeSpan = 2.0f + frandom()*2.0f; b.m_Rotspeed = 0.0f; b.m_StartSize = (32.0f + frandom()*32) / 1.75f; b.m_EndSize = 16.0f / 1.75f; b.m_Gravity = 1400.0f + frandom()*300; b.m_Vel = Dir * ((frandom()+0.05f)*700.0f); b.m_Rot = GetAngle(b.m_Vel); b.m_Friction = 0.85f+frandom()*0.075f; float c = frandom()*0.3f + 0.7f; b.m_Color = vec4(c, c, c, 1.0f); m_pClient->m_pBlood->Add(GROUP_BLOOD, &b); }
void CEffects::PlayerSpawn(vec2 Pos) { for(int i = 0; i < 32; i++) { CParticle p; p.SetDefault(); p.m_Spr = SPRITE_PART_SHELL; p.m_Pos = Pos; p.m_Vel = RandomDir() * (powf(frandom(), 3)*600.0f); p.m_LifeSpan = 0.3f + frandom()*0.3f; p.m_StartSize = 64.0f + frandom()*32; p.m_EndSize = 0; p.m_Rot = frandom()*pi*2; p.m_Rotspeed = frandom(); p.m_Gravity = frandom()*-400.0f; p.m_Friction = 0.7f; p.m_Color = vec4(0xb5/255.0f, 0x50/255.0f, 0xcb/255.0f, 1.0f); m_pClient->m_pParticles->Add(CParticles::GROUP_GENERAL, &p); } m_pClient->m_pSounds->Play(CSounds::CHN_WORLD, SOUND_PLAYER_SPAWN, 1.0f, Pos); }
void CEffects::BulletTrail(vec2 Pos) { if(!m_Add100hz) return; CParticle p; p.SetDefault(); p.m_Spr = SPRITE_PART_BALL; p.m_Pos = Pos; p.m_LifeSpan = 0.25f + frandom()*0.25f; p.m_StartSize = 8.0f; p.m_EndSize = 0; p.m_Friction = 0.7f; if (g_Config.m_GfxEyeCandy) { p.m_LifeSpan = 0.25f + frandom() * 0.75f; p.m_Friction = 0.7f; p.m_Gravity = -40 + frandom() * 3.0f; p.m_Color = vec4(frandom() * 0.5f + 0.5f, frandom() * 0.5f + 0.5f, frandom() * 0.5f + 0.5f, 1.0f); } m_pClient->m_pParticles->Add(CParticles::GROUP_PROJECTILE_TRAIL, &p); }
int irandom( int range ) { return frandom() * range; }
void CPickup::Tick() { // wait for respawn //if(m_SpawnTick > 0) - 12.5. if(m_SpawnTick > 0 && !m_Dropable && !m_Flashing) { if(Server()->Tick() > m_SpawnTick && !m_SkipAutoRespawn) { // respawn m_SpawnTick = -1; if(m_Type == POWERUP_WEAPON) GameServer()->CreateSound(m_Pos, SOUND_WEAPON_SPAWN); } else return; } // item drops from enemies if (m_Dropable) { if (m_Life > 0) m_Life--; else { m_SpawnTick = 999; return; } if (m_Life < 100) m_Flashing = true; } // a small visual effect before pickup disappears if (m_Flashing) { m_FlashTimer--; if (m_FlashTimer <= 0) m_FlashTimer = 20; if (m_FlashTimer > 10) m_SpawnTick = 999; else m_SpawnTick = -1; } // physics if (m_Dropable) { m_Vel.y += 0.5f; bool Grounded = false; if(GameServer()->Collision()->CheckPoint(m_Pos.x+12, m_Pos.y+12+5)) Grounded = true; if(GameServer()->Collision()->CheckPoint(m_Pos.x-12, m_Pos.y+12+5)) Grounded = true; if (Grounded) m_Vel.x *= 0.8f; else m_Vel.x *= 0.99f; GameServer()->Collision()->MoveBox(&m_Pos, &m_Vel, vec2(24.0f, 24.0f), 0.4f); } // Check if a player intersected us CCharacter *pChr = GameServer()->m_World.ClosestCharacter(m_Pos, 20.0f, 0); if(pChr && pChr->IsAlive()) // && !pChr->GetPlayer()->m_pAI) { // player picked us up, is someone was hooking us, let them go int RespawnTime = -1; switch (m_Type) { case POWERUP_HEALTH: if (m_Subtype > 0 && m_Owner >= 0 && m_Owner < MAX_CLIENTS && GameServer()->m_apPlayers[m_Owner]) { int Team = GameServer()->m_apPlayers[m_Owner]->GetTeam(); if (Team != pChr->GetPlayer()->GetTeam()) { if (m_Subtype == 1) GameServer()->CreateExplosion(m_Pos, m_Owner, WEAPON_HAMMER, false, false); if (m_Subtype == 2) { CSuperexplosion *S = new CSuperexplosion(&GameServer()->m_World, m_Pos, m_Owner, WEAPON_HAMMER, 1); GameServer()->m_World.InsertEntity(S); } GameServer()->CreateSound(m_Pos, SOUND_PICKUP_HEALTH); RespawnTime = g_pData->m_aPickups[m_Type].m_Respawntime; m_Life = 0; m_Flashing = false; m_Subtype = 0; break; } } if(pChr->IncreaseHealth(10)) { GameServer()->CreateSound(m_Pos, SOUND_PICKUP_HEALTH); RespawnTime = g_pData->m_aPickups[m_Type].m_Respawntime; m_Life = 0; m_Flashing = false; } else if (pChr->GetPlayer()->GotAbility(STORE_HEALTH) && pChr->StoreHealth()) { GameServer()->CreateSound(m_Pos, SOUND_PICKUP_HEALTH); RespawnTime = g_pData->m_aPickups[m_Type].m_Respawntime; m_Life = 0; m_Flashing = false; } break; case POWERUP_ARMOR: if(pChr->IncreaseArmor(1)) { GameServer()->CreateSound(m_Pos, SOUND_PICKUP_ARMOR); RespawnTime = g_pData->m_aPickups[m_Type].m_Respawntime; m_Life = 0; m_Flashing = false; } break; case POWERUP_WEAPON: if(m_Subtype >= 0 && m_Subtype < NUM_CUSTOMWEAPONS) { int Parent = aCustomWeapon[m_Subtype].m_ParentWeapon; if (Parent < 0 || Parent >= NUM_WEAPONS) { RespawnTime = g_pData->m_aPickups[m_Type].m_Respawntime; m_Life = 0; m_Flashing = false; break; } if (pChr->GiveCustomWeapon(m_Subtype, 0.2f + frandom()*0.3f)) { if(Parent == WEAPON_GRENADE) GameServer()->CreateSound(m_Pos, SOUND_PICKUP_GRENADE); else GameServer()->CreateSound(m_Pos, SOUND_PICKUP_SHOTGUN); if(pChr->GetPlayer()) { //GameServer()->SendWeaponPickup(pChr->GetPlayer()->GetCID(), Parent); char aBuf[256]; str_format(aBuf, sizeof(aBuf), "Picked up %s", aCustomWeapon[m_Subtype].m_Name); GameServer()->SendChatTarget(pChr->GetPlayer()->GetCID(), aBuf); } RespawnTime = g_pData->m_aPickups[m_Type].m_Respawntime; m_Life = 0; m_Flashing = false; } else { if (pChr->GiveAmmo(&m_Subtype, 0.125f + frandom()*0.15f)) { char aBuf[256]; str_format(aBuf, sizeof(aBuf), "Picked up ammo for %s", aCustomWeapon[m_Subtype].m_Name); GameServer()->SendChatTarget(pChr->GetPlayer()->GetCID(), aBuf); RespawnTime = g_pData->m_aPickups[m_Type].m_Respawntime; m_Life = 0; m_Flashing = false; } } /*if(pChr->GiveWeapon(m_Subtype, 10)) // !pChr->m_WeaponPicked && { RespawnTime = g_pData->m_aPickups[m_Type].m_Respawntime; //pChr->m_WeaponPicked = true; if(m_Subtype == WEAPON_GRENADE) GameServer()->CreateSound(m_Pos, SOUND_PICKUP_GRENADE); else if(m_Subtype == WEAPON_SHOTGUN) GameServer()->CreateSound(m_Pos, SOUND_PICKUP_SHOTGUN); else if(m_Subtype == WEAPON_RIFLE) GameServer()->CreateSound(m_Pos, SOUND_PICKUP_SHOTGUN); if(pChr->GetPlayer()) GameServer()->SendWeaponPickup(pChr->GetPlayer()->GetCID(), m_Subtype); }*/ } break; // sword not in use, instead snap weapon to look like sword case POWERUP_NINJA: { /* // activate ninja on target player pChr->GiveNinja(); RespawnTime = g_pData->m_aPickups[m_Type].m_Respawntime; // loop through all players, setting their emotes CCharacter *pC = static_cast<CCharacter *>(GameServer()->m_World.FindFirst(CGameWorld::ENTTYPE_CHARACTER)); for(; pC; pC = (CCharacter *)pC->TypeNext()) { if (pC != pChr) pC->SetEmote(EMOTE_SURPRISE, Server()->Tick() + Server()->TickSpeed()); } pChr->SetEmote(EMOTE_ANGRY, Server()->Tick() + 1200 * Server()->TickSpeed() / 1000); m_Flashing = false; break; */ } default: break; }; if(RespawnTime >= 0) { char aBuf[256]; str_format(aBuf, sizeof(aBuf), "pickup player='%d:%s' item=%d/%d", pChr->GetPlayer()->GetCID(), Server()->ClientName(pChr->GetPlayer()->GetCID()), m_Type, m_Subtype); GameServer()->Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "game", aBuf); m_SpawnTick = Server()->Tick() + Server()->TickSpeed() * RespawnTime; } } }
void CBuildings::RenderGenerator(const struct CNetObj_Building *pCurrent, const CNetObj_Building *pPrev) { vec2 Pos = mix(vec2(pPrev->m_X, pPrev->m_Y), vec2(pCurrent->m_X, pCurrent->m_Y), Client()->IntraGameTick()); // render Graphics()->TextureSet(g_pData->m_aImages[IMAGE_BUILDINGS].m_Id); Graphics()->QuadsBegin(); Graphics()->SetColor(1, 1, 1, 1); Graphics()->QuadsSetRotation(0); RenderTools()->SelectSprite(SPRITE_GENERATOR); RenderTools()->DrawSprite(Pos.x, Pos.y, 192); float c = sin(CustomStuff()->m_SawbladeAngle*0.25f)*0.3f + 0.7f; //team color if (m_pClient->m_Snap.m_pGameInfoObj) { int Flags = m_pClient->m_Snap.m_pGameInfoObj->m_GameFlags; int Team = pCurrent->m_Team; if ((Flags & GAMEFLAG_TEAMS) && !(Flags & GAMEFLAG_INFECTION)) { if (Team == TEAM_RED) Graphics()->SetColor(1, c, 0, 1); else if (Team == TEAM_BLUE) Graphics()->SetColor(0, c, 1, 1); } else if (Team == TEAM_RED) { vec4 pc = CustomStuff()->m_LocalColor; Graphics()->SetColor(pc.r, pc.g, pc.b, 1); } else Graphics()->SetColor(0.5f, c, 1, 1); } else Graphics()->SetColor(0.5f, c, 1, 1); RenderTools()->SelectSprite(SPRITE_GENERATOR_COLOR); RenderTools()->DrawSprite(Pos.x, Pos.y, 192); Graphics()->QuadsEnd(); bool Repair = pCurrent->m_Status & (1<<BSTATUS_REPAIR); float Time = Pos.x * 0.432f + pCurrent->m_Y * 0.2354f + CustomStuff()->m_SawbladeAngle * 0.1f; if (Repair) { Time += CustomStuff()->m_SawbladeAngle * 0.15f; if (frandom() < 0.15f) m_pClient->m_pEffects->Electrospark(vec2(Pos.x, Pos.y)+vec2(frandom()-frandom(), frandom()-frandom()) * 50.0f, 40+frandom()*20, vec2(0, 0)); } // repair sprite if (Repair && (CustomStuff()->LocalTick()/12+(pCurrent->m_X/8 + pCurrent->m_Y/32))%8 < 4) { Graphics()->QuadsBegin(); RenderTools()->SelectSprite(SPRITE_STATUS_REPAIR); Graphics()->SetColor(1, 1, 1, 1); Graphics()->QuadsSetRotation(0); RenderTools()->DrawSprite(Pos.x-34, Pos.y-52, 52); Graphics()->QuadsEnd(); } }
void CPickup::Tick() { if (!m_Dropable && GameServer()->Collision()->IsForceTile(m_Pos.x, m_Pos.y+24) != 0) { m_ResetableDropable = true; m_SpawnPos = m_Pos; m_Life = 280; m_Flashing = false; m_FlashTimer = 0; m_Dropable = true; m_Treasure = false; m_SpawnTick = -1; m_Ammo = 1.0f; } // wait for respawn //if(m_SpawnTick > 0) - 12.5. if(m_SpawnTick > 0 && (!m_Dropable || m_ResetableDropable) && !m_Flashing) { if(Server()->Tick() > m_SpawnTick && !m_SkipAutoRespawn) { // respawn m_SpawnTick = -1; if (m_ResetableDropable) { m_Pos = m_SpawnPos; m_Dropable = false; } if(m_Type == POWERUP_WEAPON) GameServer()->CreateSound(m_Pos, SOUND_WEAPON_SPAWN); } else return; } // item drops from enemies if (m_Dropable && !m_Treasure) { if (m_Life < 100) m_Flashing = true; if (m_Life > 0) m_Life--; else { if (m_ResetableDropable) { m_Flashing = false; m_Dropable = false; m_SpawnTick = Server()->Tick() + Server()->TickSpeed() * (4.0f+frandom()*6); } else m_SpawnTick = 999; return; } } // a small visual effect before pickup disappears if (m_Flashing) { m_FlashTimer--; if (m_FlashTimer <= 0) m_FlashTimer = 20; if (m_FlashTimer > 10) m_SpawnTick = 999; else m_SpawnTick = -1; } // physics if (m_Dropable && !m_Treasure) { m_Vel.y += 0.5f; bool Grounded = false; if(GameServer()->Collision()->CheckPoint(m_Pos.x+12, m_Pos.y+12+5)) Grounded = true; if(GameServer()->Collision()->CheckPoint(m_Pos.x-12, m_Pos.y+12+5)) Grounded = true; int OnForceTile = GameServer()->Collision()->IsForceTile(m_Pos.x-12, m_Pos.y+12+5); if (OnForceTile == 0) OnForceTile = GameServer()->Collision()->IsForceTile(m_Pos.x+12, m_Pos.y+12+5); if (Grounded) m_Vel.x = (m_Vel.x + OnForceTile) * 0.8f; //m_Vel.x *= 0.8f; else m_Vel.x *= 0.99f; //if (OnForceTile == -1) // m_Vel.x -= 0.3f; GameServer()->Collision()->MoveBox(&m_Pos, &m_Vel, vec2(24.0f, 24.0f), 0.4f); } // Check if a player intersected us CCharacter *pChr = GameServer()->m_World.ClosestCharacter(m_Pos, 20.0f, 0); if(pChr && pChr->IsAlive() && pChr->m_SkipPickups <= 0 && (!g_Config.m_SvBotsSkipPickups || !pChr->GetPlayer()->m_IsBot)) // && !pChr->GetPlayer()->m_pAI) { // player picked us up, is someone was hooking us, let them go int RespawnTime = -1; switch (m_Type) { case POWERUP_HEALTH: if(pChr->IncreaseHealth(10)) { GameServer()->CreateSound(m_Pos, SOUND_PICKUP_HEALTH); RespawnTime = g_pData->m_aPickups[m_Type].m_Respawntime; m_Life = 0; m_Flashing = false; } break; case POWERUP_ARMOR: if(pChr->IncreaseArmor(1)) { GameServer()->CreateSound(m_Pos, SOUND_PICKUP_ARMOR); RespawnTime = g_pData->m_aPickups[m_Type].m_Respawntime; m_Life = 0; m_Flashing = false; } break; case POWERUP_MINE: if(pChr->AddMine()) { GameServer()->CreateSound(m_Pos, SOUND_PICKUP_ARMOR); RespawnTime = g_pData->m_aPickups[m_Type].m_Respawntime; m_Life = 0; m_Flashing = false; } break; case POWERUP_KIT: if(pChr->AddKit()) { GameServer()->CreateSound(m_Pos, SOUND_PICKUP_ARMOR); RespawnTime = g_pData->m_aPickups[m_Type].m_Respawntime; m_Life = 0; m_Flashing = false; } break; // todo: clean and remove parent weapon type case POWERUP_WEAPON: if(m_Subtype >= 0 && m_Subtype < NUM_CUSTOMWEAPONS) { /* if (Parent < 0 || Parent >= NUM_WEAPONS) { RespawnTime = g_pData->m_aPickups[m_Type].m_Respawntime; m_Life = 0; m_Flashing = false; break; } */ float AmmoFill = 1.0f; if (m_Dropable) AmmoFill = 0.3f + frandom()*0.3f; if (m_Ammo >= 0.0f) AmmoFill = m_Ammo; if (pChr->GiveCustomWeapon(m_Subtype, AmmoFill)) { if(m_Subtype == WEAPON_GRENADE) GameServer()->CreateSound(m_Pos, SOUND_PICKUP_GRENADE); else GameServer()->CreateSound(m_Pos, SOUND_PICKUP_SHOTGUN); if(pChr->GetPlayer()) { //GameServer()->SendWeaponPickup(pChr->GetPlayer()->GetCID(), Parent); GameServer()->SendWeaponPickup(pChr->GetPlayer()->GetCID(), m_Subtype); //char aBuf[256]; str_format(aBuf, sizeof(aBuf), "Picked up %s", aCustomWeapon[m_Subtype].m_Name); //GameServer()->SendChatTarget(pChr->GetPlayer()->GetCID(), aBuf); } RespawnTime = g_pData->m_aPickups[m_Type].m_Respawntime; m_Life = 0; m_Flashing = false; } else { if (pChr->GiveAmmo(&m_Subtype, AmmoFill)) { if(m_Subtype == WEAPON_GRENADE) GameServer()->CreateSound(m_Pos, SOUND_PICKUP_GRENADE); else GameServer()->CreateSound(m_Pos, SOUND_PICKUP_SHOTGUN); //char aBuf[256]; str_format(aBuf, sizeof(aBuf), "Picked up ammo for %s", aCustomWeapon[m_Subtype].m_Name); //GameServer()->SendChatTarget(pChr->GetPlayer()->GetCID(), aBuf); if(pChr->GetPlayer()) GameServer()->SendWeaponPickup(pChr->GetPlayer()->GetCID(), m_Subtype); RespawnTime = g_pData->m_aPickups[m_Type].m_Respawntime; m_Life = 0; m_Flashing = false; } } /*if(pChr->GiveWeapon(m_Subtype, 10)) // !pChr->m_WeaponPicked && { RespawnTime = g_pData->m_aPickups[m_Type].m_Respawntime; //pChr->m_WeaponPicked = true; if(m_Subtype == WEAPON_GRENADE) GameServer()->CreateSound(m_Pos, SOUND_PICKUP_GRENADE); else if(m_Subtype == WEAPON_SHOTGUN) GameServer()->CreateSound(m_Pos, SOUND_PICKUP_SHOTGUN); else if(m_Subtype == WEAPON_RIFLE) GameServer()->CreateSound(m_Pos, SOUND_PICKUP_SHOTGUN); if(pChr->GetPlayer()) GameServer()->SendWeaponPickup(pChr->GetPlayer()->GetCID(), m_Subtype); }*/ } break; default: break; }; if(RespawnTime >= 0) { // force 10 sec on factory boxes if (m_ResetableDropable) m_SpawnTick = Server()->Tick() + Server()->TickSpeed() * (4.0f+frandom()*6); char aBuf[256]; str_format(aBuf, sizeof(aBuf), "pickup player='%d:%s' item=%d/%d", pChr->GetPlayer()->GetCID(), Server()->ClientName(pChr->GetPlayer()->GetCID()), m_Type, m_Subtype); GameServer()->Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "game", aBuf); m_SpawnTick = Server()->Tick() + Server()->TickSpeed() * RespawnTime; } } }
int main(int argc, char **argv) { FFTComplex *tab, *tab1, *tab_ref; FFTSample *tab2; int it, i, c; int do_speed = 0; int do_mdct = 0; int do_inverse = 0; FFTContext s1, *s = &s1; MDCTContext m1, *m = &m1; int fft_nbits, fft_size; fft_nbits = 9; for(;;) { c = getopt(argc, argv, "hsimn:"); if (c == -1) break; switch(c) { case 'h': help(); break; case 's': do_speed = 1; break; case 'i': do_inverse = 1; break; case 'm': do_mdct = 1; break; case 'n': fft_nbits = atoi(optarg); break; } } fft_size = 1 << fft_nbits; tab = av_malloc(fft_size * sizeof(FFTComplex)); tab1 = av_malloc(fft_size * sizeof(FFTComplex)); tab_ref = av_malloc(fft_size * sizeof(FFTComplex)); tab2 = av_malloc(fft_size * sizeof(FFTSample)); if (do_mdct) { if (do_inverse) av_log(NULL, AV_LOG_INFO,"IMDCT"); else av_log(NULL, AV_LOG_INFO,"MDCT"); ff_mdct_init(m, fft_nbits, do_inverse); } else { if (do_inverse) av_log(NULL, AV_LOG_INFO,"IFFT"); else av_log(NULL, AV_LOG_INFO,"FFT"); ff_fft_init(s, fft_nbits, do_inverse); fft_ref_init(fft_nbits, do_inverse); } av_log(NULL, AV_LOG_INFO," %d test\n", fft_size); /* generate random data */ for(i=0;i<fft_size;i++) { tab1[i].re = frandom(); tab1[i].im = frandom(); } /* checking result */ av_log(NULL, AV_LOG_INFO,"Checking...\n"); if (do_mdct) { if (do_inverse) { imdct_ref((float *)tab_ref, (float *)tab1, fft_nbits); ff_imdct_calc(m, tab2, (float *)tab1); check_diff((float *)tab_ref, tab2, fft_size); } else { mdct_ref((float *)tab_ref, (float *)tab1, fft_nbits); ff_mdct_calc(m, tab2, (float *)tab1); check_diff((float *)tab_ref, tab2, fft_size / 2); } } else { memcpy(tab, tab1, fft_size * sizeof(FFTComplex)); ff_fft_permute(s, tab); ff_fft_calc(s, tab); fft_ref(tab_ref, tab1, fft_nbits); check_diff((float *)tab_ref, (float *)tab, fft_size * 2); } /* do a speed test */ if (do_speed) { int64_t time_start, duration; int nb_its; av_log(NULL, AV_LOG_INFO,"Speed test...\n"); /* we measure during about 1 seconds */ nb_its = 1; for(;;) { time_start = gettime(); for(it=0;it<nb_its;it++) { if (do_mdct) { if (do_inverse) { ff_imdct_calc(m, (float *)tab, (float *)tab1); } else { ff_mdct_calc(m, (float *)tab, (float *)tab1); } } else { memcpy(tab, tab1, fft_size * sizeof(FFTComplex)); ff_fft_calc(s, tab); } } duration = gettime() - time_start; if (duration >= 1000000) break; nb_its *= 2; } av_log(NULL, AV_LOG_INFO,"time: %0.1f us/transform [total time=%0.2f s its=%d]\n", (double)duration / nb_its, (double)duration / 1000000.0, nb_its); } if (do_mdct) { ff_mdct_end(m); } else { ff_fft_end(s); } return 0; }
void CGameControllerCSBB::Restart() { char aBuf[128]; str_format(aBuf, sizeof(aBuf), "Restarting game"); GameServer()->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "cstt", aBuf); m_RedCaptureTime = 0; m_BlueCaptureTime = 0; m_Base = -1; m_DefendingTeam = -1; m_RoundTimeLimit = 0; // gamecontroller m_ResetTime = true; // gamecontroller m_NewGame = false; ClearPickups(); m_GameState = CSBB_NEWBASE; m_RoundTick = 0; m_Round = 0; m_BombDefuseTimer = 0; m_BombDefused = false; m_aTeamscore[TEAM_RED] = 0; m_aTeamscore[TEAM_BLUE] = 0; GameServer()->SendBroadcast("", -1); m_BombActionTimer = 0; for (int i = 0; i < MAX_CLIENTS; i++) { m_aDefusing[i] = false; m_aPlanting[i] = 0; m_aBombActionTimer[i] = 0; CPlayer *pPlayer = GameServer()->m_apPlayers[i]; if(!pPlayer) continue; pPlayer->m_CanShop = false; pPlayer->NewRound(); } GameServer()->m_FreezeCharacters = false; GameServer()->m_CanRespawn = true; m_BombCarrierTurn = frandom()*MAX_CLIENTS; m_RoundTimeLimit = 0; // gamecontroller protected if (m_pBomb) m_pBomb->m_Hide = true; for (int i = 0; i < MAX_BOMBAREAS; i++) { if (m_apBombArea[i]) { m_apBombArea[i]->m_Hide = true; m_apBombArea[i]->m_UseSnapping = false; //m_apBombArea[i]->m_Team = TEAM_BLUE; } } //m_pBomb->m_Team = TEAM_RED; GameServer()->ResetVotes(); }
double fnurandom1( double centricity ) { return pow( frandom(), 1 / (1 - centricity) ); }
void CAIpyro2::DoBehavior() { m_Attack = 0; if (m_ShockTimer > 0 && m_ShockTimer--) { m_ReactionTime = 1 + frandom()*3; return; } HeadToMovingDirection(); SeekClosestEnemyInSight(); bool Jump = false; bool Shooting = false; // if we see a player if (m_EnemiesInSight > 0) { ReactToPlayer(); if (ShootAtClosestEnemy()) { Shooting = true; } else { if (SeekClosestEnemy()) { m_TargetPos = m_PlayerPos; if (WeaponShootRange() - m_PlayerDistance > 200) SeekRandomWaypoint(); } } } else { //if (Player()->GetCharacter()->PlayerCollision() && frandom()*10 < 3) // Jump = true; ShootAtClosestBuilding(); if (SeekClosestEnemy()) m_TargetPos = m_PlayerPos; else if(SeekRandomEnemy()) { m_TargetPos = m_PlayerPos; if (WeaponShootRange() - m_PlayerDistance > 200) SeekRandomWaypoint(); } } if ((Shooting && Player()->GetCharacter()->IsGrounded()) || (abs(m_Pos.x - m_TargetPos.x) < 40 && abs(m_Pos.y - m_TargetPos.y) < 40)) { // stand still m_Move = 0; m_Jump = 0; m_Hook = 0; } else { if (UpdateWaypoint()) { MoveTowardsWaypoint(); } else { m_WaypointPos = m_TargetPos; MoveTowardsWaypoint(true); } } if (Jump) m_Jump = 1; Player()->GetCharacter()->m_SkipPickups = 999; RandomlyStopShooting(); if (m_ShockTimer > 0 && m_ShockTimer--) { m_Attack = 0; m_Move = 0; m_Hook = 0; m_Jump = 0; } // next reaction in m_ReactionTime = 1 + frandom()*3; }
int paint( /* compute and paint a rectangle */ PNODE *p ) { static RAY thisray; double h, v; if ((p->xmax <= p->xmin) | (p->ymax <= p->ymin)) { /* empty */ p->x = p->xmin; p->y = p->ymin; setcolor(p->v, 0.0, 0.0, 0.0); return(0); } /* jitter ray direction */ p->x = h = p->xmin + (p->xmax-p->xmin)*frandom(); p->y = v = p->ymin + (p->ymax-p->ymin)*frandom(); if ((thisray.rmax = viewray(thisray.rorg, thisray.rdir, &ourview, h/hresolu, v/vresolu)) < -FTINY) { setcolor(thisray.rcol, 0.0, 0.0, 0.0); } else if (!ray_pnprocs) { /* immediate mode */ ray_trace(&thisray); } else { /* queuing mode */ int rval; rayorigin(&thisray, PRIMARY, NULL, NULL); thisray.rno = (RNUMBER)p; rval = ray_pqueue(&thisray); if (!rval) return(0); if (rval < 0) return(-1); /* get node for returned ray */ p = (PNODE *)thisray.rno; } copycolor(p->v, thisray.rcol); scalecolor(p->v, exposure); recolor(p); /* paint it */ if (dev->flush != NULL) { /* shall we check for input? */ static RNUMBER lastflush = 0; RNUMBER counter = raynum; int flushintvl; if (!ray_pnprocs) { counter = nrays; flushintvl = WFLUSH1; } else if (ambounce == 0) flushintvl = ray_pnprocs*WFLUSH; else if (niflush < WFLUSH) flushintvl = ray_pnprocs*niflush/(ambounce+1); else flushintvl = ray_pnprocs*WFLUSH/(ambounce+1); if (lastflush > counter) lastflush = 0; /* counter wrapped */ if (counter - lastflush >= flushintvl) { lastflush = counter; (*dev->flush)(); niflush++; } } return(1); }
int Random::irandom(int lo, int hi) { double xx = frandom(); return (int) round (lo + xx * (hi-lo)); }
float Random::frandom(float lo, float hi) { double xx = frandom(); xx = lo + xx * (hi-lo); return xx; }
int Random::irandom (int N) { float xx = frandom() *N; return (int) round(xx); }
void CFlowEmitter::OnRender() { for (int i = 0; i < MAX_FLOWSETTINGS; i++) { if (m_aFlowSettings[i].m_Activ) { m_pClient->m_pFlow->Add(m_aFlowSettings[i].m_Pos, m_aFlowSettings[i].m_Vel * (m_aFlowSettings[i].m_VelRandomAdd + m_aFlowSettings[i].m_VelRandomMulti * (frandom() + m_aFlowSettings[i].m_VelRandomInAdd)), m_aFlowSettings[i].m_Size); } } }
inline vec2 RandomDir() { return normalize(vec2(frandom()-0.5f, frandom()-0.5f)); }
int CGameControllerCSBB::OnCharacterDeath(class CCharacter *pVictim, class CPlayer *pKiller, int WeaponID) { //IGameController::OnCharacterDeath(pVictim, pKiller, WeaponID); int HadBomb = 0; pVictim->GetPlayer()->m_InterestPoints = 0; int DropWeapon = pVictim->m_ActiveCustomWeapon; if (DropWeapon != HAMMER_BASIC && DropWeapon != GUN_PISTOL) // g_Config.m_SvWeaponDrops == 1 && { DropPickup(pVictim->m_Pos, POWERUP_WEAPON, pVictim->m_LatestHitVel, DropWeapon); for (int i = 0; i < 2; i++) { if (frandom()*10 < 3) DropPickup(pVictim->m_Pos, POWERUP_ARMOR, pVictim->m_LatestHitVel+vec2(frandom()*6.0-frandom()*6.0, frandom()*6.0-frandom()*6.0), 0); else DropPickup(pVictim->m_Pos, POWERUP_HEALTH, pVictim->m_LatestHitVel+vec2(frandom()*6.0-frandom()*6.0, frandom()*6.0-frandom()*6.0), 0); } } else { // drop pickup if (pVictim->HasAmmo()) DropPickup(pVictim->m_Pos, POWERUP_ARMOR, pVictim->m_LatestHitVel, 0); else DropPickup(pVictim->m_Pos, POWERUP_HEALTH, pVictim->m_LatestHitVel, 0); for (int i = 0; i < 2; i++) { if (frandom()*10 < 3) DropPickup(pVictim->m_Pos, POWERUP_ARMOR, pVictim->m_LatestHitVel+vec2(frandom()*6.0-frandom()*6.0, frandom()*6.0-frandom()*6.0), 0); else DropPickup(pVictim->m_Pos, POWERUP_HEALTH, pVictim->m_LatestHitVel+vec2(frandom()*6.0-frandom()*6.0, frandom()*6.0-frandom()*6.0), 0); } } // drop flags CBomb *B = m_pBomb; if(B && pKiller && pKiller->GetCharacter() && B->m_pCarryingCharacter == pKiller->GetCharacter()) HadBomb |= 2; if(B && B->m_pCarryingCharacter == pVictim) { GameServer()->CreateSoundGlobal(SOUND_CTF_DROP); B->m_DropTick = Server()->Tick(); B->m_pCarryingCharacter = 0; B->m_Vel = vec2(0,0); B->m_Status = BOMB_IDLE; HadBomb |= 1; } if(pKiller && pKiller->GetTeam() != pVictim->GetPlayer()->GetTeam()) { pKiller->m_Score++; pKiller->AddMoney(g_Config.m_SvKillMoney); pKiller->m_InterestPoints += 60; } //if (WeaponID != WEAPON_GAME) // pVictim->GetPlayer()->m_ForceToSpectators = true; pVictim->GetPlayer()->m_RespawnTick = Server()->Tick()+Server()->TickSpeed()*g_Config.m_SvRespawnDelayCSBB; return HadBomb; }
void CParticles::Update(float TimePassed) { static float FrictionFraction = 0; FrictionFraction += TimePassed; if(FrictionFraction > 2.0f) // safty messure FrictionFraction = 0; int FrictionCount = 0; while(FrictionFraction > 0.05f) { FrictionCount++; FrictionFraction -= 0.05f; } for(int g = 0; g < NUM_GROUPS; g++) { int i = m_aFirstPart[g]; while(i != -1) { int Next = m_aParticles[i].m_NextPart; //m_aParticles[i].vel += flow_get(m_aParticles[i].pos)*time_passed * m_aParticles[i].flow_affected; m_aParticles[i].m_Vel.y += m_aParticles[i].m_Gravity*TimePassed; for(int f = 0; f < FrictionCount; f++) // apply friction m_aParticles[i].m_Vel *= m_aParticles[i].m_Friction; // move the point vec2 Vel = m_aParticles[i].m_Vel*TimePassed; if (m_aParticles[i].m_Type == PARTICLE_BLOOD) { int coll = 0; Collision()->MovePoint(&m_aParticles[i].m_Pos, &Vel, 0.1f, NULL, &coll); if (coll && !m_aParticles[i].m_Collide) { Collision()->IntersectLine(m_aParticles[i].m_LastPos, m_aParticles[i].m_Pos, 0x0, &m_aParticles[i].m_Pos, false); vec2 Dir = normalize(m_aParticles[i].m_Vel); CParticle p; p.SetDefault(); p.m_Spr = SPRITE_PART_EXPL01; p.m_Pos = m_aParticles[i].m_Pos + Dir * 8.0f; p.m_Vel = vec2(0.0,0.0f); p.m_LifeSpan = 30.0f + frandom()*0.3f; p.m_StartSize = 5.0f + frandom()*22.0f; p.m_EndSize = 5.0f + frandom()*22.0f; p.m_Rot = frandom()*pi*2; p.m_Rotspeed = 0.0f; p.m_Gravity = 0.0f; p.m_Friction = 0.0f; p.m_Type = PARTICLE_BLOOD_L; p.m_Collide = true; p.m_Color = vec4(m_aParticles[i].m_Color.r, m_aParticles[i].m_Color.g, m_aParticles[i].m_Color.b, 0.35f); m_pClient->m_pParticles->Add(CParticles::GROUP_HCLIENT_BLOOD, &p); m_aParticles[i].m_Collide = true; m_aParticles[i].m_Life = m_aParticles[i].m_LifeSpan+1; } m_aParticles[i].m_LastPos = m_aParticles[i].m_Pos; } else Collision()->MovePoint(&m_aParticles[i].m_Pos, &Vel, 0.1f+0.9f*frandom(), NULL); m_aParticles[i].m_Vel = Vel* (1.0f/TimePassed); m_aParticles[i].m_Life += TimePassed; m_aParticles[i].m_Rot += TimePassed * m_aParticles[i].m_Rotspeed; // check particle death if(m_aParticles[i].m_Life > m_aParticles[i].m_LifeSpan) { // remove it from the group list if(m_aParticles[i].m_PrevPart != -1) m_aParticles[m_aParticles[i].m_PrevPart].m_NextPart = m_aParticles[i].m_NextPart; else m_aFirstPart[g] = m_aParticles[i].m_NextPart; if(m_aParticles[i].m_NextPart != -1) m_aParticles[m_aParticles[i].m_NextPart].m_PrevPart = m_aParticles[i].m_PrevPart; // insert to the free list if(m_FirstFree != -1) m_aParticles[m_FirstFree].m_PrevPart = i; m_aParticles[i].m_PrevPart = -1; m_aParticles[i].m_NextPart = m_FirstFree; m_FirstFree = i; } i = Next; } } }
int main(int argc, char **argv) { FFTComplex *tab, *tab1, *tab_ref; FFTSample *tab2; int it, i, c; int do_speed = 0; int err = 1; enum tf_transform transform = TRANSFORM_FFT; int do_inverse = 0; FFTContext s1, *s = &s1; FFTContext m1, *m = &m1; RDFTContext r1, *r = &r1; DCTContext d1, *d = &d1; int fft_nbits, fft_size, fft_size_2; double scale = 1.0; AVLFG prng; av_lfg_init(&prng, 1); fft_nbits = 9; for(;;) { c = getopt(argc, argv, "hsimrdn:f:"); if (c == -1) break; switch(c) { case 'h': help(); break; case 's': do_speed = 1; break; case 'i': do_inverse = 1; break; case 'm': transform = TRANSFORM_MDCT; break; case 'r': transform = TRANSFORM_RDFT; break; case 'd': transform = TRANSFORM_DCT; break; case 'n': fft_nbits = atoi(optarg); break; case 'f': scale = atof(optarg); break; } } fft_size = 1 << fft_nbits; fft_size_2 = fft_size >> 1; tab = av_malloc(fft_size * sizeof(FFTComplex)); tab1 = av_malloc(fft_size * sizeof(FFTComplex)); tab_ref = av_malloc(fft_size * sizeof(FFTComplex)); tab2 = av_malloc(fft_size * sizeof(FFTSample)); switch (transform) { case TRANSFORM_MDCT: av_log(NULL, AV_LOG_INFO,"Scale factor is set to %f\n", scale); if (do_inverse) av_log(NULL, AV_LOG_INFO,"IMDCT"); else av_log(NULL, AV_LOG_INFO,"MDCT"); ff_mdct_init(m, fft_nbits, do_inverse, scale); break; case TRANSFORM_FFT: if (do_inverse) av_log(NULL, AV_LOG_INFO,"IFFT"); else av_log(NULL, AV_LOG_INFO,"FFT"); ff_fft_init(s, fft_nbits, do_inverse); fft_ref_init(fft_nbits, do_inverse); break; case TRANSFORM_RDFT: if (do_inverse) av_log(NULL, AV_LOG_INFO,"IDFT_C2R"); else av_log(NULL, AV_LOG_INFO,"DFT_R2C"); ff_rdft_init(r, fft_nbits, do_inverse ? IDFT_C2R : DFT_R2C); fft_ref_init(fft_nbits, do_inverse); break; case TRANSFORM_DCT: if (do_inverse) av_log(NULL, AV_LOG_INFO,"DCT_III"); else av_log(NULL, AV_LOG_INFO,"DCT_II"); ff_dct_init(d, fft_nbits, do_inverse ? DCT_III : DCT_II); break; } av_log(NULL, AV_LOG_INFO," %d test\n", fft_size); /* generate random data */ for (i = 0; i < fft_size; i++) { tab1[i].re = frandom(&prng); tab1[i].im = frandom(&prng); } /* checking result */ av_log(NULL, AV_LOG_INFO,"Checking...\n"); switch (transform) { case TRANSFORM_MDCT: if (do_inverse) { imdct_ref((float *)tab_ref, (float *)tab1, fft_nbits); ff_imdct_calc(m, tab2, (float *)tab1); err = check_diff((float *)tab_ref, tab2, fft_size, scale); } else { mdct_ref((float *)tab_ref, (float *)tab1, fft_nbits); ff_mdct_calc(m, tab2, (float *)tab1); err = check_diff((float *)tab_ref, tab2, fft_size / 2, scale); } break; case TRANSFORM_FFT: memcpy(tab, tab1, fft_size * sizeof(FFTComplex)); ff_fft_permute(s, tab); ff_fft_calc(s, tab); fft_ref(tab_ref, tab1, fft_nbits); err = check_diff((float *)tab_ref, (float *)tab, fft_size * 2, 1.0); break; case TRANSFORM_RDFT: if (do_inverse) { tab1[ 0].im = 0; tab1[fft_size_2].im = 0; for (i = 1; i < fft_size_2; i++) { tab1[fft_size_2+i].re = tab1[fft_size_2-i].re; tab1[fft_size_2+i].im = -tab1[fft_size_2-i].im; } memcpy(tab2, tab1, fft_size * sizeof(FFTSample)); tab2[1] = tab1[fft_size_2].re; ff_rdft_calc(r, tab2); fft_ref(tab_ref, tab1, fft_nbits); for (i = 0; i < fft_size; i++) { tab[i].re = tab2[i]; tab[i].im = 0; } err = check_diff((float *)tab_ref, (float *)tab, fft_size * 2, 0.5); } else { for (i = 0; i < fft_size; i++) { tab2[i] = tab1[i].re; tab1[i].im = 0; } ff_rdft_calc(r, tab2); fft_ref(tab_ref, tab1, fft_nbits); tab_ref[0].im = tab_ref[fft_size_2].re; err = check_diff((float *)tab_ref, (float *)tab2, fft_size, 1.0); } break; case TRANSFORM_DCT: memcpy(tab, tab1, fft_size * sizeof(FFTComplex)); ff_dct_calc(d, tab); if (do_inverse) { idct_ref(tab_ref, tab1, fft_nbits); } else { dct_ref(tab_ref, tab1, fft_nbits); } err = check_diff((float *)tab_ref, (float *)tab, fft_size, 1.0); break; } /* do a speed test */ if (do_speed) { int64_t time_start, duration; int nb_its; av_log(NULL, AV_LOG_INFO,"Speed test...\n"); /* we measure during about 1 seconds */ nb_its = 1; for(;;) { time_start = gettime(); for (it = 0; it < nb_its; it++) { switch (transform) { case TRANSFORM_MDCT: if (do_inverse) { ff_imdct_calc(m, (float *)tab, (float *)tab1); } else { ff_mdct_calc(m, (float *)tab, (float *)tab1); } break; case TRANSFORM_FFT: memcpy(tab, tab1, fft_size * sizeof(FFTComplex)); ff_fft_calc(s, tab); break; case TRANSFORM_RDFT: memcpy(tab2, tab1, fft_size * sizeof(FFTSample)); ff_rdft_calc(r, tab2); break; case TRANSFORM_DCT: memcpy(tab2, tab1, fft_size * sizeof(FFTSample)); ff_dct_calc(d, tab2); break; } } duration = gettime() - time_start; if (duration >= 1000000) break; nb_its *= 2; } av_log(NULL, AV_LOG_INFO,"time: %0.1f us/transform [total time=%0.2f s its=%d]\n", (double)duration / nb_its, (double)duration / 1000000.0, nb_its); } switch (transform) { case TRANSFORM_MDCT: ff_mdct_end(m); break; case TRANSFORM_FFT: ff_fft_end(s); break; case TRANSFORM_RDFT: ff_rdft_end(r); break; case TRANSFORM_DCT: ff_dct_end(d); break; } av_free(tab); av_free(tab1); av_free(tab2); av_free(tab_ref); av_free(exptab); return err; }
void CAIPistolbot::DoBehavior() { vec2 Pos; // character check if (Player()->GetCharacter()) Pos = Player()->GetCharacter()->m_Pos; else return; // reset jump and attack m_Jump = 0; m_Attack = 0; CheckAITiles(); SeekPlayer(); // unstuck move if (abs(Pos.x - m_LastPos.x) < 20) { if (frandom() * 10 < 3) m_Move = -1; if (frandom() * 10 < 3) m_Move = 1; if (frandom() * 10 < 2) m_Jump = 1; } if (m_PlayerSpotCount > 0) { m_TargetTimer = 0; // on first time standstill and look stupid if (m_PlayerSpotCount == 1) { m_Move = 0; m_Direction = m_PlayerDirection; m_TargetPos = m_PlayerPos; m_Jump = 0; Player()->GetCharacter()->SetEmoteFor(EMOTE_ANGRY, 1200, 1200); m_ReactionTime = 40; return; } if (m_PlayerPos.x < Pos.x) m_TargetPos.x = m_PlayerPos.x + 400; else m_TargetPos.x = m_PlayerPos.x - 400; MoveTowardsTarget(140); if (m_PlayerDistance < 600) m_Attack = 1; if (m_PlayerDistance < 800) { m_Direction = m_PlayerDirection; } // start timer if (m_PlayerSpotTimer == 0) m_PlayerSpotTimer++; } else { // head to moving direction if (m_Move != 0) m_Direction = vec2(m_Move, 0); } /* // forget target after a while if (m_TargetTimer > 0) { MoveTowardsTarget(); if (m_TargetTimer > 20) { m_TargetTimer = 0; m_Move = 0; m_Jump = 0; m_Attack = 0; m_ReactionTime = 60 + frandom()*3; Player()->GetCharacter()->SetEmoteFor(EMOTE_HAPPY, 1200); GameServer()->SendEmoticon(Player()->GetCID(), EMOTICON_ZZZ); return; } } */ // next reaction in m_ReactionTime = 6 + frandom()*3; }
static int ambsample( /* initial ambient division sample */ AMBHEMI *hp, int i, int j, int n ) { AMBSAMP *ap = &ambsam(hp,i,j); RAY ar; int hlist[3], ii; double spt[2], zd; /* generate hemispherical sample */ /* ambient coefficient for weight */ if (ambacc > FTINY) setcolor(ar.rcoef, AVGREFL, AVGREFL, AVGREFL); else copycolor(ar.rcoef, hp->acoef); if (rayorigin(&ar, AMBIENT, hp->rp, ar.rcoef) < 0) return(0); if (ambacc > FTINY) { multcolor(ar.rcoef, hp->acoef); scalecolor(ar.rcoef, 1./AVGREFL); } hlist[0] = hp->rp->rno; hlist[1] = j; hlist[2] = i; multisamp(spt, 2, urand(ilhash(hlist,3)+n)); resample: SDsquare2disk(spt, (j+spt[1])/hp->ns, (i+spt[0])/hp->ns); zd = sqrt(1. - spt[0]*spt[0] - spt[1]*spt[1]); for (ii = 3; ii--; ) ar.rdir[ii] = spt[0]*hp->ux[ii] + spt[1]*hp->uy[ii] + zd*hp->rp->ron[ii]; checknorm(ar.rdir); /* avoid coincident samples */ if (!n && ambcollision(hp, i, j, ar.rdir)) { spt[0] = frandom(); spt[1] = frandom(); goto resample; /* reject this sample */ } dimlist[ndims++] = AI(hp,i,j) + 90171; rayvalue(&ar); /* evaluate ray */ ndims--; zd = raydistance(&ar); if (zd <= FTINY) return(0); /* should never happen */ multcolor(ar.rcol, ar.rcoef); /* apply coefficient */ if (zd*ap->d < 1.0) /* new/closer distance? */ ap->d = 1.0/zd; if (!n) { /* record first vertex & value */ if (zd > 10.0*thescene.cusize + 1000.) zd = 10.0*thescene.cusize + 1000.; VSUM(ap->p, ar.rorg, ar.rdir, zd); copycolor(ap->v, ar.rcol); } else { /* else update recorded value */ hp->acol[RED] -= colval(ap->v,RED); hp->acol[GRN] -= colval(ap->v,GRN); hp->acol[BLU] -= colval(ap->v,BLU); zd = 1.0/(double)(n+1); scalecolor(ar.rcol, zd); zd *= (double)n; scalecolor(ap->v, zd); addcolor(ap->v, ar.rcol); } addcolor(hp->acol, ap->v); /* add to our sum */ return(1); }
void CGameControllerMOD::Tick() { IGameController::Tick(); m_HumanCounter = 0; m_InfectedCounter = 0; //Count type of players for(int i = 0; i < MAX_CLIENTS; i ++) { CPlayer *pPlayer = GameServer()->m_apPlayers[i]; if(!pPlayer) continue; if(pPlayer->GetTeam() == TEAM_SPECTATORS) continue; if(pPlayer->IsInfected()) m_InfectedCounter++; else m_HumanCounter++; } m_InfectedStarted = false; //If the game can start ... if(m_GameOverTick == -1 && m_HumanCounter + m_InfectedCounter >= 2) { //If the infection started if(m_RoundStartTick + Server()->TickSpeed()*10 < Server()->Tick()) { m_InfectedStarted = true; for(int i = 0; i < MAX_CLIENTS; i ++) { CPlayer *pPlayer = GameServer()->m_apPlayers[i]; if(!pPlayer) continue; if(pPlayer->GetTeam() == TEAM_SPECTATORS) { pPlayer->StartInfection(); } else if(pPlayer->GetClass() == PLAYERCLASS_NONE) { pPlayer->SetClass(ChooseHumanClass(pPlayer)); if(pPlayer->GetCharacter()) pPlayer->GetCharacter()->IncreaseArmor(10); } } //If needed, infect players int nbInfectedNeeded = 2; if(m_InfectedCounter + m_HumanCounter < 4) { nbInfectedNeeded = 1; } while(m_InfectedCounter < nbInfectedNeeded) { float InfectionProb = 1.0/static_cast<float>(m_HumanCounter); float random = frandom(); //Fair infection bool FairInfectionFound = false; for(int i = 0; i < MAX_CLIENTS; i ++) { CPlayer *pPlayer = GameServer()->m_apPlayers[i]; if(!pPlayer) continue; if(pPlayer->GetTeam() == TEAM_SPECTATORS) continue; if(pPlayer->IsInfected()) continue; if(!Server()->IsClientInfectedBefore(i)) { Server()->InfecteClient(i); GameServer()->m_apPlayers[i]->StartInfection(); m_InfectedCounter++; m_HumanCounter--; GameServer()->SendChatTarget_Language_s(-1, "%s has been infected", Server()->ClientName(i)); FairInfectionFound = true; break; } } //Unfair infection if(!FairInfectionFound) { for(int i = 0; i < MAX_CLIENTS; i ++) { CPlayer *pPlayer = GameServer()->m_apPlayers[i]; if(!pPlayer) continue; if(pPlayer->GetTeam() == TEAM_SPECTATORS) continue; if(pPlayer->IsInfected()) continue; if(random < InfectionProb) { Server()->InfecteClient(i); GameServer()->m_apPlayers[i]->StartInfection(); m_InfectedCounter++; m_HumanCounter--; GameServer()->SendChatTarget_Language_s(-1, "%s has been infected", Server()->ClientName(i)); break; } else { random -= InfectionProb; } } } } } else { for(int i = 0; i < MAX_CLIENTS; i ++) { CPlayer *pPlayer = GameServer()->m_apPlayers[i]; if(!pPlayer) continue; if(pPlayer->GetTeam() == TEAM_SPECTATORS) { pPlayer->SetClass(PLAYERCLASS_NONE); } } } //Win check if(m_InfectedStarted && m_HumanCounter == 0 && m_InfectedCounter > 1) { float RoundDuration = static_cast<float>((Server()->Tick()-m_RoundStartTick)/((float)Server()->TickSpeed()))/60.0f; int Minutes = static_cast<int>(RoundDuration); int Seconds = static_cast<int>((RoundDuration - Minutes)*60.0f); GameServer()->SendChatTarget_Language_ii(-1, "Infected won the round in %i:%02i minutes", Minutes, Seconds); EndRound(); } //Start the final explosion if the time is over if(m_InfectedStarted && !m_ExplosionStarted && g_Config.m_SvTimelimit > 0 && (Server()->Tick()-m_RoundStartTick) >= g_Config.m_SvTimelimit*Server()->TickSpeed()*60) { for(CCharacter *p = (CCharacter*) GameServer()->m_World.FindFirst(CGameWorld::ENTTYPE_CHARACTER); p; p = (CCharacter *)p->TypeNext()) { if(p->IsInfected()) { GameServer()->SendEmoticon(p->GetPlayer()->GetCID(), EMOTICON_GHOST); } else { GameServer()->SendEmoticon(p->GetPlayer()->GetCID(), EMOTICON_EYES); } } m_ExplosionStarted = true; } //Do the final explosion if(m_ExplosionStarted) { bool NewExplosion = false; for(int j=0; j<m_MapHeight; j++) { for(int i=0; i<m_MapWidth; i++) { if((m_GrowingMap[j*m_MapWidth+i] & 1) && ( (i > 0 && m_GrowingMap[j*m_MapWidth+i-1] & 2) || (i < m_MapWidth-1 && m_GrowingMap[j*m_MapWidth+i+1] & 2) || (j > 0 && m_GrowingMap[(j-1)*m_MapWidth+i] & 2) || (j < m_MapHeight-1 && m_GrowingMap[(j+1)*m_MapWidth+i] & 2) )) { NewExplosion = true; m_GrowingMap[j*m_MapWidth+i] |= 8; m_GrowingMap[j*m_MapWidth+i] &= ~1; if(rand()%10 == 0) { vec2 TilePos = vec2(16.0f, 16.0f) + vec2(i*32.0f, j*32.0f); GameServer()->CreateExplosion(TilePos, -1, WEAPON_GAME, true); GameServer()->CreateSound(TilePos, SOUND_GRENADE_EXPLODE); } } } } for(int j=0; j<m_MapHeight; j++) { for(int i=0; i<m_MapWidth; i++) { if(m_GrowingMap[j*m_MapWidth+i] & 8) { m_GrowingMap[j*m_MapWidth+i] &= ~8; m_GrowingMap[j*m_MapWidth+i] |= 2; } } } for(CCharacter *p = (CCharacter*) GameServer()->m_World.FindFirst(CGameWorld::ENTTYPE_CHARACTER); p; p = (CCharacter *)p->TypeNext()) { if(!p->IsInfected()) continue; int tileX = static_cast<int>(round(p->m_Pos.x))/32; int tileY = static_cast<int>(round(p->m_Pos.y))/32; if(tileX < 0) tileX = 0; if(tileX >= m_MapWidth) tileX = m_MapWidth-1; if(tileY < 0) tileY = 0; if(tileY >= m_MapHeight) tileY = m_MapHeight-1; if(m_GrowingMap[tileY*m_MapWidth+tileX] & 2 && p->GetPlayer()) { p->Die(p->GetPlayer()->GetCID(), WEAPON_GAME); } } //If no more explosions, game over, decide who win if(!NewExplosion) { if(m_HumanCounter) { if(m_HumanCounter <= 1) { GameServer()->SendChatTarget_Language(-1, "One human won the round"); } else { GameServer()->SendChatTarget_Language_i(-1, "%i humans won the round", m_HumanCounter); } for(int i = 0; i < MAX_CLIENTS; i ++) { CPlayer *pPlayer = GameServer()->m_apPlayers[i]; if(!pPlayer) continue; if(pPlayer->GetTeam() == TEAM_SPECTATORS) continue; if(!pPlayer->IsInfected()) { pPlayer->IncreaseScore(5); pPlayer->m_WinAsHuman++; GameServer()->SendChatTarget_Language(i, "You have survived, +5 points"); } } } else { GameServer()->SendChatTarget_Language_ii(-1, "Infected won the round in %i:%02i minutes", g_Config.m_SvTimelimit, 0); } EndRound(); } } } else { m_RoundStartTick = Server()->Tick(); } }
CBuilding::CBuilding(CGameWorld *pGameWorld, vec2 Pos, int Type, int Team) : CEntity(pGameWorld, CGameWorld::ENTTYPE_BUILDING) { m_SetTimer = 0; m_Center = vec2(0, 0); m_Status = 0; for (int i = 0; i < NUM_BSTATUS; i++) m_aStatus[i] = 0; switch (Type) { case BUILDING_SAWBLADE: m_ProximityRadius = SawbladePhysSize; m_Life = 100; break; case BUILDING_MINE1: case BUILDING_MINE2: m_ProximityRadius = MinePhysSize; m_Life = 10+frandom()*10; m_SetTimer = GameServer()->Server()->TickSpeed()*1.5f; break; case BUILDING_BARREL: m_ProximityRadius = BarrelPhysSize; m_Life = 15+frandom()*10; break; case BUILDING_LAZER: m_ProximityRadius = LazerPhysSize; m_Life = 100; break; case BUILDING_BASE: m_ProximityRadius = BasePhysSize; m_Life = 60; break; case BUILDING_STAND: m_ProximityRadius = StandPhysSize; m_Life = 60; m_Center = vec2(0, -10); break; case BUILDING_FLAMETRAP: m_ProximityRadius = FlametrapPhysSize; m_Life = 60; break; default: m_ProximityRadius = BuildingPhysSize; m_Life = 100; }; m_Pos = Pos; m_Team = Team; m_Type = Type; m_MaxLife = m_Life; if (!GameServer()->m_pController->IsTeamplay()) m_Team = TEAM_NEUTRAL; if (m_Team == TEAM_BLUE) m_DamageOwner = BLUE_BASE; else if (m_Team == TEAM_RED) m_DamageOwner = RED_BASE; else m_DamageOwner = NEUTRAL_BASE; m_TriggerTimer = 0; GameWorld()->InsertEntity(this); }
int CGameControllerMOD::ChooseHumanClass(CPlayer* pPlayer) { float random = frandom(); float TotalProbHumanClass = m_TotalProbHumanClass; //Get information about existing infected int nbSupport = 0; int nbMedic = 0; int nbDefender = 0; for(int i = 0; i < MAX_CLIENTS; i++) { CPlayer *pPlayer = GameServer()->m_apPlayers[i]; if(!pPlayer) continue; if(pPlayer->GetTeam() == TEAM_SPECTATORS) continue; switch(pPlayer->GetClass()) { case PLAYERCLASS_NINJA: case PLAYERCLASS_MERCENARY: case PLAYERCLASS_SNIPER: nbSupport++; break; case PLAYERCLASS_MEDIC: nbMedic++; break; case PLAYERCLASS_ENGINEER: case PLAYERCLASS_SOLDIER: case PLAYERCLASS_SCIENTIST: nbDefender++; break; } } bool defenderEnabled = true; if(nbDefender >= g_Config.m_InfDefenderLimit) { TotalProbHumanClass -= m_ClassProbability[PLAYERCLASS_ENGINEER]; TotalProbHumanClass -= m_ClassProbability[PLAYERCLASS_SOLDIER]; TotalProbHumanClass -= m_ClassProbability[PLAYERCLASS_SCIENTIST]; defenderEnabled = false; } bool supportEnabled = true; if(nbSupport >= g_Config.m_InfSupportLimit) { TotalProbHumanClass -= m_ClassProbability[PLAYERCLASS_NINJA]; TotalProbHumanClass -= m_ClassProbability[PLAYERCLASS_MERCENARY]; TotalProbHumanClass -= m_ClassProbability[PLAYERCLASS_SNIPER]; supportEnabled = false; } bool medicEnabled = true; if(nbMedic >= g_Config.m_InfMedicLimit) { TotalProbHumanClass -= m_ClassProbability[PLAYERCLASS_MEDIC]; medicEnabled = false; } if(defenderEnabled) { random -= m_ClassProbability[PLAYERCLASS_ENGINEER]/TotalProbHumanClass; if(random < 0.0f) { return PLAYERCLASS_ENGINEER; } random -= m_ClassProbability[PLAYERCLASS_SOLDIER]/TotalProbHumanClass; if(random < 0.0f) { return PLAYERCLASS_SOLDIER; } random -= m_ClassProbability[PLAYERCLASS_SCIENTIST]/TotalProbHumanClass; if(random < 0.0f) { return PLAYERCLASS_SCIENTIST; } } if(medicEnabled) { random -= m_ClassProbability[PLAYERCLASS_MEDIC]/TotalProbHumanClass; if(random < 0.0f) { return PLAYERCLASS_MEDIC; } } if(supportEnabled) { random -= m_ClassProbability[PLAYERCLASS_NINJA]/TotalProbHumanClass; if(random < 0.0f) { return PLAYERCLASS_NINJA; } random -= m_ClassProbability[PLAYERCLASS_MERCENARY]/TotalProbHumanClass; if(random < 0.0f) { return PLAYERCLASS_MERCENARY; } random -= m_ClassProbability[PLAYERCLASS_SNIPER]/TotalProbHumanClass; if(random < 0.0f) { return PLAYERCLASS_SNIPER; } } return PLAYERCLASS_ENGINEER; }
void CBuildings::RenderLazer(const struct CNetObj_Building *pCurrent) { // danger line Graphics()->ShaderBegin(SHADER_DEATHRAY, 0.3f); Graphics()->TextureSet(-1); RenderTools()->SelectSprite(-1); Graphics()->QuadsBegin(); Graphics()->SetColor(0, 0, 0, 0.15f); vec2 p1 = vec2(pCurrent->m_X, pCurrent->m_Y+8); //vec2 p2 = vec2(pCurrent->m_X, pCurrent->m_Y+1200); float y = 64.0f; bool Break = false; float s1 = 2.0f; while (y < 1200.0f && !Break) { vec2 p2 = vec2(pCurrent->m_X, pCurrent->m_Y+y); if (Collision()->IntersectLine(p1, p2, 0x0, &p2)) Break = true; float s2 = frandom()*6.0f; IGraphics::CFreeformItem FreeFormItem( p1.x-s1, p1.y, p1.x+s1, p1.y, p1.x-s2, p2.y, p1.x+s2, p2.y); Graphics()->QuadsDrawFreeform(&FreeFormItem, 1); s1 = s2; p1 = p2; y += 64.0f; } /* Collision()->IntersectLine(p1, p2, 0x0, &p2); IGraphics::CFreeformItem FreeFormItem( p1.x-2, p1.y, p1.x+2, p1.y, p1.x-2, p2.y, p1.x+2, p2.y); Graphics()->QuadsDrawFreeform(&FreeFormItem, 1); */ Graphics()->QuadsEnd(); Graphics()->ShaderEnd(); // deathray Graphics()->TextureSet(g_pData->m_aImages[IMAGE_BUILDINGS].m_Id); Graphics()->QuadsBegin(); RenderTools()->SelectSprite(SPRITE_LAZER); Graphics()->SetColor(1, 1, 1, 1); Graphics()->QuadsSetRotation(0); RenderTools()->DrawSprite(pCurrent->m_X, pCurrent->m_Y+15, 64); Graphics()->QuadsEnd(); }
int CGameControllerMOD::ChooseInfectedClass(CPlayer* pPlayer) { float random = frandom(); float TotalProbInfectedClass = m_TotalProbInfectedClass; //Get information about existing infected int nbInfected = 0; bool thereIsAWitch = false; bool thereIsAnUndead = false; for(int i = 0; i < MAX_CLIENTS; i++) { CPlayer *pPlayer = GameServer()->m_apPlayers[i]; if(!pPlayer) continue; if(pPlayer->GetTeam() == TEAM_SPECTATORS) continue; if(pPlayer->IsInfected()) nbInfected++; if(pPlayer->GetClass() == PLAYERCLASS_WITCH) thereIsAWitch = true; if(pPlayer->GetClass() == PLAYERCLASS_UNDEAD) thereIsAnUndead = true; } //Check if hunters are enabled bool hunterEnabled = true; if(Server()->GetClassAvailability(PLAYERCLASS_HUNTER) == 0) { TotalProbInfectedClass -= m_ClassProbability[PLAYERCLASS_HUNTER]; hunterEnabled = false; } //Check if ghost are enabled bool ghostEnabled = true; if(Server()->GetClassAvailability(PLAYERCLASS_GHOST) == 0) { TotalProbInfectedClass -= m_ClassProbability[PLAYERCLASS_GHOST]; ghostEnabled = false; } //Check if spider are enabled bool spiderEnabled = true; if(Server()->GetClassAvailability(PLAYERCLASS_SPIDER) == 0) { TotalProbInfectedClass -= m_ClassProbability[PLAYERCLASS_SPIDER]; spiderEnabled = false; } //Check if boomers are enabled bool boomerEnabled = true; if(Server()->GetClassAvailability(PLAYERCLASS_BOOMER) == 0) { TotalProbInfectedClass -= m_ClassProbability[PLAYERCLASS_BOOMER]; boomerEnabled = false; } //Check if undeads are enabled bool undeadEnabled = true; if(nbInfected < 2 || thereIsAnUndead || (Server()->GetClassAvailability(PLAYERCLASS_UNDEAD) == 0) || !pPlayer->m_WasHumanThisRound) { TotalProbInfectedClass -= m_ClassProbability[PLAYERCLASS_UNDEAD]; undeadEnabled = false; } //Check if witches are enabled bool witchEnabled = true; if(nbInfected < 2 || thereIsAWitch || (Server()->GetClassAvailability(PLAYERCLASS_WITCH) == 0) || !pPlayer->m_WasHumanThisRound) { TotalProbInfectedClass -= m_ClassProbability[PLAYERCLASS_WITCH]; witchEnabled = false; } random *= TotalProbInfectedClass; //Find the random class if(undeadEnabled) { random -= m_ClassProbability[PLAYERCLASS_UNDEAD]; if(random < 0.0f) { GameServer()->SendBroadcast_Language(-1, "The undead is coming!"); GameServer()->CreateSoundGlobal(SOUND_CTF_CAPTURE); return PLAYERCLASS_UNDEAD; } } if(witchEnabled) { random -= m_ClassProbability[PLAYERCLASS_WITCH]; if(random < 0.0f) { GameServer()->SendBroadcast_Language(-1, "The witch is coming!"); GameServer()->CreateSoundGlobal(SOUND_CTF_CAPTURE); return PLAYERCLASS_WITCH; } } if(boomerEnabled) { random -= m_ClassProbability[PLAYERCLASS_BOOMER]; if(random < 0.0f) { return PLAYERCLASS_BOOMER; } } if(ghostEnabled) { random -= m_ClassProbability[PLAYERCLASS_GHOST]; if(random < 0.0f) { return PLAYERCLASS_GHOST; } } if(spiderEnabled) { random -= m_ClassProbability[PLAYERCLASS_SPIDER]; if(random < 0.0f) { return PLAYERCLASS_SPIDER; } } if(hunterEnabled) { random -= m_ClassProbability[PLAYERCLASS_HUNTER]; if(random < 0.0f) { return PLAYERCLASS_HUNTER; } } return PLAYERCLASS_SMOKER; }