//todo: rewrite this to not need direct access to trap members. bool ZoneDatabase::LoadTraps(const char* zonename, int16 version) { std::string query = StringFormat("SELECT id, x, y, z, effect, effectvalue, effectvalue2, skill, " "maxzdiff, radius, chance, message, respawn_time, respawn_var, level " "FROM traps WHERE zone='%s' AND version=%u", zonename, version); auto results = QueryDatabase(query); if (!results.Success()) { return false; } for (auto row = results.begin(); row != results.end(); ++row) { Trap* trap = new Trap(); trap->trap_id = atoi(row[0]); trap->m_Position = glm::vec3(atof(row[1]), atof(row[2]), atof(row[3])); trap->effect = atoi(row[4]); trap->effectvalue = atoi(row[5]); trap->effectvalue2 = atoi(row[6]); trap->skill = atoi(row[7]); trap->maxzdiff = atof(row[8]); trap->radius = atof(row[9]); trap->chance = atoi(row[10]); trap->message = row[11]; trap->respawn_time = atoi(row[12]); trap->respawn_var = atoi(row[13]); trap->level = atoi(row[14]); entity_list.AddTrap(trap); trap->CreateHiddenTrigger(); } return true; }
void InGameState::checkAndResolveDynamicCollision() { Circle avatarBC(m_avatar->getPostion(), m_avatar->getRadius() / 4); for(unsigned int index = 0; index < m_monsters.size(); index++) { Monster* monster = m_monsters.at(index); if (!monster->isDead()) { Circle monsterBC(monster->getPostion(),monster->getRadius() / 4); if(avatarBC.collidesWith(monsterBC)) { if (m_stats->isSuperMode()) { monster->kill(); m_stats->addScore(MONSTER_KILLED); } else m_avatar->kill(); } } for (unsigned int bomb = 0; bomb < m_bombs.size(); bomb++) { if (m_bombs[bomb]->isColliding(monster) && !monster->isDead()) { monster->kill(); m_stats->addScore(MONSTER_KILLED); } } } for (unsigned int bomb = 0; bomb < m_bombs.size(); bomb++) { if (m_bombs[bomb]->isColliding(m_avatar)) { m_avatar->kill(); } } if (!m_avatar->inAir()) { for(unsigned int index = 0; index < m_traps.size(); index++) { Trap* trap = m_traps.at(index); Circle trapBC(trap->getPostion(),trap->getRadius() / 8); if(avatarBC.collidesWith(trapBC)) { m_avatar->kill(); } } } }
void EntityList::ClearTrapPointers() { auto it = trap_list.begin(); while (it != trap_list.end()) { Trap* cur = it->second; if (cur->IsTrap()) { cur->DestroyHiddenTrigger(); } ++it; } }
void EntityList::UpdateAllTraps(bool respawn, bool repopnow) { auto it = trap_list.begin(); while (it != trap_list.end()) { Trap* cur = it->second; if (cur->IsTrap()) { cur->UpdateTrap(respawn, repopnow); } ++it; } Log.Out(Logs::General, Logs::Traps, "All traps updated."); }
bool EntityList::IsTrapGroupSpawned(uint32 trap_id, uint8 group) { auto it = trap_list.begin(); while (it != trap_list.end()) { Trap* cur = it->second; if (cur->IsTrap() && cur->group == group && cur->trap_id != trap_id) { return true; } ++it; } return false; }
bool ZoneDatabase::LoadTraps(const char* zonename, int16 version) { std::string query = StringFormat("SELECT id, x, y, z, effect, effectvalue, effectvalue2, skill, " "maxzdiff, radius, chance, message, respawn_time, respawn_var, level, " "`group`, triggered_number, despawn_when_triggered FROM traps WHERE zone='%s' AND version=%u", zonename, version); auto results = QueryDatabase(query); if (!results.Success()) { return false; } for (auto row = results.begin(); row != results.end(); ++row) { uint32 tid = atoi(row[0]); uint8 grp = atoi(row[15]); if(grp > 0) { // If a member of our group is already spawned skip loading this trap. if(entity_list.IsTrapGroupSpawned(tid, grp)) { continue; } } Trap* trap = new Trap(); trap->trap_id = tid; trap->db_id = tid; trap->m_Position = glm::vec3(atof(row[1]), atof(row[2]), atof(row[3])); trap->effect = atoi(row[4]); trap->effectvalue = atoi(row[5]); trap->effectvalue2 = atoi(row[6]); trap->skill = atoi(row[7]); trap->maxzdiff = atof(row[8]); trap->radius = atof(row[9]); trap->chance = atoi(row[10]); trap->message = row[11]; trap->respawn_time = atoi(row[12]); trap->respawn_var = atoi(row[13]); trap->level = atoi(row[14]); trap->group = grp; trap->triggered_number = atoi(row[16]); trap->despawn_when_triggered = atoi(row[17]); entity_list.AddTrap(trap); trap->CreateHiddenTrigger(); Log.Out(Logs::General, Logs::Traps, "Trap %d successfully loaded.", trap->trap_id); } return true; }
void draw() { // clear the color and depth in the frame buffer glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // use the loaded shader program // Don't change unless you know what you are doing glUseProgram (programID); // Eye - Location of camera. Don't change unless you are sure!! // glm::vec3 eye ( 5*cos(camera_rotation_angle*M_PI/180.0f), 0, 5*sin(camera_rotation_angle*M_PI/180.0f) ); // Target - Where is the camera looking at. Don't change unless you are sure!! // glm::vec3 target (0, 0, 0); // Up - Up vector defines tilt of camera. Don't change unless you are sure!! // glm::vec3 up (0, 1, 0); // Compute Camera matrix (view) // Matrices.view = glm::lookAt( eye, target, up ); // Rotating Camera for 3D // Don't change unless you are sure!! Matrices.view = glm::lookAt(glm::vec3(0, 0, 3), glm::vec3(0, 0, 0), glm::vec3(0, 1, 0)); // Fixed camera for 2D (ortho) in XY plane // Compute ViewProject matrix as view/camera might not be changed for this frame (basic scenario) // Don't change unless you are sure!! glm::mat4 VP = Matrices.projection * Matrices.view; // Send our transformation to the currently bound shader, in the "MVP" uniform // For each model you render, since the MVP will be different (at least the M part) // Don't change unless you are sure!! glm::mat4 MVP; // MVP = Projection * View * Model // Scene render trap1.draw(VP); ball1.draw(VP); flr.draw(VP); trampoline1.draw(VP); trampoline2.draw(VP); if(level==1) { trampoline3.draw(VP); trampoline4.draw(VP); trap2.draw(VP); } for(int i=0;i<10;i++) if(!enemy[level][i].hitflag) enemy[level][i].draw(VP); }
void EntityList::GetTrapInfo(Client* client) { uint8 count = 0; auto it = trap_list.begin(); while (it != trap_list.end()) { Trap* cur = it->second; if (cur->IsTrap()) { bool isset = (cur->chkarea_timer.Enabled() && !cur->reset_timer.Enabled()); client->Message(CC_Default, " Trap: (%d) found at %0.2f,%0.2f,%0.2f. Times Triggered: %d Is Active: %d Group: %d Message: %s", cur->trap_id, cur->m_Position.x, cur->m_Position.y, cur->m_Position.z, cur->times_triggered, isset, cur->group, cur->message.c_str()); ++count; } ++it; } client->Message(CC_Default, "%d traps found.", count); }
//checks for trap collisions void PlayerActor::doTrapCollision(float* nextX, float* nextY) { //loop through the traps and check collision vector<Trap*>* traps = dxMan->GetTraps(); for(vector<Trap*>::iterator iter = traps->begin(); iter != traps->end(); ++iter) { Trap* trapTest = *iter; bool hit = TestTrapCollision(trapTest, nextX, nextY); if (hit) { //check if trap is dangerous at this time if(trapTest->trapWillKill() || trapTest->trapType == 3) { trapTest->OnPlayerCollide(this); } } } }
//todo: rewrite this to not need direct access to trap members. bool ZoneDatabase::LoadTraps(const char* zonename, int16 version) { char errbuf[MYSQL_ERRMSG_SIZE]; char *query = 0; MYSQL_RES *result; MYSQL_ROW row; // int char_num = 0; unsigned long* lengths; if (RunQuery(query, MakeAnyLenString(&query, "SELECT id,x,y,z,effect,effectvalue,effectvalue2,skill,maxzdiff,radius,chance,message,respawn_time,respawn_var,level FROM traps WHERE zone='%s' AND version=%u", zonename, version), errbuf, &result)) { safe_delete_array(query); while ((row = mysql_fetch_row(result))) { lengths = mysql_fetch_lengths(result); Trap* trap = new Trap(); trap->trap_id = atoi(row[0]); trap->x = atof(row[1]); trap->y = atof(row[2]); trap->z = atof(row[3]); trap->effect = atoi(row[4]); trap->effectvalue = atoi(row[5]); trap->effectvalue2 = atoi(row[6]); trap->skill = atoi(row[7]); trap->maxzdiff = atof(row[8]); trap->radius = atof(row[9]); trap->chance = atoi(row[10]); trap->message = row[11]; trap->respawn_time = atoi(row[12]); trap->respawn_var = atoi(row[13]); trap->level = atoi(row[14]); entity_list.AddTrap(trap); trap->CreateHiddenTrigger(); } mysql_free_result(result); } else { LogFile->write(EQEMuLog::Error, "Error in LoadTraps query '%s': %s", query, errbuf); safe_delete_array(query); return false; } return true; }
void tick_elements() { if(ball1.onwater()) { if(ball1.speedx>0) ball1.speedx=waterspeed; else ball1.speedx=-waterspeed; } ball1.tick(); ball1.checkheight(); if(level==1) { if(enemy[1][9].position.x >= 3.8) for(int i=0;i<10;i++) enemy[1][i].speedx=-0.01; if(enemy[1][6].position.x <= -3.8) for(int i=0;i<10;i++) enemy[1][i].speedx=0.01; for(int i=0;i<10;i++) enemy[1][i].tick(); } if(detect_collision(ball1.bounding_box(),trap1.bounding_box()) ||( detect_collision(ball1.bounding_box(),trap2.bounding_box()) && level==1)) { if(life==0) { quit(window); } else { ball1.reset_speedy(); ball1.position.y+=0.4; ball1.speedy=0.04; life--; disp_score(); } } }
uint16 Map::RunOver(uint8 x, uint8 y, bool memonly, Creature *c, int32 dangerFactor, bool Incor, bool Meld) { if (!Incor && SolidAt(x,y)) { if (Meld) { int i = TTER(PTerrainAt(x,y,c))->Material; if (i == MAT_GRANITE || i == MAT_MAGMA || i == MAT_QUARTZ || i == MAT_GEMSTONE || i == MAT_MINERAL) ; // we can walk here else return 0; } else return 0; } if (memonly && !At(x,y).Memory) return 0; if (At(x,y).Contents) { Creature *ca; Trap *tr; Door *dr; for (ca=FCreatureAt(x,y);ca;ca=NCreatureAt(x,y)) if (ca && c->Percieves(ca) && ca->isHostileTo(c)) return 0; for (tr=FTrapAt(x,y);tr;tr=NTrapAt(x,y)) { if (tr->TrapFlags & TS_FOUND) if (!(tr->TrapFlags & TS_DISARMED)) { if (dangerFactor & DF_IGNORE_TRAPS) return (sizeX * 3) + (tr->TrapLevel() * 10); else return 0; } } for (dr=FDoorAt(x,y);dr;dr=NDoorAt(x,y)) if (!(dr->DoorFlags & DF_OPEN)) return 0; } rID stickyID = StickyAt(x,y); if (stickyID && !c->HasStati(STUCK) && !c->HasMFlag(M_AMORPH) && !c->isAerial() && c->onPlane() == PHASE_MATERIAL && c->ResistLevel(AD_STUK) != -1 && !c->HasAbility(CA_WOODLAND_STRIDE)) { if (dangerFactor & DF_IGNORE_TERRAIN) return (sizeX * 3); else return 0; } Feature * f; for (f=FFeatureAt(x,y);f;f=NFeatureAt(x,y)) if (TFEAT(f->fID)->PEvent(EV_MON_CONSIDER,c,f,f->fID) == ABORT) { if (dangerFactor & DF_IGNORE_TERRAIN) return (sizeX * 3); else return 0; } if (At(x,y).Terrain) { rID t = PTerrainAt(x,y,c); if (TTER(t)->HasFlag(TF_WARN)) { if (TTER(t)->PEvent(EV_MON_CONSIDER,c,t) == ABORT) { if (dangerFactor & DF_IGNORE_TERRAIN) return (sizeX * 3); else return 0; } } if (TTER(t)->MoveMod) return 4; else return 2; } return 2; }