本文整理汇总了C++中NPC类的典型用法代码示例。如果您正苦于以下问题:C++ NPC类的具体用法?C++ NPC怎么用?C++ NPC使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NPC类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: FindControllingNPC
void Stampede::Activate()
{
AnimationSystem::GetInstance()->ResetAnimation(action);
trail = GameplayState::GetInstance()->CreateEmitter("radicorn_mane");
duration = 3.0f;
firstHit = false;
SGD::AudioManager::GetInstance()->PlayAudio(GameplayState::GetInstance()->stampede_sfx, true);
damage = owner->GetStat(StatType::accuracy) + 35;
SGD::Point spawnPoint;
if (fromTheLeft)
{
spawnPoint.y = owner->GetPosition().y - 900;
m_vtVelocity.y = 1200;
}
else
{
spawnPoint.y = owner->GetPosition().y + 900;
m_vtVelocity.y = -1200;
trail->SetRotation(PI);
}
NPC* temp = FindControllingNPC(owner);
spawnPoint.x = temp->GetTarget()->GetPosition().x;
this->SetPosition(spawnPoint);
}
示例2: NPC
bool World::createDynamicNPC(const std::string &name, TYPE_OF_RACE_ID type, const position &pos, /*CCharacter::face_to dir,*/ Character::sex_type sex, const std::string &scriptname) {
try {
try {
NPC *newNPC = new NPC(DYNNPC_BASE, name, type, pos, (Character::face_to)4/*dir*/, false, sex, {});
// add npc to npc list
Npc.insert(newNPC);
try {
// try to load the script
std::shared_ptr<LuaNPCScript> script(new LuaNPCScript(scriptname, newNPC));
newNPC->setScript(script);
} catch (ScriptException &e) {
Logger::error(LogFacility::Script) << "World::createDynamicNPC: Error while loading dynamic NPC script: " << scriptname << ": " << e.what() << Log::end;
}
} catch (FieldNotFound &) {
Logger::error(LogFacility::Script) << "World::createDynamicNPC: No space available for dynamic NPC: " << name << " near " << pos << Log::end;
}
return true;
} catch (...) {
Logger::error(LogFacility::Script) << "World::createDynamicNPC: Unknown error while loading dynamic NPC: " << name << Log::end;
return false;
}
}
示例3: iterator
void EntityList::AETaunt(Client* taunter, float range) {
LinkedListIterator<NPC*> iterator(npc_list);
if(range == 0) {
range = 100; //arbitrary default...
}
range = range * range;
iterator.Reset();
while(iterator.MoreElements())
{
NPC * them = iterator.GetData();
float zdiff = taunter->GetZ() - them->GetZ();
if (zdiff < 0)
zdiff *= -1;
if (zdiff < 10
&& taunter->IsAttackAllowed(them)
&& taunter->DistNoRootNoZ(*them) <= range) {
if (taunter->CheckLosFN(them)) {
taunter->Taunt(them, true);
}
}
iterator.Advance();
}
}
示例4: throw
////////////////////////////////////////////////////////////////////////////////
// 액션을 실행한다.
////////////////////////////////////////////////////////////////////////////////
void ActionSay::execute (Creature * pCreature1 , Creature * pCreature2)
throw(Error)
{
__BEGIN_TRY
Assert(pCreature1 != NULL);
Assert(pCreature2 != NULL);
Assert(pCreature1->isNPC());
Assert(pCreature2->isPC());
NPC* pNPC = dynamic_cast<NPC*>(pCreature1);
Player* pPlayer = pCreature2->getPlayer();
Assert(pPlayer != NULL);
GCNPCResponse okpkt;
pPlayer->sendPacket(&okpkt);
GCNPCSay gcNPCSay;
gcNPCSay.setObjectID(pNPC->getObjectID());
gcNPCSay.setScriptID(m_ScriptID);
gcNPCSay.setSubjectID(0);
pPlayer->sendPacket(&gcNPCSay);
__END_CATCH
}
示例5: lua_gettop
int script::addnpc(lua_State *L)
{
int n = lua_gettop(L);
if (n < 6) {
return 0;
}
unsigned short map = (unsigned short)lua_tonumber(L, 1);
unsigned short x = (unsigned short)lua_tonumber(L, 2);
unsigned short y = (unsigned short)lua_tonumber(L, 3);
const char *name = lua_tolstring(L, 4, 0);
unsigned short apr = (unsigned short)lua_tonumber(L, 5);
unsigned short dir = (unsigned short)lua_tonumber(L, 6);
Map *m = DataService::getService()->getMap(map);
if (!m)
return 0;
NPC *npc = new NPC(x, y, m, name, apr, dir);
m->addEntity(npc);
lua_pushnumber(L, (double)npc->getOid());
return 1;
}
示例6: return
int16 QuestManager::unique_spawn(int npc_type, int grid, int unused, float x, float y, float z, float heading) {
Mob *other = entity_list.GetMobByNpcTypeID(npc_type);
if(other != NULL) {
return(other->GetID());
}
NPCType* tmp = 0;
if ((tmp = Database::Instance()->GetNPCType(npc_type)))
{
NPC* npc = new NPC(tmp, 0, x, y, z, heading);
npc->AddLootTable();
entity_list.AddNPC(npc,true);
// Quag: Sleep in main thread? ICK!
// Sleep(200);
// Quag: check is irrelevent, it's impossible for npc to be 0 here
// (we're in main thread, nothing else can possibly modify it)
// if(npc != 0) {
if(grid > 0)
{
// HarakiriFIXME npc->AssignWaypoints(grid);
}
npc->SendPosUpdate();
// }
return(npc->GetID());
}
return(0);
}
示例7: throw
////////////////////////////////////////////////////////////////////////////////
// 액션을 실행한다.
////////////////////////////////////////////////////////////////////////////////
void ActionRandomSay::execute (Creature * pCreature1 , Creature * pCreature2)
throw(Error)
{
__BEGIN_TRY
__BEGIN_DEBUG
Assert(pCreature1 != NULL);
Assert(pCreature2 == NULL);
Assert(pCreature1->isNPC());
// RandomSay는 아래에서 보다시피, 임의의 범위(Start와 End) 안의
// 스크립트 중 랜덤을 돌려 하나를 클라이언트에게 보내는 식이다.
// 그러므로 Start와 End 사이에 존재하지 않는 스크립트가 있으면 곤란하다.
// 스크립트 테이블을 만들 때, RandomSay에 사용하는 것은
// 데이터가 반드시 연속적으로 존재하게 만들어야 한다.
NPC* pNPC = dynamic_cast<NPC*>(pCreature1);
ScriptID_t scriptID = m_StartScriptID + random() % (m_EndScriptID - m_StartScriptID + 1);
const Script* pScript = g_pPublicScriptManager->getScript(scriptID);
GCNPCSay gcNPCSay;
gcNPCSay.setObjectID(pNPC->getObjectID());
gcNPCSay.setScriptID(pScript->getScriptID());
gcNPCSay.setSubjectID(0);
Zone * pZone = pNPC->getZone();
Assert(pZone != NULL);
pZone->broadcastPacket(pNPC->getX() , pNPC->getY() , &gcNPCSay);
__END_DEBUG
__END_CATCH
}
示例8: NPC
bool Spawn2::Process() {
//Yeahlight: This is where an NPC spawn/respawn happens
if (timer->Check()) {
timer->Disable();
SpawnGroup* sg = zone->spawn_group_list->GetSpawnGroup(spawngroup_id_);
if (sg == 0)
return false;
SPAWN_TIME_OF_DAY tmp_time_of_day;
int32 npcid = sg->GetNPCType(&tmp_time_of_day);
if (npcid) {
NPCType* tmp = Database::Instance()->GetNPCType(npcid);
//Yeahlight: Preventing boats from autospawning for Tazadar
if (tmp && tmp->race != 72 && tmp->race != 73) {
tmp->time_of_day = tmp_time_of_day; // Kibanu
NPC* npc = new NPC(tmp, this, x, y, z, heading, false, roamRange, myRoamBox, myPathGrid, myPathGridStart);
npc->AddLootTable();
npc->GetMeleeWeapons();
npc->CalcBonuses(true, true);
entity_list.AddNPC(npc);
}
}
else {
Reset();
}
}
return true;
}
示例9: memcpy
void Trap::CreateHiddenTrigger()
{
if(hiddenTrigger)
return;
const NPCType *base_type = database.GetNPCType(500);
NPCType *make_npc = new NPCType;
memcpy(make_npc, base_type, sizeof(NPCType));
make_npc->max_hp = 100000;
make_npc->cur_hp = 100000;
strcpy(make_npc->name, "a_trap");
make_npc->runspeed = 0.0f;
make_npc->bodytype = BT_Special;
make_npc->race = 127;
make_npc->gender = 0;
make_npc->loottable_id = 0;
make_npc->npc_spells_id = 0;
make_npc->d_meele_texture1 = 0;
make_npc->d_meele_texture2 = 0;
make_npc->trackable = 0;
make_npc->level = level;
strcpy(make_npc->special_abilities, "19,1^20,1^24,1^25,1");
NPC* npca = new NPC(make_npc, 0, x, y, z, 0, FlyMode3);
npca->GiveNPCTypeData(make_npc);
entity_list.AddNPC(npca);
hiddenTrigger = npca;
ownHiddenTrigger = true;
}
示例10: GetMostHated
gemNPCActor* Tribe::GetMostHated(NPC* npc, float range, bool includeOutsideRegion, bool includeInvisible, bool includeInvincible, float* hate)
{
float mostHatedAmount = 0.0;
gemNPCActor* mostHated = NULL;
csVector3 pos;
iSector* sector;
psGameObject::GetPosition(npc->GetActor(), pos, sector);
for(size_t i=0; i < members.GetSize(); i++)
{
NPC* member = members[i];
float hateValue = 0;
gemNPCActor* hated = member->GetMostHated(pos, sector, range, NULL,
includeOutsideRegion, includeInvisible, includeInvincible,
&hateValue);
if(!mostHated || hateValue > mostHatedAmount)
{
mostHatedAmount = hateValue;
mostHated = hated;
}
}
if(hate)
{
*hate = mostHatedAmount;
}
return mostHated;
}
示例11: add_spawnable_npc
void Tournament::add_spawnable_npc(GSpawnNPC *snpc) {
NPC *npc = resources.get_npc(snpc->npc_name);
SpawnableNPC *nnpc = new SpawnableNPC;
nnpc->npc = npc;
nnpc->state.id = snpc->id;
nnpc->state.owner = snpc->owner;
nnpc->state.flags = 0;
nnpc->state.direction = snpc->direction;
nnpc->state.x = snpc->x;
nnpc->state.y = snpc->y;
nnpc->state.accel_x = snpc->accel_x;
nnpc->state.accel_y = snpc->accel_y;
nnpc->icon = NPCAnimationStanding;
nnpc->iconindex = 0;
nnpc->init_owner = snpc->owner;
nnpc->ignore_owner_counter = npc->get_ignore_owner_counter();
nnpc->move_counter = static_cast<double>(npc->get_move_init_randomized());
spawnable_npcs.push_back(nnpc);
if (!server) {
try {
if (snpc->sound_name[0]) {
subsystem.play_sound(resources.get_sound(snpc->sound_name), 0);
}
} catch (const Exception& e) {
subsystem << e.what();
}
}
}
示例12: load
QList<NPC*> GameLoader::loadNpcs(const QDomElement& element)
{
QList<NPC*> npcs;
QString source = element.attribute("source");
if (!source.isNull())
{
QDomDocument document = load(path()+"/"+source);
npcs = loadNpcs(document.documentElement());
_paths.pop();
return npcs;
}
QDomNodeList children = element.childNodes();
for (int i=0; i<children.size(); ++i)
{
QDomElement child = children.at(i).toElement();
if (child.tagName()=="npc")
{
NPC* npc = new NPC();
npc->setName(child.attribute("name"));
initializeObject(child, npc);
npcs << npc;
}
}
return npcs;
}
示例13: delete
void NPCManager::handleNewMap() {
Map_NPC mn;
ItemStack item_roll;
// remove existing NPCs
for (unsigned i=0; i<npcs.size(); i++)
delete(npcs[i]);
npcs.clear();
// read the queued NPCs in the map file
while (!map->npcs.empty()) {
mn = map->npcs.front();
map->npcs.pop();
NPC *npc = new NPC(map, items);
npc->load(mn.id, stats->level);
npc->pos.x = mn.pos.x;
npc->pos.y = mn.pos.y;
// if this NPC needs randomized items
while (npc->random_stock > 0 && npc->stock_count < NPC_VENDOR_MAX_STOCK) {
item_roll.item = loot->randomItem(npc->level);
item_roll.quantity = rand() % items->items[item_roll.item].rand_vendor + 1;
npc->stock.add(item_roll);
npc->random_stock--;
}
npc->stock.sort();
npcs.push_back(npc);
}
}
示例14: defenceLocation
///=====================================================
///
///=====================================================
void AISystem::DefendStrategy() const{
static IntVec2 defenceLocation(48, 9);
for (Actors::const_iterator actorIter = Actor::s_actorsOnMap.cbegin(); actorIter != Actor::s_actorsOnMap.cend(); ++actorIter){
Actor* actor = actorIter->second;
if (actor->m_isDead)
continue;
if (actor->IsPlayer()){
break;
}
else{
NPC* npc = (NPC*)actor;
if (npc->m_plannedBehavior->m_name == "Wander" && CalcDistanceSquared(npc->m_position, defenceLocation) > (10 * 10)){ //if we're far away from the defence location and wandering, move toward the defence location
DefendLocationBehavior* defendLocationBehavior = (DefendLocationBehavior*)npc->FindBehaviorByName("DefendLocation");
RECOVERABLE_ASSERT(defendLocationBehavior != nullptr);
if (defendLocationBehavior != nullptr){
defendLocationBehavior->m_defenceLocation = defenceLocation;
npc->m_plannedBehavior = defendLocationBehavior;
}
}
}
}
}
示例15: castSkybaserForGhost
void castSkybaserForGhost(Mission* mission, Airplane* airplane, CatToy* ghost)
{
assert( ghost );
// detect cattoy level
float cattoyLevel = 0.25f * (
ghost->getVirtues()->getEnduranceSkill() +
ghost->getVirtues()->getPerceptionSkill() +
ghost->getVirtues()->getRiggingSkill() +
ghost->getVirtues()->getTrackingSkill()
);
// detect player is a LICENSED_CHAR
bool playerIsLicensed = mission->getScene()->getCareer()->getLicensedFlag();
// build list of same level npc
std::vector<unsigned int> npcs;
database::NPCInfo::select( cattoyLevel, 0.126f, !playerIsLicensed, npcs );
// select NPC
unsigned int index = getCore()->getRandToolkit()->getUniformInt() % npcs.size();
unsigned int npcId = npcs[index];
// create NPC
NPC* npc = new NPC( mission, npcId, airplane, NULL, ghost );
// devote ghost
npc->devoteCattoy();
// setup cameraman behaviour
npc->setProgram( new NPCCameraman( npc ) );
// setup brief signature
npc->getJumper()->setSignatureType( stBrief );
}