void test() { CharacterClass a; Faction faction(a); container <Character> cont; cont.push_back(Character()); cont.push_back(Character()); cont.push_back(Character()); cont.push_back(Character()); cont.push_back(Character()); cont.push_back(Character()); cont.push_back(Character()); cont.push_back(Character()); cont.push_back(Character()); cont.push_back(Character()); cont.push_back(Character()); cont.push_back(Character()); cont.push_back(Character()); for(size_t i=0; i<cont.size(); ++i) faction.addPlayer(cont[i]); faction.KUPSKO(); //printf("%d %d\n", cont[5].param[0], cont[9].param[0]); }
int LuaPlayerObject::getFactionStanding(lua_State* L) { //String faction = lua_tostring(L, -1); const char* str = lua_tostring(L, -1); String faction(str); float standing = realObject->getFactionStanding(faction); lua_pushnumber(L, standing); return 1; }
int FactionManager::addFaction(lua_State* L) { String allies = Lua::getStringParameter(L); String enemies = Lua::getStringParameter(L); String factionName = Lua::getStringParameter(L); FactionManager* factionManager = FactionManager::instance(); FactionMap* factionMap = factionManager->getFactionMap(); if (factionMap == NULL) return 1; Faction faction(factionName); faction.parseEnemiesFromList(enemies); faction.parseAlliesFromList(allies); factionMap->addFaction(faction); return 0; }
void CreateBullet(Entity *e, SpawnEntityMessage *msg) { const int bulletHitboxSize = 15; Entity *spawner = msg->Spawner(); LocationComponent *spawnerLocation = static_cast<LocationComponent *>(spawner->GetComponent(ComponentType::LOCATION)); FactionComponent *spawnerFaction = static_cast<FactionComponent *>(spawner->GetComponent(ComponentType::FACTION)); SDL_assert(spawnerLocation != nullptr); Faction bulletFaction = Faction::NONE; if (spawnerFaction != nullptr) { bulletFaction = spawnerFaction->GetFaction(); } double x = spawnerLocation->GetX(); double y = spawnerLocation->GetY(); double speed = 10.0; double xVel = 0; double yVel = 0; Direction direction = spawnerLocation->GetFiringDirection(); switch (direction) { case Direction::RIGHT: x += bulletHitboxSize; xVel = speed; break; case Direction::LEFT: x -= bulletHitboxSize; xVel = -speed; break; case Direction::UP: y -= bulletHitboxSize; yVel = -speed; break; case Direction::DOWN: y += bulletHitboxSize; yVel = speed; break; default: break; } std::unique_ptr<LocationComponent> location(new LocationComponent()); location->SetLocation(x, y); location->SetDirection(direction); std::unique_ptr<GraphicsComponent> graphics(new GraphicsComponent()); graphics->AddFrame(0, 200007); std::unique_ptr<CollisionComponent> collision(new CollisionComponent); collision->AddHitbox(8, 8, bulletHitboxSize, bulletHitboxSize, HitboxType::TRIGGER); std::unique_ptr<VelocityComponent> velocity(new VelocityComponent(0, 0)); velocity->SetVelocity(xVel, yVel); std::unique_ptr<FactionComponent> faction(new FactionComponent(bulletFaction)); std::unique_ptr<SoundComponent> sound(new SoundComponent()); sound->AddSoundEffect(SoundEffectType::DEATH, SOUND_GUN_HIT); e->AddComponent(ComponentType::SOUND, std::move(sound)); e->AddComponent(ComponentType::COLLISION, std::move(collision)); e->AddComponent(ComponentType::GRAPHICS, std::move(graphics)); e->AddComponent(ComponentType::LOCATION, std::move(location)); e->AddComponent(ComponentType::VELOCITY, std::move(velocity)); e->AddComponent(ComponentType::FACTION, std::move(faction)); VMState damageColliderScript = Compiler::Compile("data/scripts/DamageColliderScript.txt"); RegisterNativeBindings(damageColliderScript); e->AddVmScript(std::move(damageColliderScript)); VMState bulletScript = Compiler::Compile("data/scripts/BulletScript.txt"); RegisterNativeBindings(bulletScript); e->AddVmScript(std::move(bulletScript)); }
void psNPCLoader::WriteFactions() { // <factions> // <faction name=".." value=".."> // <faction name=".." value=".."> // .... // </factions> csString factions; npc->GetFactions()->GetFactionListCSV(factions); // consider (null) and NULL as empty entries if(factions.StartsWith("(null)") || factions.StartsWith("NULL")) return; // factions are stored in the DB like this: '3,40,2,50,..' // so this needs to be converted int pos = 0; int start = 0; csString sub; csArray<int> intList; while(pos< (int)factions.Length()) { if(factions.GetAt(pos)==',') { factions.SubString(sub,start,pos-start); intList.Push(atoi(sub)); start = ++pos; } pos++; } csRef<iDocumentNode> factionsNode = npcRoot->CreateNodeBefore(CS_NODE_ELEMENT); factionsNode->SetValue("factions"); if(factions.Length()>0) { factions.SubString(sub, start, factions.Length()-start); intList.Push(atoi(sub)); for(size_t i=0; i<intList.GetSize(); i+=2) { csString temp; int factionID = intList[i ]; int value = intList[i+1]; Result faction(db->Select("SELECT faction_name " "FROM factions " "WHERE id=%i;", factionID)); csRef<iDocumentNode> factionNode = factionsNode->CreateNodeBefore(CS_NODE_ELEMENT); factionNode->SetValue("faction"); factionNode->SetAttribute("name", faction[0][0]); factionNode->SetAttributeAsInt("value", value); } } }