AIController::AIController(World* a_world) { m_pWorld = a_world; m_farmerValue.setNormalizationType(UtilityValue::INVERSE_LINEAR); m_farmerValue.setMinMaxValues(-1, 10); //m_farmerValue.setValue() //Supply - Demand? UtilityScore* pFarmerValue = new UtilityScore(); pFarmerValue->addUtilityValue(&m_farmerValue, 1.0f); m_pUtilityScoreMap["AssignFarmer"] = pFarmerValue; m_harvesterValue.setNormalizationType(UtilityValue::INVERSE_LINEAR); m_harvesterValue.setMinMaxValues(0, 20); m_harvesterValue.setValue(m_pWorld->getCurrentStockpileLogs()); //Need for logs? UtilityScore* pHarvesterValue = new UtilityScore(); pHarvesterValue->addUtilityValue(&m_harvesterValue, 0.70f); m_pUtilityScoreMap["AssignHarvester"] = pHarvesterValue; m_builderValue.setNormalizationType(UtilityValue::INVERSE_LINEAR); m_builderValue.setMinMaxValues(0, 10); m_builderValue.setValue(CalculateHouseDemand()); // * (0,1) stockpile log value UtilityScore* pBuilderValue = new UtilityScore(); pBuilderValue->addUtilityValue(&m_builderValue, 0.70f); m_pUtilityScoreMap["AssignBuilder"] = pBuilderValue; AddNPC(); AddNPC(); }
bool NFCTileModule::LoadTileData(const NFGUID & self, const int nSceneID) { mxTileData.RemoveElement(self); std::string strData; if (m_pPlayerRedisModule->LoadPlayerTile(nSceneID, self, strData)) { NFMsg::AckMiningTitle xData; if (xData.ParseFromString(strData)) { for (int i = 0; i < xData.tile_size(); ++i) { const NFMsg::TileState& xTile = xData.tile(i); AddTile(self, xTile.x(), xTile.y(), xTile.opr()); } for (int i = 0; i < xData.building_size(); ++i) { const NFMsg::TileBuilding& xTile = xData.building(i); AddBuilding(self, xTile.x(), xTile.y(), NFINetModule::PBToNF(xTile.guid()), xTile.configid()); } for (int i = 0; i < xData.npc_size(); ++i) { const NFMsg::TileNPC& xTile = xData.npc(i); AddNPC(self, xTile.x(), xTile.y(), NFINetModule::PBToNF(xTile.guid()), xTile.configid()); } return true; } } return false; }
void AIController::Update(float a_fdeltaTime) { reassignTimer -= a_fdeltaTime; if (glfwGetKey(glfwGetCurrentContext(), GLFW_KEY_SPACE)) { if (canSpawn) { AddNPC(); canSpawn = false; } } else { canSpawn = true; } //Reassign Jobs if (reassignTimer <= 0) { CalculateNPCJobs(); reassignTimer = 5; } for (std::vector<UtilityNPC*>::const_iterator iter = m_pWorld->NPCVector.begin(); iter != m_pWorld->NPCVector.end(); iter++) { (*iter)->update(a_fdeltaTime); } }
P_CHAR cCharStuff::AddNPCxyz(int s, int npcNum, int type, int x1, int y1, signed char z1) //Morrolan - replacement for old Npcs->AddNPCxyz(), fixes a LOT of problems. { if (type == 0) return AddNPC(s, NULL, npcNum, x1,y1,z1); // 's' maybe(!) is a socket if (type == 1) clConsole.send("ERROR: type == 1 not supported!\n"); return NULL; }
bool CGame::OnInit() { CApp::OnInit(); player=new CPlayer(); player->OnLoad("../Res/circle_a.png",render); CEntity::entity_list.push_back(player); srand(time(nullptr)); AddNPC(6); pause=false; Restart(); return true; }
CMonster* CMap::AddNpc( UINT montype, fPoint position, int team) { CNPC* thisnpc = new CNPC; assert(thisnpc); thisnpc->clientid = GServer->GetNewClientID(); thisnpc->dir = 0; thisnpc->npctype = montype; thisnpc->pos = position; thisnpc->posMap = id; thisnpc->thisnpc = GServer->GetNPCDataByID( montype ); thisnpc->team = team; thisnpc->thisnpc->dialogid = 0; thisnpc->dialog=0; thisnpc->event=0; thisnpc->thisnpc->eventid=0; thisnpc->lastAiUpdate=clock(); AddNPC( thisnpc ); }
void ObjectMgr::LoadTransporters() { Log.Notice("TransporterHandler", "Start loading transport_data"); { const char* loadAllTransportData = "SELECT entry, name, period FROM transport_data"; QueryResult* result = WorldDatabase.Query(loadAllTransportData); if (!result) { Log.Error("TransporterHandler", "Query failed: %s", loadAllTransportData); return; } uint32 count = 0; do { Field* field = result->Fetch(); TransporterDataQueryResult dbResult; dbResult.entry = field[0].GetUInt32(); dbResult.name = field[1].GetString(); dbResult.period = field[2].GetUInt32(); GameObjectInfo* goInfo = GameObjectNameStorage.LookupEntry(dbResult.entry); if (goInfo == nullptr) { Log.Error("TransporterHandler", "Transporter gameobject %u not available in GameObjectNameStorage!", dbResult.entry); continue; } Transporter* pTransporter = new Transporter((uint64)HIGHGUID_TYPE_TRANSPORTER << 32 | dbResult.entry); pTransporter->SetInfo(goInfo); if (!pTransporter->CreateAsTransporter(dbResult.entry, "", dbResult.period)) { Log.Error("TransporterHandler", "Transporter %s failed creation for some reason.", dbResult.name.c_str()); delete pTransporter; } else { Log.Debug("TransporterHandler", "%s, Entry: %u, Period: %u loaded", dbResult.name.c_str(), dbResult.entry, dbResult.period); AddTransport(pTransporter); ++count; } } while (result->NextRow()); delete result; Log.Success("TransporterHandler", "%u transporters loaded from table transporter_data", count); } Log.Notice("TransporterHandler", "Start loading transport_creatures"); { const char* loadTransportPassengers = "SELECT transport_entry, creature_entry, position_x, position_y, position_z, orientation FROM transport_creatures"; bool success = false; QueryResult* result = WorldDatabase.Query(&success, loadTransportPassengers); if (!success) { Log.Error("TransporterHandler", "Query failed: %s", loadTransportPassengers); return; } uint32 count = 0; if (result) { do { Field* field = result->Fetch(); uint32 transport_entry = field[0].GetUInt32(); uint32 creature_entry = field[1].GetUInt32(); auto transporter = GetTransporterByEntry(transport_entry); if (transporter == nullptr) { Log.Error("TransporterHandler", "Could not find transporter %u for transport_creatures entry %u", transport_entry, creature_entry); continue; } TransporterCreaturesQueryResult dbResult; dbResult.transport_entry = field[0].GetUInt32(); dbResult.creature_entry = field[1].GetUInt32(); dbResult.position_x = field[2].GetFloat(); dbResult.position_y = field[3].GetFloat(); dbResult.position_z = field[4].GetFloat(); dbResult.orientation = field[5].GetFloat(); transporter->creature_transport_data.push_back(dbResult); transporter->AddNPC(dbResult.creature_entry, dbResult.position_x, dbResult.position_y, dbResult.position_z, dbResult.orientation); ++count; } while (result->NextRow()); delete result; Log.Success("TransporterHandler", "%u transport passengers from table transport_creatures loaded.", count); } } }
void CGame::NextLevel() { AddNPC(obj_incr); Restart(); }
void RiseDeadSpell::Update(float timeDelta) { if(m_creationFailed) { m_light = LightHandle(); return; } m_duration+=200; m_fissure.Update(timeDelta); m_fissure.Render(); if(lightHandleIsValid(m_light)) { EERIE_LIGHT * light = lightHandleGet(m_light); light->intensity = 0.7f + 2.3f; light->fallend = 500.f; light->fallstart = 400.f; light->rgb = Color3f(0.8f, 0.2f, 0.2f); light->duration=800; light->time_creation = (unsigned long)(arxtime); } unsigned long tim = m_fissure.ulCurrentTime; if(tim > 3000 && m_entity == EntityHandle() && !m_creationFailed) { ARX_SOUND_PlaySFX(SND_SPELL_ELECTRIC, &m_targetPos); Cylinder phys = Cylinder(m_targetPos, 50, -200); float anything = CheckAnythingInCylinder(phys, NULL, CFLAG_JUST_TEST); if(glm::abs(anything) < 30) { const char * cls = "graph/obj3d/interactive/npc/undead_base/undead_base"; Entity * io = AddNPC(cls, -1, IO_IMMEDIATELOAD); if(io) { ARX_INTERACTIVE_HideGore(io); RestoreInitialIOStatusOfIO(io); io->summoner = m_caster; io->ioflags|=IO_NOSAVE; m_entity = io->index(); io->scriptload=1; ARX_INTERACTIVE_Teleport(io, phys.origin); SendInitScriptEvent(io); if(ValidIONum(m_caster)) { EVENT_SENDER = entities[m_caster]; } else { EVENT_SENDER = NULL; } SendIOScriptEvent(io,SM_SUMMONED); Vec3f pos = m_fissure.m_eSrc; pos += randomVec3f() * 100.f; pos += Vec3f(-50.f, 50.f, -50.f); MakeCoolFx(pos); } m_light = LightHandle(); } else { ARX_SOUND_PlaySFX(SND_MAGIC_FIZZLE); m_creationFailed = true; m_duration=0; } } else if(!arxtime.is_paused() && tim < 4000) { if(Random::getf() > 0.95f) { MakeCoolFx(m_fissure.m_eSrc); } } }
BOOL CLibInfoCharSvr::UseSkillBATTLE_MOVEATACK(CInfoCharSvr *pInfoChar, CInfoSkillBase *pInfoSkillBase) { int i, nCount, nDirectionTmp, nDirection; BOOL bRet, bResult; POINT ptFront; PCInfoMapBase pInfoMap; PCInfoSkillMOVEATACK pInfoSkill = (PCInfoSkillMOVEATACK)pInfoSkillBase; CInfoCharMOVEATACKSvr InfoCharTmp, *pInfoCharTmp; CPacketMAP_FORMATMSG PacketMsg; ARRAYINT anDirection; bRet = FALSE; pInfoMap = (PCInfoMapBase)m_pLibInfoMap->GetPtr (pInfoChar->m_dwMapID); if (pInfoMap == NULL) { goto Exit; } switch (pInfoSkill->m_dwPutType) { case SKILLMOVEATACKPUTTYPE_FRONT: /* 前方 */ nDirection = pInfoChar->GetDrawDirection (); anDirection.Add (nDirection); break; case SKILLMOVEATACKPUTTYPE_CROSS: /* 上下左右 */ anDirection.Add (0); anDirection.Add (1); anDirection.Add (2); anDirection.Add (3); break; } nCount = anDirection.GetSize (); for (i = 0; i < nCount; i ++) { nDirectionTmp = anDirection[i]; /* 進めるかチェック */ bResult = IsMove (pInfoChar, nDirectionTmp); if (bResult == FALSE) { continue; } nDirection = pInfoChar->GetDrawDirection (); pInfoChar->GetFrontPos (ptFront, nDirectionTmp, TRUE); InfoCharTmp.m_dwParentCharID = pInfoChar->m_dwCharID; InfoCharTmp.m_dwMapID = pInfoChar->m_dwMapID; InfoCharTmp.m_nDirection = nDirectionTmp; InfoCharTmp.m_bChargeAtack = pInfoChar->m_bChargeAtack; InfoCharTmp.m_nMapX = ptFront.x; InfoCharTmp.m_nMapY = ptFront.y; InfoCharTmp.m_dwHP = 1; InfoCharTmp.m_nMoveType = CHARMOVETYPE_MOVEATACK; InfoCharTmp.m_wGrpIDNPC = (WORD)-1; InfoCharTmp.m_wGrpIDCloth = (WORD)pInfoSkill->m_adwEffectID[nDirectionTmp]; pInfoCharTmp = (PCInfoCharMOVEATACKSvr)AddNPC (&InfoCharTmp); pInfoCharTmp->SetMap (pInfoMap); pInfoCharTmp->m_bParentInfo = FALSE; pInfoCharTmp->m_bHitQuit = pInfoSkill->m_bHitQuit; pInfoCharTmp->m_bDistanceDelete = pInfoSkill->m_bDistanceDelete; pInfoCharTmp->m_nAtackTarget = pInfoSkill->m_dwTartgetType; pInfoCharTmp->m_dwMoveWait = pInfoSkill->m_dwWaitTime; pInfoCharTmp->m_dwMoveCount = pInfoSkill->m_dwDistance; pInfoCharTmp->m_dwHitEffectID = pInfoSkill->m_dwHitEffectID; pInfoCharTmp->m_dwValue1 = pInfoSkill->m_dwValue1; pInfoCharTmp->m_dwValue2 = pInfoSkill->m_dwValue2; pInfoCharTmp->m_dwQuitTime = timeGetTime () + pInfoSkill->m_dwAliveTime; } PacketMsg.Make ( FORMATMSGID_USESKILL, pInfoChar->m_dwCharID, pInfoSkillBase->m_dwSkillID, RGB (255, 255, 255), FALSE, FORMATMSGTYPE_NOLOG); m_pMainFrame->SendToScreenChar (pInfoChar, &PacketMsg); bRet = TRUE; Exit: return bRet; }
void SummonCreatureSpell::Update() { if(arxtime.is_paused()) return; float elapsed = arxtime.now_f() - m_timcreation; if(elapsed <= 4000) { if(Random::getf() > 0.7f) { Vec3f pos = m_fissure.m_eSrc; MakeCoolFx(pos); } m_fissure.Update(g_framedelay); m_fissure.Render(); m_requestSummon = true; m_summonedEntity = EntityHandle(); } else if(m_requestSummon) { lightHandleDestroy(m_light); m_requestSummon = false; ARX_SOUND_PlaySFX(SND_SPELL_ELECTRIC, &m_targetPos); Cylinder phys = Cylinder(m_targetPos, 50, -200); float anything = CheckAnythingInCylinder(phys, NULL, CFLAG_JUST_TEST); if(glm::abs(anything) < 30) { long tokeep; res::path cls; if(m_megaCheat) { if(Random::getf() > 0.5f) { tokeep = -1; cls = "graph/obj3d/interactive/npc/wrat_base/wrat_base"; } else { tokeep = 0; cls = "graph/obj3d/interactive/npc/y_mx/y_mx"; } } else if(Random::getf() > 0.997f || (sp_max && Random::getf() > 0.8f) || (cur_mr >= 3 && Random::getf() > 0.3f)) { tokeep = 0; cls = "graph/obj3d/interactive/npc/y_mx/y_mx"; } else if(Random::getf() > 0.997f || (cur_rf >= 3 && Random::getf() > 0.8f) || (cur_mr >= 3 && Random::getf() > 0.3f)) { tokeep = -1; cls = "graph/obj3d/interactive/npc/wrat_base/wrat_base"; } else if(m_level >= 9) { tokeep = 1; cls = "graph/obj3d/interactive/npc/demon/demon"; } else if(Random::getf() > 0.98f) { tokeep = -1; cls = "graph/obj3d/interactive/npc/wrat_base/wrat_base"; } else { tokeep = 0; cls = "graph/obj3d/interactive/npc/chicken_base/chicken_base"; } Entity * io = AddNPC(cls, -1, IO_IMMEDIATELOAD); if(!io) { cls = "graph/obj3d/interactive/npc/chicken_base/chicken_base"; tokeep = 0; io = AddNPC(cls, -1, IO_IMMEDIATELOAD); } if(io) { RestoreInitialIOStatusOfIO(io); io->summoner = m_caster; io->scriptload = 1; if(tokeep == 1) { io->ioflags |= IO_NOSAVE; } io->pos = phys.origin; SendInitScriptEvent(io); if(tokeep < 0) { io->scale=1.65f; io->physics.cyl.radius=25; io->physics.cyl.height=-43; io->speed_modif=1.f; } if(ValidIONum(m_caster)) { EVENT_SENDER = entities[m_caster]; } else { EVENT_SENDER = NULL; } SendIOScriptEvent(io,SM_SUMMONED); for(long j = 0; j < 3; j++) { Vec3f pos = m_fissure.m_eSrc; pos += randomVec3f() * 100.f; pos += Vec3f(-50.f, 50.f, -50.f); MakeCoolFx(pos); } if(tokeep==1) m_summonedEntity = io->index(); else m_summonedEntity = EntityHandle(); } } } else if(m_summonedEntity == EntityHandle()) { m_duration = 0; } }