DeleteEventCommand::DeleteEventCommand(CQEventWidget1 *pEVentWidget1) { mpEVentWidget1 = pEVentWidget1; mFirstTime = true; mpEventData = new UndoEventData(); std::string sName = mpEVentWidget1->mpEvent->getObjectName(); mpEventData->setName(sName); mType = EVENTDELETE; setEntityType("Event"); setName(sName); CCopasiVector< CEventAssignment >::const_iterator it = mpEVentWidget1->mpEvent->getAssignments().begin(); CCopasiVector< CEventAssignment >::const_iterator end = mpEVentWidget1->mpEvent->getAssignments().end(); for (; it != end; ++it) { const CModelEntity * pEntity = dynamic_cast< CModelEntity * >(CCopasiRootContainer::getKeyFactory()->get((*it)->getTargetKey())); UndoEventAssignmentData *eventAssignData = new UndoEventAssignmentData(); eventAssignData->setName(pEntity->getObjectName()); eventAssignData->setExpression((*it)->getExpression()); mpEventData->getEventAssignmentData()->append(eventAssignData); } mpEventData->setTriggerExpression(mpEVentWidget1->mpEvent->getTriggerExpression()); mpEventData->setDelayExpression(mpEVentWidget1->mpEvent->getDelayExpression()); mpEventData->setPriorityExpression(mpEVentWidget1->mpEvent->getPriorityExpression()); this->setText(deleteEventText(sName)); }
RemoveAllReactionRowsCommand::RemoveAllReactionRowsCommand(CQReactionDM * pReaDM, const QModelIndex&) { mpReactionDM = pReaDM; assert(CCopasiRootContainer::getDatamodelList()->size() > 0); CCopasiDataModel* pDataModel = (*CCopasiRootContainer::getDatamodelList())[0]; assert(pDataModel != NULL); CModel * pModel = pDataModel->getModel(); assert(pModel != NULL); for (int i = 0; i != pReaDM->rowCount() - 1; ++i) { UndoReactionData *data = new UndoReactionData(); CReactionInterface* ri = new CReactionInterface((*CCopasiRootContainer::getDatamodelList())[0]->getModel()); if (pModel->getReactions()[i]) { data->setName(pModel->getReactions()[i]->getObjectName()); ri->initFromReaction(pModel->getReactions()[i]->getKey()); data->setRi(ri); mpReaData.append(data); } } mType = REACTIONREMOVEALL; setEntityType("Reaction"); this->setText(removeAllReactionRowsText()); }
bool NormalWall::initEntity() { if (!Sprite::initWithFile(m_sSource)) return false; getTexture()->setAliasTexParameters(); this->setPosition(this->_initVec + this->getContentSize() / 2); setEntityType(EntityType::kType_Normal); return true; }
insertReactionRowsCommand::insertReactionRowsCommand(int position, int rows, CQReactionDM *pReactionDM, const QModelIndex&): CCopasiUndoCommand() { mpReactionDM = pReactionDM; this->setText(insertRowsText()); mRows = rows; mPosition = position; mType = REACTIONINSERT; setEntityType("Reaction"); }
InsertCompartmentRowsCommand::InsertCompartmentRowsCommand(int position, int rows, CQCompartmentDM *pCompartmentDM, const QModelIndex&): CCopasiUndoCommand() { mpCompartmentDM = pCompartmentDM; mpCompartmentData = new UndoCompartmentData(); this->setText(insertRowsText()); mRows = rows; mPosition = position; firstTime = true; mType = COMPARTMENTINSERT; setEntityType("Compartment"); }
bool HeroSprite::initEntity() { if (!Sprite::initWithFile(m_sSource)) return false; getTexture()->setAliasTexParameters(); this->setPosition(this->_initVec + Point(this->getContentSize().width / 2, 0)); setEntityType(EntityType::kType_Hero); this->setAnchorPoint(Point(0.5, 0)); _offset = 0.0f; _moveUpOrDown = MoveDir_None; _moveLeftOrRight = MoveDir_None; return true; }
RemoveAllGlobalQuantityRowsCommand::RemoveAllGlobalQuantityRowsCommand(CQGlobalQuantityDM * pGlobalQuantityDM, const QModelIndex&) { mpGlobalQuantityDM = pGlobalQuantityDM; assert(CCopasiRootContainer::getDatamodelList()->size() > 0); CCopasiDataModel* pDataModel = (*CCopasiRootContainer::getDatamodelList())[0]; assert(pDataModel != NULL); CModel * pModel = pDataModel->getModel(); assert(pModel != NULL); for (int i = 0; i != pGlobalQuantityDM->rowCount() - 1; ++i) { UndoGlobalQuantityData *data = new UndoGlobalQuantityData(); if (pModel->getModelValues()[i]) { data->setName(pModel->getModelValues()[i]->getObjectName()); data->setStatus(pModel->getModelValues()[i]->getStatus()); if (pModel->getModelValues()[i]->getStatus() != CModelEntity::ASSIGNMENT) { data->setInitialValue(pModel->getModelValues()[i]->getInitialValue()); } // set expression if (pModel->getModelValues()[i]->getStatus() != CModelEntity::FIXED) { data->setExpression(pModel->getModelValues()[i]->getExpression()); } // set initial expression if (pModel->getModelValues()[i]->getStatus() != CModelEntity::ASSIGNMENT) { data->setInitialExpression(pModel->getModelValues()[i]->getInitialExpression()); } setDependentObjects(pModel->getModelValues()[i]->getDeletedObjects()); data->setReactionDependencyObjects(getReactionData()); data->setSpecieDependencyObjects(getSpecieData()); data->setEventDependencyObjects(getEventData()); mpGlobalQuantityData.append(data); } } mType = GLOBALQUANTITYREMOVEALL; setEntityType("Global Quantity"); this->setText(removeAllGlobalQuantityRowsText()); }
bool BrokableWall::init( const ValueMap &valueMap , const ValueMap &gidProperties ) { if (!BaseEntity::initWithMap(valueMap )) return false; //std::string img = Utils::getWallByType(this->m_nType); std::string img = gidProperties.find("source")->second.asString(); m_durability = gidProperties.find("durability")->second.asInt(); if (!BaseEntity::initWithFile(img)) return false; setPositionAndRotation(); this->setPhysicsBody(PhysicsBody::createEdgeBox(this->getContentSize(), PhysicsMaterial(1.0f, 0.4f, 1.0f), 0));//ÃÜ¶È µ¯Á¦ Ħ²ÁÁ¦ setContactTestBitmask(0x0002); setEntityType(Type_Brokable); return true; }
void Entity::createSensorFixture() { setEntityType(Quasi::DynamicType); m_body->SetGravityScale(0); m_sensorFixture = new Fixture(this); m_sensorFixture->setMaterial(new Material(this)); m_sensorFixture->setWidth(width()); m_sensorFixture->setHeight(height()); m_sensorFixture->setShapeItem(this); m_sensorFixture->setWorld(m_world); m_sensorFixture->setEntity(this); m_sensorFixture->setSensor(true); m_sensorFixture->updateFixture(); }
bool YellowWall::init( const ValueMap &valueMap, const ValueMap & gidProperties ) { if (!BaseEntity::initWithMap(valueMap)) return false; //std::string img = Utils::getWallByType(this->m_nType); std::string img = gidProperties.find("source")->second.asString(); if (!BaseEntity::initWithFile(img)) return false; setPositionAndRotation(); std::string type = gidProperties.find("type")->second.asString(); if (type == "target") { this->setPhysicsBody(PhysicsBody::createEdgeBox(this->getContentSize(), PhysicsMaterial(1.0f, 0.2f, 1.0f), 0)); this->setContactTestBitmask(0x0001); setEntityType(Type_Yellow); } else if (type == "flag") { this->playFlagAnimate(); this->setPhysicsBody(PhysicsBody::createEdgeBox(this->getContentSize())); this->setContactTestBitmask(0x0002); setEntityType(Type_Flag); } return true; }
RemoveEventRowsCommand::RemoveEventRowsCommand(QModelIndexList rows, CQEventDM * pEventDM, const QModelIndex&) { mpEventDM = pEventDM; mRows = rows; mFirstTime = true; assert(CCopasiRootContainer::getDatamodelList()->size() > 0); CCopasiDataModel* pDataModel = (*CCopasiRootContainer::getDatamodelList())[0]; assert(pDataModel != NULL); CModel * pModel = pDataModel->getModel(); assert(pModel != NULL); QModelIndexList::const_iterator i; for (i = rows.begin(); i != rows.end(); ++i) { UndoEventData *data = new UndoEventData(); if (!pEventDM->isDefaultRow(*i) && pModel->getEvents()[(*i).row()]) { data->setName(pModel->getEvents()[(*i).row()]->getObjectName()); data->setPriorityExpression(pModel->getEvents()[(*i).row()]->getPriorityExpression()); data->setDelayExpression(pModel->getEvents()[(*i).row()]->getDelayExpression()); data->setTriggerExpression(pModel->getEvents()[(*i).row()]->getTriggerExpression()); CCopasiVector< CEventAssignment >::const_iterator it = pModel->getEvents()[(*i).row()]->getAssignments().begin(); CCopasiVector< CEventAssignment >::const_iterator end = pModel->getEvents()[(*i).row()]->getAssignments().end(); for (; it != end; ++it) { const CModelEntity * pEntity = dynamic_cast< CModelEntity * >(CCopasiRootContainer::getKeyFactory()->get((*it)->getTargetKey())); UndoEventAssignmentData *eventAssignData = new UndoEventAssignmentData(); eventAssignData->setName(pEntity->getObjectName()); eventAssignData->setExpression((*it)->getExpression()); data->getEventAssignmentData()->append(eventAssignData); } mpEventData.append(data); } } this->setText(removeEventRowsText()); mType = EVENTREMOVE; setEntityType("Event"); }
DeleteSpecieCommand::DeleteSpecieCommand(CQSpeciesDetail *pSpecieDetail) { mpSpecieDetail = pSpecieDetail; mFirstTime = true; mpSpecieData = new UndoSpecieData(); mpReactionData = new QList <UndoReactionData*>(); mpGlobalQuantityData = new QList <UndoGlobalQuantityData*>(); mpEventData = new QList <UndoEventData*>(); std::string sName = mpSpecieDetail->mpMetab->getObjectName(); mpSpecieData->setName(sName); mpSpecieData->setStatus(mpSpecieDetail->mpMetab->getStatus()); if (mpSpecieDetail->mpMetab->getStatus() != CModelEntity::ASSIGNMENT) { mpSpecieData->setIConc(mpSpecieDetail->mpMetab->getInitialConcentration()); } if (mpSpecieDetail->mpMetab->getStatus() == CModelEntity::ASSIGNMENT || mpSpecieDetail->mpMetab->getStatus() == CModelEntity::ODE) { mpSpecieData->setExpression(mpSpecieDetail->mpMetab->getExpression()); } // set initial expression if (mpSpecieDetail->mpMetab->getStatus() != CModelEntity::ASSIGNMENT) { mpSpecieData->setInitialExpression(mpSpecieDetail->mpMetab->getInitialExpression()); } //store to be deleted data //QList<UndoReactionData*> *dependencyObjects = new QList<UndoReactionData*>(); setDependentObjects(mpSpecieDetail->mpMetab->getDeletedObjects()); mpSpecieData->setReactionDependencyObjects(getReactionData()); mpSpecieData->setGlobalQuantityDependencyObjects(getGlobalQuantityData()); mpSpecieData->setEventDependencyObjects(getEventData()); mType = SPECIEDELETE; setEntityType("Species"); setName(sName); this->setText(deleteSpecieText(sName)); }
RemoveCompartmentRowsCommand::RemoveCompartmentRowsCommand(QModelIndexList rows, CQCompartmentDM * pCompartmentDM, const QModelIndex&) { mpCompartmentDM = pCompartmentDM; mRows = rows; mFirstTime = true; assert(CCopasiRootContainer::getDatamodelList()->size() > 0); CCopasiDataModel* pDataModel = (*CCopasiRootContainer::getDatamodelList())[0]; assert(pDataModel != NULL); CModel * pModel = pDataModel->getModel(); assert(pModel != NULL); QModelIndexList::const_iterator i; for (i = rows.begin(); i != rows.end(); ++i) { UndoCompartmentData *data = new UndoCompartmentData(); if (!pCompartmentDM->isDefaultRow(*i) && pModel->getCompartments()[(*i).row()]) { mpSpecieData = new QList <UndoSpecieData*>(); mpReactionData = new QList <UndoReactionData*>(); mpGlobalQuantityData = new QList <UndoGlobalQuantityData*>(); mpEventData = new QList <UndoEventData*>(); data->setName(pModel->getCompartments()[(*i).row()]->getObjectName()); data->setStatus(pModel->getCompartments()[(*i).row()]->getStatus()); data->setInitialValue(pModel->getCompartments()[(*i).row()]->getInitialValue()); setDependentObjects(pModel->getCompartments()[(*i).row()]->getDeletedObjects()); data->setReactionDependencyObjects(getReactionData()); data->setSpecieDependencyObjects(getSpecieData()); data->setGlobalQuantityDependencyObjects(getGlobalQuantityData()); data->setEventDependencyObjects(getEventData()); mpCompartmentData.append(data); } } this->setText(removeCompartmentRowsText()); mType = COMPARTMENTREMOVE; setEntityType("Compartment"); }
DeleteGlobalQuantityCommand::DeleteGlobalQuantityCommand(CQModelValue *pModelValue) { mpModelValue = pModelValue; mFirstTime = true; mpGlobalQuantityData = new UndoGlobalQuantityData(); std::string sName = mpModelValue->mpModelValue->getObjectName(); mpGlobalQuantityData->setName(sName); mpGlobalQuantityData->setStatus(mpModelValue->mpModelValue->getStatus()); if (mpModelValue->mpModelValue->getStatus() != CModelEntity::ASSIGNMENT) { mpGlobalQuantityData->setInitialValue(mpModelValue->mpModelValue->getInitialValue()); } if (mpModelValue->mpModelValue->getStatus() != CModelEntity::FIXED) { mpGlobalQuantityData->setExpression(mpModelValue->mpModelValue->getExpression()); } // set initial expression if (mpModelValue->mpModelValue->getStatus() != CModelEntity::ASSIGNMENT) { mpGlobalQuantityData->setInitialExpression(mpModelValue->mpModelValue->getInitialExpression()); } //store to be deleted data setDependentObjects(mpModelValue->mpModelValue->getDeletedObjects()); mpGlobalQuantityData->setReactionDependencyObjects(getReactionData()); mpGlobalQuantityData->setSpecieDependencyObjects(getSpecieData()); mpGlobalQuantityData->setEventDependencyObjects(getEventData()); mType = GLOBALQUANTITYDELETE; setEntityType("Global Quantity"); this->setText(deleteGlobalQuantityText(sName)); setName(sName); }
EventDataChangeCommand::EventDataChangeCommand(QModelIndex index, const QVariant value, int role, CQEventDM *pEventDM) { // stores the data mOld = index.data(Qt::DisplayRole); mNew = value; mpEventDM = pEventDM; mIndex = index; mRole = role; //mPathIndex = pathFromIndex(index); this->setText(eventDataChangeText()); //set the data for UNDO history assert(CCopasiRootContainer::getDatamodelList()->size() > 0); CCopasiDataModel* pDataModel = (*CCopasiRootContainer::getDatamodelList())[0]; assert(pDataModel != NULL); CModel * pModel = pDataModel->getModel(); CEvent *pEvent = pModel->getEvents()[index.row()]; mType = EVENTDATACHANGE; setEntityType("Event"); setAction("Change"); setName(pEvent->getObjectName()); setOldValue(TO_UTF8(mOld.toString())); setNewValue(TO_UTF8(mNew.toString())); switch (index.column()) { case 0: setProperty(""); break; case 1: setProperty("Name"); break; } }
//------------------------------------------------------------------------------ // Set entity type enumerations //------------------------------------------------------------------------------ bool Ntm::setSlotEntityType(const base::List* const msg) { bool ok = false; if (msg != nullptr) { int values[7]; int n = msg->getNumberList(values, 7); if (n >= 4) { // Need at least Kind, domain, country & category ok = true; // First, assume they're valid unsigned char k = 0; // Kind if (values[0] >= 0x0 && values[0] <= 0xff) { k = static_cast<unsigned char>(values[0]); } else { std::cerr << "Ntm::setSlotEntityType: Invalid kind: [ 0 .. 255 ]" << std::endl; ok = false; } unsigned char d = 0; // Domain if (values[1] >= 0x0 && values[1] <= 0xff) { d = static_cast<unsigned char>(values[1]); } else { std::cerr << "Ntm::setSlotEntityType: Invalid domain: [ 0 .. 255 ]" << std::endl; ok = false; } unsigned short cc = 0; // Country code if (values[2] >= 0x0 && values[2] <= 0xffff) { cc = (unsigned char) values[2]; } else { std::cerr << "Ntm::setSlotEntityType: Invalid country: [ 0 .. 65535 ]" << std::endl; ok = false; } unsigned char c = 0; // Category if (values[3] >= 0x0 && values[3] <= 0xff) { c = static_cast<unsigned char>(values[3]); } else { std::cerr << "Ntm::setSlotEntityType: Invalid category: [ 0 .. 255 ]" << std::endl; ok = false; } // Ok so far, now for the optional stuff ... unsigned char sc = 0; // Subcategory unsigned char sp = 0; // Specific unsigned char ex = 0; // Extra if (n >= 5) { if (values[4] >= 0x0 && values[4] <= 0xff) { sc = static_cast<unsigned char>(values[4]); } else { std::cerr << "Ntm::setSlotEntityType: Invalid subcategory: [ 0 .. 255 ]" << std::endl; ok = false; } } if (n >= 6) { if (values[5] >= 0x0 && values[5] <= 0xff) { sp = static_cast<unsigned char>(values[5]); } else { std::cerr << "Ntm::setSlotEntityType: Invalid specific: [ 0 .. 255 ]" << std::endl; ok = false; } } if (n >= 7) { if (values[6] >= 0x0 && values[6] <= 0xff) { ex = static_cast<unsigned char>(values[6]); } else { std::cerr << "Ntm::setSlotEntityType: Invalid extra: [ 0 .. 255 ]" << std::endl; ok = false; } } // If all's well, then set the entity type if (ok) { ok = setEntityType(k, d, cc, c, sc, sp, ex); } } else { std::cerr << "Ntm::setSlotEntityType: Invalid entity type vector: need at least [ kind domain country category ]" << std::endl; } } return ok; }
//------------------------------------------------------------------------------ // entityState2Nib() -- (Input support) // Transfers data from the incoming entity attributes to the basic // NIB class variables. //------------------------------------------------------------------------------ void Nib::entityState2Nib() { if (isAttributeUpdateRequired(NetIO::ENTITY_IDENTIFIER_AI)) { setPlayerID(baseEntity->entityIdentifier.entityNumber); setSiteID(baseEntity->entityIdentifier.federateIdentifier.siteID); setApplicationID(baseEntity->entityIdentifier.federateIdentifier.applicationID); setAttributeUpdateRequiredFlag(NetIO::ENTITY_IDENTIFIER_AI, false); haveEntityIdFlg = true; } if (isAttributeUpdateRequired(NetIO::ENTITY_TYPE_AI)) { setEntityType( baseEntity->entityType.entityKind, baseEntity->entityType.domain, baseEntity->entityType.countryCode, baseEntity->entityType.category, baseEntity->entityType.subcategory, baseEntity->entityType.specific, baseEntity->entityType.extra ); setAttributeUpdateRequiredFlag(NetIO::ENTITY_TYPE_AI, false); haveEntityTypeFlg = true; } if (isAttributeUpdateRequired(NetIO::SPATIAL_AI)) { // NIB's base entity structures //SpatialStruct* spatial = &(baseEntity->spatial); SpatialRVStruct* spatialRvw = &(baseEntity->spatialRvw); // Set the freeze flag freeze(spatialRvw->isFrozen != 0); // Get the geocentric position, velocity and acceleration osg::Vec3d geocPos; geocPos[base::Nav::IX] = spatialRvw->worldLocation.x; geocPos[base::Nav::IY] = spatialRvw->worldLocation.y; geocPos[base::Nav::IZ] = spatialRvw->worldLocation.z; osg::Vec3d geocVel; geocVel[base::Nav::IX] = spatialRvw->velocityVector.xVelocity; geocVel[base::Nav::IY] = spatialRvw->velocityVector.yVelocity; geocVel[base::Nav::IZ] = spatialRvw->velocityVector.zVelocity; osg::Vec3d geocAcc; geocAcc[base::Nav::IX] = spatialRvw->accelerationVector.xAcceleration; geocAcc[base::Nav::IY] = spatialRvw->accelerationVector.yAcceleration; geocAcc[base::Nav::IZ] = spatialRvw->accelerationVector.zAcceleration; // Get orientation orientation and rates osg::Vec3d geocAngles; geocAngles[base::Nav::IPHI] = spatialRvw->orientation.phi; geocAngles[base::Nav::ITHETA] = spatialRvw->orientation.theta; geocAngles[base::Nav::IPSI] = spatialRvw->orientation.psi; osg::Vec3d arates(0.0, 0.0, 0.0); // (re)initialize the dead reckoning function double diffTime(0.0); resetDeadReckoning( RVW_DRM, geocPos, geocVel, geocAcc, geocAngles, arates, diffTime); haveWorldLocationFlg = true; haveOrientationFlg = true; setAttributeUpdateRequiredFlag(NetIO::SPATIAL_AI, false); } // PhysicalEntity pointer PhysicalEntity* physicalEntity = dynamic_cast<PhysicalEntity*>(baseEntity); if (physicalEntity != nullptr) { if (isAttributeUpdateRequired(NetIO::FORCE_IDENTIFIER_AI)) { // Side: When mapping Force ID to Player Side ... if (physicalEntity->forceIdentifier == FRIENDLY) { // Friendly's are blue, ... setSide(simulation::Player::BLUE); } else if (physicalEntity->forceIdentifier == OPPOSING) { // opposing side is red, ... setSide(simulation::Player::RED); } else if (physicalEntity->forceIdentifier == NEUTRAL) { // Neutrals are white, ... setSide(simulation::Player::WHITE); } else { // and everyone else is gray. setSide(simulation::Player::GRAY); } setAttributeUpdateRequiredFlag(NetIO::FORCE_IDENTIFIER_AI, false); } } setMode(simulation::Player::ACTIVE); setTimeExec( (double) getNetIO()->getCurrentTime() ); }
SchoolFish::SchoolFish() : FlockEntity() { burstDelay = 0; naijaReaction = "smile"; rippleTimer = 0; oldFlockID = -1; respawnTimer = 0; dodgeAbility = (rand()%900)/1000.0 + 0.1; float randScale = float(rand()%200)/1000.0; scale = Vector(0.6-randScale, 0.6-randScale); /* float randColor = float(rand()%250)/1000.0; color = Vector(1-randColor, 1-randColor, 1-randColor); */ //color.interpolateTo(Vector(0.5, 0.5, 0.5), 2, -1, 1); color.path.addPathNode(Vector(1,1,1), 0); color.path.addPathNode(Vector(1,1,1), 0.5); color.path.addPathNode(Vector(0.8, 0.8, 0.8), 0.7); color.path.addPathNode(Vector(1,1,1), 1.0); color.startPath(2); color.loopType = -1; color.update((rand()%1000)/1000.0); flipDelay = 0; swimSound = "SchoolFishSwim"; soundDelay = (rand()%300)/100.0; range = 0; setEntityType(ET_ENEMY); canBeTargetedByAvatar = true; health = maxHealth = 1; //scale = Vector(0.5, 0.5); avoidTime=0; vel = Vector(-minUrgency, 0); setTexture("flock-0001"); flockType = FLOCK_FISH; //updateCull = -1; updateCull = 4000; collideRadius = 20; //2 32 0.1 0.1 -0.03 0 4 0 setSegs(8, 2, 0.1, 0.9, 0, -0.03, 8, 0); /* setDamageTarget(DT_AVATAR_SPORECHILD, false); setDamageTarget(DT_AVATAR_ENERGYBLAST, false); */ //setAllDamageTargets(true); setDamageTarget(DT_AVATAR_LIZAP, false); /* setDamageTarget(DT_AVATAR_ENERGYBLAST, false); setDamageTarget(DT_AVATAR_SHOCK, false); */ //setDamageTarget(DT_AVATAR_BITE, true); // updateCull = 10248; targetPriority = -1; setEatType(EAT_FILE, "SchoolFish"); this->deathSound = ""; this->targetPriority = -1; setDamageTarget(DT_AVATAR_PET, false); }
void SchoolFish::onUpdate(float dt) { BBGE_PROF(SchoolFish_onUpdate); /* Quad::onUpdate(dt); return; */ /* if (dsq->continuity.form == FORM_BEAST) this->activationType = ACT_CLICK; else this->activationType = ACT_NONE; */ /* if (burstDelay == 0) { maxSpeedLerp = 2; Vector v = getNormal(); vel = 0; v *= -5000; vel += v; //float t = (100 + rand()%100)/100.0; float t = 2; maxSpeedLerp.interpolateTo(1, t); burstDelay = 10;// + (rand()%100)/100.0; //rotateToVec(v, 0, 90); //rotation.interpolateTo(0, 1); if (v.x > 0 && !isfh()) { flipHorizontal(); flipDelay = 0.5; } if (v.x < 0 && isfh()) { flipHorizontal(); flipDelay = 0.5; } } else */ { burstDelay -= dt; if (burstDelay < 0) { burstDelay = 0; } } if (stickToNaijasHead && alpha.x < 0.1) stickToNaijasHead = false; if (this->layer < LR_ENTITIES) { //debugLog("background fish!"); /* setDamageTarget(DT_AVATAR_SHOCK, false); setDamageTarget(DT_AVATAR_BITE, false); setDamageTarget(DT_AVATAR_VOMIT, false); setDamageTarget(DT_AVATAR_ENERGYBLAST, false); */ setEntityType(ET_NEUTRAL); collideRadius = 0; } if (getState() == STATE_DEAD) { FlockEntity::onUpdate(dt); respawnTimer -= dt; if (!(dsq->game->avatar->position - this->position).isLength2DIn(2000)) { if (respawnTimer < 0) { respawnTimer = 0; perform(STATE_IDLE); } } } else { /* if (layer == LR_ENTITIES || layer == LR_ENTITIES2) { rippleTimer -= dt; if (rippleTimer < 0) { if (core->afterEffectManager) core->afterEffectManager->addEffect(new ShockEffect(Vector(core->width/2, core->height/2),position,0.04,0.06,15,0.2f)); rippleTimer = 0.5; } } */ FlockEntity::onUpdate(dt); if (dsq->game->isValidTarget(this, 0)) dsq->game->handleShotCollisions(this); /* soundDelay -= dt; if (soundDelay <= 0) { //sound(swimSound, 1000 + rand()%100); soundDelay = 4+(rand()%50)/100.0; } */ /* 1. if distance_to(closest_boid) <= too_close then set direction away from closest_boid 2. speed_of_neighbors := average(speed(x), for all x where distance_to(x) <= neighborhood_size) direction_of_neighbors := avg(direction(x), for all x where distance_to(x) <= neighborhood_size) if speed < speed_of_neighbors then increase speed if speed > speed_of_neighbors then decrease speed turn towards direction_of_neighbors 3. position_of_neighbors := avg(position(x), for all x where distance_to(x) <= neighborhood_size) turn towards position_of_neighbors */ float seperation = 1; float alignment = 0; float cohesion = 0.75; /* FlockPiece flock; getFlockInRange(160, &flock); */ // if flock in 160 ? if (true) { VectorSet newDirection; if (avoidTime>0) { avoidTime -= dt; if (avoidTime<0) avoidTime=0; } Vector dir = getFlockHeading(); Vector accumulator; applyCohesion(accumulator); applyAlignment(accumulator, dir); // alignment applySeparation(accumulator); applyAvoidance(accumulator); updateVelocity(accumulator); /* if (dsq->game->isValidTarget(this, 0)) doSpellAvoidance(dt, 96, dodgeAbility); */ Vector lastPosition = position; Vector newPosition = position + (vel*velocityScale*dt) + vel2*dt; position = newPosition; if (dsq->game->isObstructed(position)) { position = lastPosition; /* position = Vector(newPosition.x, lastPosition.y); if (dsq->game->isObstructed(position)) { position = Vector(lastPosition.x, newPosition.y); if (dsq->game->isObstructed(position)) { position = lastPosition; } } */ } //updateCurrents(dt); updateVel2(dt); /* if (flipDelay > 0) { flipDelay -= dt; if (flipDelay < 0) { flipDelay = 0; } } */ flipDelay = 0; //dir.normalize2D(); if (flipDelay <= 0) { const float amt = 0; /* if (fabs(dir.x) > fabs(dir.y)) { if (dir.x > amt && !isfh()) { flipHorizontal(); flipDelay = 0.5; } if (dir.x < -amt && isfh()) { flipHorizontal(); flipDelay = 0.5; } } */ if (vel.x > amt && !isfh()) { flipHorizontal(); } if (vel.x < -amt && isfh()) { flipHorizontal(); } } //rotateToVec(accumulator, 5, 90); float angle = atan(dir.y/dir.x); angle = ((angle*180)/3.14); if (angle > 45) angle = 45; if (angle < -45) angle = -45; rotation = Vector(0,0,angle); //rotation.interpolateTo(Vector(0, 0, angle), 0); } } }
PatchMesh::PatchMesh() { setEntityType(TypedEntity::TPatchMesh); m_numQuads = 0; }