3 * @brief
\83Q
\81[
\83\80\92\86\82Ì
\83N
\83\8a\81[
\83`
\83\83\81[
\82ð
\92è
\8b`
\82·
\82é
12 #include "GameSurface.h"
13 #include "GameLogger.h"
14 #include "GameWorld.h"
24 SOUL Creature::soulLevel[CREATURE_MAX_LEVEL] =
26 // 0 //
\83\8d\83X
\83g
\88æ
27 50, // Lv1
\83f
\83t
\83H
\83\8b\83g
\8aî
\8f\80\83\
\83E
\83\8b
28 100, // Lv2
\93\9e\92B
\83\
\83E
\83\8b
36 1280, // Lv10
\93\9e\92B
\83\
\83E
\83\8b
46 15000, // Lv20
\93\9e\92B
\83\
\83E
\83\8b
56 350000, // Lv30
\93\9e\92B
\83\
\83E
\83\8b
66 6000000, // Lv40
\93\9e\92B
\83\
\83E
\83\8b
76 90000000, // Lv50
\93\9e\92B
\83\
\83E
\83\8b
86 11100000000, // Lv60
\93\9e\92B
\83\
\83E
\83\8b
89 Creature::Creature(std::map<TAG, std::shared_ptr<Species>>::iterator speciesIt)
90 : GameInstance(), HaveSymbol(), HaveHp(), HaveGameTime(), HavePosition(), HaveInventory(), HaveSize()
93 SetSpeciesData(&(*speciesIt->second));
96 Creature::Creature(std::map<TAG, std::shared_ptr<Species>>::iterator& speciesIt, std::map<ID, std::shared_ptr<Field>>::iterator& fieldIt, MAP_LENGTH x, MAP_LENGTH y)
97 : GameInstance(), HaveSymbol(), HaveHp(), HaveGameTime(), HavePosition(fieldIt, x, y), HaveInventory(), HaveSize()
100 sightList.resize((this->sightRange * 2 + 1)*(this->sightRange * 2 + 1));
101 fieldIt->second->GetSight(sightList, this->sightRange, x, y);
102 SetSpeciesData(speciesIt->second.get());
105 Creature::Creature(void)
110 Creature::~Creature(void)
114 void Creature::SetSpeciesData(Species *speciesPtr)
116 std::normal_distribution<> distHeight(speciesPtr->GetHeight(), GameConstants::HeightStandardDeviation);
117 std::normal_distribution<> distWeight(speciesPtr->GetWeight(), GameConstants::WeightStandardDeviation);
118 this->name = speciesPtr->GetName();
119 this->symbol = speciesPtr->GetSymbol();
120 this->symbolColor = speciesPtr->GetSymbolColor();
121 this->currentSoul = this->maxSoul = speciesPtr->GetBaseSoul();
122 this->currentFeed = speciesPtr->GetBaseFeed() * 3 / 4;
123 this->maxFeed = speciesPtr->GetBaseFeed();
124 this->weight = distWeight(Dice::mt);
125 this->height = distHeight(Dice::mt);
126 this->campTag = TAG_VARIABLE;
127 this->firstRace = speciesPtr->GetFirstRaceTag();
128 this->secondRace = speciesPtr->GetSecondtRaceTag();
131 void Creature::WipeData(void)
133 GameInstance::WipeData();
134 HaveSymbol::WipeData();
135 HaveSize::WipeData();
136 this->currentMp = this->maxMp = this->maxMaxMp = 10;
137 this->currentSoul = this->maxSoul = Creature::soulLevel[0];
138 this->currentDiscipilne.SetPoint(0, 0, 0, 0, 0);
139 this->firstRace = "";
140 this->secondRace = "";
141 this->height = 160.0f;
142 this->weight = 50.0f;
143 this->divineLevel = -1;
144 savings.Set(10, 10, 10);
145 this->currentFeed = this->maxFeed = 20000;
147 currentStatus.Set(8, 8, 8, 8, 8, 8);
148 maxStatus.Set(8, 8, 8, 8, 8, 8);
149 maxMaxStatus.Set(20, 20, 20, 20, 20, 20);
151 sightRange = BASE_SIGHT_RANGE;
154 this->currentHp = this->maxHp = this->GetNorMaxHP();
156 this->skillExpList.clear();
159 this->campTag = TAG_VARIABLE;
161 //this->fieldID = -1;
162 //this->position.Set(0, 0);
164 this->skillExpList.clear();
167 this->symbolColor.SetColor(255, 255, 255, 255);
171 bool Creature::IsAlive(void)
173 return this->currentHp > 0 && this->currentSoul > 0;
176 bool Creature::TakeEffect(Effect *effectPtr, POWER amount)
178 if(!effectPtr) this->CalcHP(-amount);
182 void Creature::die(void)
186 void Creature::calcHPTable(void)
189 HP hitDice = this->GetSize();
190 HP minLine = hitDice * (CREATURE_MAX_LEVEL + 4) * 70 / 100;
191 HP maxLine = hitDice * (CREATURE_MAX_LEVEL + 4) * 130 / 100;
193 if(hitDice <= 0) hitDice = 1;
197 this->hpTable[0] = hitDice + Dice::Cast(3, hitDice);
198 for(lev = 0; lev < CREATURE_MAX_LEVEL - 1; lev++)
200 this->hpTable[lev + 1] = this->hpTable[lev] + Dice::Rand1(hitDice);
203 while(this->hpTable[CREATURE_MAX_LEVEL - 1] < minLine && this->hpTable[CREATURE_MAX_LEVEL - 1] > maxLine);
206 void Creature::calcMP(MP amount)
208 this->currentMp += amount;
209 if(this->currentMp > this->maxMp) this->currentMp = this->maxMp;
210 if(this->currentMp < 0) this->currentMp = 0;
213 void Creature::setMP(MP amount)
215 this->currentMp += amount;
216 if(this->currentMp > this->maxMp) this->currentMp = this->maxMp;
217 if(this->currentMp < 0) this->currentMp = 0;
220 LEVEL Creature::GetLevel(void)
223 if(this->currentSoul <= 0) return 0;
224 if(this->currentSoul < Creature::soulLevel[1]) return 1;
225 for(level = 2; level < CREATURE_MAX_LEVEL; level++)
227 if(Creature::soulLevel[level - 1] > this->currentSoul) return level;
232 HP Creature::GetNorMaxHP(void)
234 return this->hpTable[this->GetLevel()];
237 MP Creature::GetCurMP(void)
239 return this->currentMp;
242 MP Creature::GetMaxMP(void)
247 MP Creature::GetNorMaxMP(void)
249 return this->maxMaxMp;
252 AC Creature::GetArmorSaving(void)
254 return this->savings.GetArmor();
257 EV Creature::GetEvasionSaving(void)
259 return this->savings.GetEvasion();
262 VO Creature::GetVolitionSaving(void)
264 return this->savings.GetVolition();
267 SOUL Creature::GetCurrentSoul(void)
269 return this->currentSoul;
272 SOUL Creature::GetMaxSoul(void)
274 return this->maxSoul;
277 BASE_STATUS Creature::GetCurrentStatus(CREATURE_STATUS stat)
279 return currentStatus.Get(stat);
282 BASE_STATUS Creature::GetMaxStatus(CREATURE_STATUS stat)
284 return maxStatus.Get(stat);
287 BASE_STATUS Creature::GetMaxMAXStatus(CREATURE_STATUS stat)
289 return maxMaxStatus.Get(stat);
292 DISCIPLINE_POINT Creature::GetDiscipilnePoint(DISCIPLINE_TYPE typ)
294 return this->currentDiscipilne.GetPoint(typ);
297 DISCIPLINE_POINT Creature::GetDiscipilneRank(DISCIPLINE_TYPE typ)
299 return this->currentDiscipilne.GetRank(typ);
302 void Creature::GainSoul(SOUL amount)
305 if(this->currentSoul < this->maxSoul)
307 diff = this->maxSoul - this->currentSoul;
310 this->maxSoul += diff / 20;
311 this->currentSoul = this->maxSoul;
316 this->maxSoul += amount / 20;
317 this->currentSoul += amount;
321 this->currentSoul += amount;
322 this->maxSoul += amount;
325 void Creature::LostSoul(SOUL amount)
327 this->currentSoul -= amount;
328 this->maxSoul -= amount / 20;
329 if(this->currentSoul < 1) this->die();
332 LEVEL Creature::GetDivineLevel(void)
334 return this->divineLevel;
337 FEED Creature::GetCurrentFeedPoint(void)
339 return this->currentFeed;
342 FEED Creature::GetMaxFeedPoint(void)
344 return this->maxFeed;
347 PLAY_EXIT_CODE Creature::TurnProcess(void)
349 Deeangband::GAME_COMMAND commandID;
350 commandID = GameElement::GameSurfacePtr->GetCommand(GameElement::GameWorldPtr->GetPlayerCreature());
351 return DoGameCommand(commandID);
354 PLAY_EXIT_CODE Creature::TimeProcess(void)
356 this->currentFeed -= 10;
357 return PLAY_EXIT_NONE;
360 TURN Creature::GetTurn(void)
365 SKILL_EXP Creature::GetSkillExp(TAG tag)
367 if(this->skillExpList.count(tag)) return this->skillExpList[tag];
371 TAG Creature::GetCampTag(void)
373 return this->campTag;
376 bool Creature::Melee(Creature *targetPtr)
378 this->TakeEffect(NULL, Dice::Cast(1, 6));
379 targetPtr->TakeEffect(NULL, Dice::Cast(1, 6));
383 bool Creature::PickUpItem(std::map<ID, std::shared_ptr<Item>>::iterator itemIt)
388 bool Creature::DropItem(std::map<ID, std::shared_ptr<Item>>::iterator itemIt)
393 bool Creature::EatItem(std::map<ID, std::shared_ptr<Item>>::iterator itemIt)
398 bool Creature::QuaffItem(std::map<ID, std::shared_ptr<Item>>::iterator itemIt)
403 bool Creature::ActivateItem(std::map<ID, std::shared_ptr<Item>>::iterator itemIt)
408 bool Creature::ThrowItem(std::map<ID, std::shared_ptr<Item>>::iterator itemIt)
413 bool Creature::ReadItem(std::map<ID, std::shared_ptr<Item>>::iterator itemIt)
418 bool Creature::CanEnterPosition(Floor *floorPtr)
420 //! @note
\88Ú
\93®
\90æ
\82Ì
\8fî
\95ñ
\82ª
\96³
\8cø(NULL)
\82È
\82ç
\82Î FALSE
421 if(!floorPtr) return false;
422 //! @note
\88Ú
\93®
\90æ
\82ª
\95Ç
\92n
\8c`
\82È
\82ç
\82Î FALSE
423 if(floorPtr->IsWall()) return false;
427 void Creature::UpdateFieldLore(void)
429 MAP_LENGTH x, y, cx, cy;
430 std::vector<Coordinates> rangeVec;
431 std::vector<Coordinates>::iterator rangeIt;
432 if(fieldPtr == NULL) return;
434 cx = this->position.GetX();
435 cy = this->position.GetY();
437 fieldPtr->GetSight(this->sightList, this->sightRange, cx, cy);
438 for(y = -this->sightRange; y < this->sightRange; y++)
440 for(x = -this->sightRange; x < this->sightRange; x++)
442 if(this->sightList[(y + this->sightRange) * (this->sightRange * 2 + 1) + x + this->sightRange]) this->GetLore()->PutFieldLore(0, cx + x, cy + y);
447 void Creature::XMLSave(std::string filename)
449 std::ofstream ofs(filename);
451 boost::archive::xml_oarchive oa(ofs);
452 oa << boost::serialization::make_nvp("Creature", *this);
455 bool Creature::InSight(MAP_LENGTH x, MAP_LENGTH y)
457 MAP_LENGTH rx = x - this->position.GetX();
458 MAP_LENGTH ry = y - this->position.GetY();
459 if(rx > this->sightRange || ry > this->sightRange || rx < -this->sightRange || ry < -this->sightRange)
464 if(x < 0 || y < 0 || x >= fieldPtr->GetWidth() || y >= fieldPtr->GetHeight())
469 return this->sightList[(ry + this->sightRange) * (this->sightRange * 2 + 1) + rx + this->sightRange];
472 ACTION_RESULT Creature::Walk(DIRECTION direction)
474 Coordinates nextPoint = this->position + Direction::DirectionVector[direction];
475 Square *nextSquarePtr = fieldPtr->GetSquare(nextPoint);
481 GameElement::GameSurfacePtr->GameMessage("
\8e\9e\8bó
\82Ì
\95Ç
\82É
\8ds
\82
\8eè
\82ð
\91j
\82Ü
\82ê
\82Ä
\82¢
\82é
\81B");
485 //! @note
\88Ú
\93®
\90æ
\82É
\95Ê
\82Ì
\83N
\83\8a\81[
\83`
\83\83\81[
\82ª
\91¶
\8dÝ
\82·
\82é
\82È
\82ç
\82Î
\94\92\95º
\8f\88\97\9d\82É
\88Ú
\8ds
\82µ
\82Ä FALSE
486 targetPtr = GameElement::GameWorldPtr->GetCreatureFromPosition(this->GetFieldID(), &nextPoint);
489 this->Melee(targetPtr);
490 GameElement::GameLoggerPtr->CreaturesCombated(this->GetName(), targetPtr->GetName());
494 floorPtr = nextSquarePtr->GetFloorPtr();
495 if(!this->CanEnterPosition(floorPtr))
497 GameElement::GameSurfacePtr->GameMessage("
\8ds
\82
\8eè
\82ð
\91j
\82Ü
\82ê
\82Ä
\82¢
\82é
\81B");
501 this->position = nextPoint;
502 this->UpdateFieldLore();
503 GameElement::GameSurfacePtr->GameMessage("");
507 ACTION_RESULT Creature::Open(DIRECTION direction)
513 ACTION_RESULT Creature::Close(DIRECTION direction)
519 ACTION_RESULT Creature::Disarm(DIRECTION direction)
525 PLAY_EXIT_CODE Creature::DoGameCommand(GAME_COMMAND command)
527 CREATURE_IT playerIt = GameElement::GameWorldPtr->GetPlayerCreature();
531 case GAME_COMMAND_VIEW_PLAYER_STATUS:
532 GameElement::GameSurfacePtr->ViewCreatureStatus(GameElement::GameWorldPtr->GetPlayerCreature()->second.get());
534 case GAME_COMMAND_DEBUG_XML_SAVE:
535 GameElement::GameWorldPtr->XMLSave();
536 GameElement::GameSurfacePtr->SystemMessage("XML
\82É
\95Û
\91¶
\82µ
\82Ü
\82µ
\82½
\81B");
538 case GAME_COMMAND_DEBUG_XML_LOAD:
539 GameElement::GameSurfacePtr->Draw(playerIt);
540 GameElement::GameWorldPtr->XMLLoad();
541 GameElement::GameSurfacePtr->SystemMessage("XML
\82©
\82ç
\8cÄ
\82Ñ
\8fo
\82µ
\82Ü
\82µ
\82½
\81B");
543 case GAME_COMMAND_EXIT:
544 return PLAY_EXIT_QUIT;
546 case GAME_COMMAND_NORTH:
547 playerIt->second.get()->Walk(DIRECTION_NORTH);
549 case GAME_COMMAND_NORTH_EAST:
550 playerIt->second.get()->Walk(DIRECTION_NORTH_EAST);
552 case GAME_COMMAND_EAST:
553 playerIt->second.get()->Walk(DIRECTION_EAST);
555 case GAME_COMMAND_SOUTH_EAST:
556 playerIt->second.get()->Walk(DIRECTION_SOUTH_EAST);
558 case GAME_COMMAND_SOUTH:
559 playerIt->second.get()->Walk(DIRECTION_SOUTH);
561 case GAME_COMMAND_SOUTH_WEST:
562 playerIt->second.get()->Walk(DIRECTION_SOUTH_WEST);
564 case GAME_COMMAND_WEST:
565 playerIt->second.get()->Walk(DIRECTION_WEST);
567 case GAME_COMMAND_NORTH_WEST:
568 playerIt->second.get()->Walk(DIRECTION_NORTH_WEST);
571 return PLAY_EXIT_NONE;