bool Actor::handleOrder(DieOrder &order, EntityEvent::Type event, const EntityEventParams ¶ms) { bool play_sound = event == EntityEvent::sound; if(event == EntityEvent::init_order) { bool is_fallen = isOneOf(m_action, Action::fall_forward, Action::fall_back, Action::fallen_back, Action::fallen_forward); bool special_death = isOneOf(order.m_death_id, DeathId::explode, DeathId::fire, DeathId::electrify, DeathId::melt); if((is_fallen || m_stance == Stance::prone) && !special_death) { order.m_death_id = DeathId::normal; play_sound = true; if(m_stance == Stance::prone && !is_fallen) animate(Action::fall_forward); else order.m_is_dead = true; } else if(!animateDeath(order.m_death_id)) animateDeath(DeathId::normal); } if(play_sound) { SoundId sound_id = m_actor.sounds[m_sound_variation].death[order.m_death_id]; if(sound_id == -1) sound_id = m_actor.sounds[m_sound_variation].death[DeathId::normal]; playSound(sound_id, pos()); if(m_actor.is_alive) playSound(m_actor.human_death_sounds[order.m_death_id], pos()); } if(event == EntityEvent::anim_finished) order.m_is_dead = true; return true; }
inline std::vector<std::string> split(const std::string& s, const std::string& delims) { std::vector<std::string> tokens; int idxStart = 0; bool inToken = false; for (std::size_t i = 0; i < s.length(); ++i) { if (isOneOf(s[i], delims)) { if (!inToken) { idxStart = i+1; } else { tokens.push_back(s.substr(idxStart, i - idxStart)); inToken = false; idxStart = i+1; } } else { inToken = true; } } if (inToken) { tokens.push_back(s.substr(idxStart)); } return tokens; }
bool HudMainPanel::onEvent(const HudEvent &event) { if(event.type == HudEvent::button_clicked) { HudButton *source = dynamic_cast<HudButton*>(event.source); if(isOneOf(source, m_hud_buttons)) { handleEvent(HudEvent::layer_changed, source->id()); } if(!m_pc_controller) return false; if(isOneOf(source, m_hud_stances) && m_pc_controller->canChangeStance()) { m_pc_controller->setStance((Stance)event.value); } if(m_hud_weapon.get() == source) m_pc_controller->reload(); return true; } return false; }
bool Weapon::canKick() const { return isOneOf(classId(), WeaponClass::unarmed, WeaponClass::knife, WeaponClass::pistol, WeaponClass::club); }
//////////////////////////////////////////////////////////////////////////////// // Lexer::Type::dom // [ <isUUID> | <isDigit>+ . ] <isIdentifier> [ . <isIdentifier> ]* // // Configuration: // rc.<name> // // System: // context.program // context.args // context.width // context.height // system.version // system.os // // Relative or absolute attribute: // <attribute> // <id>.<attribute> // <uuid>.<attribute> // // Single tag: // tags.<word> // // Date type: // <date>.year // <date>.month // <date>.day // <date>.week // <date>.weekday // <date>.julian // <date>.hour // <date>.minute // <date>.second // // Annotations (entry is a date): // annotations.<N>.entry // annotations.<N>.description // bool Lexer::isDOM (std::string& token, Lexer::Type& type) { std::size_t marker = _cursor; std::string partialToken; Lexer::Type partialType; if (isLiteral ("rc.", false, false) && isWord (partialToken, partialType)) { token = _text.substr (marker, _cursor - marker); type = Lexer::Type::dom; return true; } else _cursor = marker; if (isOneOf ({"context.program", "context.args", "context.width", "context.height", "system.version", "system.os"}, false, true)) { token = _text.substr (marker, _cursor - marker); type = Lexer::Type::dom; return true; } // Optional: // <uuid>. // <id>. std::string extractedToken; Lexer::Type extractedType; if (isUUID (extractedToken, extractedType, false) || isInteger (extractedToken, extractedType)) { if (! isLiteral (".", false, false)) { _cursor = marker; return false; } } // Any failure after this line should rollback to the checkpoint. std::size_t checkpoint = _cursor; // [prefix]tags.<word> if (isLiteral ("tags", false, false) && isLiteral (".", false, false) && isWord (partialToken, partialType)) { token = _text.substr (marker, _cursor - marker); type = Lexer::Type::dom; return true; } else _cursor = checkpoint; // [prefix]attribute if (isOneOf (attributes, false, true)) { token = _text.substr (marker, _cursor - marker); type = Lexer::Type::dom; return true; } // [prefix]attribute. if (isOneOf (attributes, false, false)) { if (isLiteral (".", false, false)) { std::string attribute = _text.substr (checkpoint, _cursor - checkpoint - 1); // if attribute type is 'date', then it has sub-elements. if (attributes[attribute] == "date" && isOneOf ({"year", "month", "day", "week", "weekday", "julian", "hour", "minute", "second"}, false, true)) { token = _text.substr (marker, _cursor - marker); type = Lexer::Type::dom; return true; } } else { token = _text.substr (marker, _cursor - marker); type = Lexer::Type::dom; return true; } } // [prefix]annotations. if (isLiteral ("annotations", true, false) && isLiteral (".", false, false)) { std::string extractedToken; Lexer::Type extractedType; if (isInteger (extractedToken, extractedType)) { if (isLiteral (".", false, false)) { if (isLiteral ("description", false, true)) { token = _text.substr (marker, _cursor - marker); type = Lexer::Type::dom; return true; } else if (isLiteral ("entry", false, true)) { token = _text.substr (marker, _cursor - marker); type = Lexer::Type::dom; return true; } else if (isLiteral ("entry", false, false) && isLiteral (".", false, false) && isOneOf ({"year", "month", "day", "week", "weekday", "julian", "hour", "minute", "second"}, false, true)) { token = _text.substr (marker, _cursor - marker); type = Lexer::Type::dom; return true; } } } } _cursor = marker; return false; }