void Creature::onHit(const MWWorld::Ptr &ptr, float damage, bool ishealth, const MWWorld::Ptr &object, const MWWorld::Ptr &attacker, bool successful) const { // NOTE: 'object' and/or 'attacker' may be empty. if(!successful) { // TODO: Handle HitAttemptOnMe script function // Missed MWBase::Environment::get().getSoundManager()->playSound3D(ptr, "miss", 1.0f, 1.0f); return; } if(!object.isEmpty()) getCreatureStats(ptr).setLastHitObject(MWWorld::Class::get(object).getId(object)); if(!attacker.isEmpty() && attacker.getRefData().getHandle() == "player") { const std::string &script = ptr.get<ESM::Creature>()->mBase->mScript; /* Set the OnPCHitMe script variable. The script is responsible for clearing it. */ if(!script.empty()) ptr.getRefData().getLocals().setVarByInt(script, "onpchitme", 1); } if(ishealth) { if(damage > 0.0f) MWBase::Environment::get().getSoundManager()->playSound3D(ptr, "Health Damage", 1.0f, 1.0f); float health = getCreatureStats(ptr).getHealth().getCurrent() - damage; setActorHealth(ptr, health, attacker); } else { MWMechanics::DynamicStat<float> fatigue(getCreatureStats(ptr).getFatigue()); fatigue.setCurrent(fatigue.getCurrent() - damage); getCreatureStats(ptr).setFatigue(fatigue); } }
QVariant Human::data(int role) const { switch(role) { case IdRole: return (unsigned int)id(); case FilterStringRole: return filterString(); case ProfessionRole: return profession(); case PosXRole: return posX(); case PosYRole: return posY(); case PosZRole: return posZ(); case NameRole: return name(); case ArcherLevelRole: return archerLevel(); case BlacksmithLevelRole: return blacksmithLevel(); case BuilderLevelRole: return builderLevel(); case CarpenterLevelRole: return carpenterLevel(); case EngineerLeveRole: return engineerLevel(); case FarmerLevelRole: return farmerLevel(); case FishermanLevelRole: return fishermanLevel(); case ForagerLevelRole: return foragerLevel(); case InfantryLevelRole: return infantryLevel(); case MinerLevelRole: return minerLevel(); case StoneMasonLevelRole: return stoneMasonLevel(); case WoodChopperLevelRole: return woodChopperLevel(); case TailorLevelRole: return tailorLevel(); case TraderLevelRole: return traderLevel(); case HerderLevelRole: return herderLevel(); case AdventurerLevelRole: return adventurerLevel(); case Unknown1Role: return unknown1Level(); case Unknown2Role: return unknown2Level(); case Unknown3Role: return unknown3Level(); case Unknown4Role: return unknown4Level(); case ExperienceRole: return experience(); case AutoChopTreesRole: return autoChop(); case GatherBerriesRole: return gatherBerries(); case HuntChickenRole: return huntChicken(); case HuntBoarRole: return huntBoar(); case ShowBowRangeRole: return showBowRange(); case TrainNearTargetRole: return trainNearTarget(); case RotationRole: return rotation(); case EquipHandRole: return equipHand(); case EquipOffhandRole: return equipOffhand(); case EquipHeadRole: return equipHead(); case EquipBodyRole: return equipBody(); case EquipFeetRole: return equipFeet(); case HealthRole: return health(); case MoraleRole: return morale(); case FatigueRole: return fatigue(); case HungerRole: return hunger(); default: return QVariant(); } }
/** * @brief Write the Human data back to a file. */ void Human::writeToFile( QFile &unitFile ) { QTextStream unitStream(&unitFile); unitStream << profession() << "/" << QString("%1").arg(posX(),0,'g',8) << "/" << QString("%1").arg(posY(),0,'g',8) << "/" << QString("%1").arg(posZ(),0,'g',8) << "/" << name() << "/"; unitStream.flush(); unitFile.write(Utils::toBinary(archerLevel())); unitFile.write(Utils::toBinary(blacksmithLevel())); unitFile.write(Utils::toBinary(builderLevel())); unitFile.write(Utils::toBinary(carpenterLevel()).constData()); unitFile.write(Utils::toBinary(engineerLevel()).constData()); unitFile.write(Utils::toBinary(farmerLevel()).constData()); unitFile.write(Utils::toBinary(fishermanLevel()).constData()); unitFile.write(Utils::toBinary(foragerLevel()).constData()); unitFile.write(Utils::toBinary(infantryLevel()).constData()); unitFile.write(Utils::toBinary(minerLevel()).constData()); unitFile.write(Utils::toBinary(stoneMasonLevel()).constData()); unitFile.write(Utils::toBinary(woodChopperLevel()).constData()); unitFile.write(Utils::toBinary(tailorLevel()).constData()); unitFile.write(Utils::toBinary(traderLevel()).constData()); unitFile.write(Utils::toBinary(herderLevel()).constData()); unitFile.write(Utils::toBinary(adventurerLevel()).constData()); unitFile.write(Utils::toBinary(unknown1Level()).constData()); unitFile.write(Utils::toBinary(unknown2Level()).constData()); unitFile.write(Utils::toBinary(unknown3Level()).constData()); unitFile.write(Utils::toBinary(unknown4Level()).constData()); unitStream << "/"; unitStream.flush(); unitFile.write(Utils::toBinary(experience()).constData()); unitStream << "/"; unitStream.flush(); unitStream << QString(autoChop()?"True":"False") << "/" << QString(gatherBerries()?"True":"False") << "/" << QString(huntChicken()?"True":"False") << "/" << QString(huntBoar()?"True":"False") << "/" << QString(showBowRange()?"True":"False") << "/"; unitStream << QString(trainNearTarget()?"True":"False") << "/"; unitStream << QString("%1").arg(rotation(),0,'g',8) << "/"; unitStream.flush(); unitFile.write(Utils::toBinary(equipHand()).constData()); unitStream << "/"; unitStream.flush(); unitFile.write(Utils::toBinary(equipOffhand()).constData()); unitStream << "/"; unitStream.flush(); unitFile.write(Utils::toBinary(equipHead()).constData()); unitStream << "/"; unitStream.flush(); unitFile.write(Utils::toBinary(equipBody()).constData()); unitStream << "/"; unitStream.flush(); unitFile.write(Utils::toBinary(equipFeet()).constData()); unitStream << "/"; unitStream.flush(); unitFile.write(Utils::toBinary(health()).constData()); unitStream << "/"; unitStream.flush(); // Dump some of the options in the file. for (unsigned int i = 0; i<52; i++) { unitStream << QString(option(i)?"True":"False") << "/"; } unitStream << timeToEat() << "/" << morale() << "/" << fatigue() << "/" << hunger() << "/"; // Dump more options in the file. for (unsigned int i = 52; i<52+12; i++) { unitStream << QString(option(i)?"True":"False") << "/"; } // Inventory Preferences for (int i = 0; i<inventoryPreferences()->length(); i++) { unitStream << inventoryPreferences()->at(i) << "/"; } // Inventory Items unitStream << inventoryItems()->length() << "/"; for (int i = 0; i<inventoryItems()->length(); i++) { unitStream << inventoryItems()->at(i) << "/"; } // Spare Inventory unitStream << spareInventory()->length() << "/"; for (int i = 0; i<spareInventory()->length(); i++) { unitStream << spareInventory()->at(i) << "/"; } // Patrol unitStream << patrolSetpoints()->length() << "/"; for (int i = 0; i<patrolSetpoints()->length(); i++) { unitStream << patrolSetpoints()->at(i) << "/"; } unitStream << patrolIndex() << "/"; unitStream << guardedUnit() << "/"; // Profession Experience for (int i = 0; i<professionEXP()->length(); i++) { unitStream << professionEXP()->at(i) << "/"; } unitStream << maxWeight() << "/"; unitStream << endl; unitStream.flush(); }