OSDN Git Service

インクルード参照関係を一部修正。 / Fix some include references.
[deeangband/Deeangband-new.git] / Deeangband / GameWorld.cpp
1 /*!
2 * @file GameWorld.cpp
3 * @brief \83Q\81[\83\80\90¢\8aE\82ð\92è\8b`\82·\82é
4 * @date 2013/12/22
5 * @author Deskull
6 * 2013 Sikabane Works.
7 */
8
9 #include "stdafx.h"
10 #include "GameWorld.h"
11 #include "Deeangband.h"
12
13 #include "Coordinates.h"
14 #include "HaveGameTime.h"
15
16 #include "Air.h"
17 #include "Ability.h"
18 #include "Authority.h"
19 #include "Building.h"
20 #include "Camp.h"
21 #include "CreatureTrait.h"
22
23 #include "Creature.h"
24 #include "Dungeon.h"
25 #include "Effect.h"
26 #include "Floor.h"
27
28 #include "FixedArtifact.h"
29 #include "GameMessage.h"
30 #include "ItemBase.h"
31 #include "ItemEgo.h"
32 #include "ItemTrait.h"
33 #include "Karma.h"
34 #include "Lore.h"
35 #include "Quest.h"
36 #include "Race.h"
37 #include "Space.h"
38 #include "Skill.h"
39 #include "Species.h"
40 #include "StartingClass.h"
41 #include "TrapBase.h"
42
43 #include "Item.h"
44 #include "Field.h"
45 #include "Trap.h"
46
47 namespace Deeangband
48 {
49
50         GameWorld::GameWorld(void)
51         {
52                 int i;
53                 Dice::Initialize();
54                 XMLLoad();
55
56                 this->itemID = 0;
57                 this->trapID = 0;
58                 this->creatureID = 0;
59                 this->fieldID = 0;
60                 this->gameTime = 0;
61
62                 GameWorld::GenerateCreature("VANILLA_STIGMATIC", 0, 10, 10);
63                 GameWorld::GenerateCreature("VANILLA_RAVING_LUNATIC", 0, 5, 5);
64                 fieldList.emplace(0, boost::make_shared<Field>(dungeonList.find("VANILLA_WOMB"), 1));
65
66
67                 for(i = 0; i < MAX_KARMAS; i++)
68                 {
69                         karmaList.emplace("VANILLA_", boost::make_shared<Karma>());
70                 }
71
72                 playerIt = creatureList.begin()++;
73         }
74
75         GameWorld::~GameWorld(void)
76         {
77         }
78
79         bool GameWorld::GenerateCreature(TAG creatureTag)
80         {
81                 creatureList.emplace(this->creatureID, boost::make_shared<Creature>(speciesList.find(creatureTag)));
82                 //actionList.push_back(creatureList[this->creatureID]);
83                 do
84                 {
85                         this->creatureID++;
86                 } while(creatureList.find(this->creatureID) != creatureList.end());
87                 return true;
88         }
89
90         bool GameWorld::GenerateCreature(TAG creatureTag, ID fieldID, int x, int y)
91         {
92                 creatureList.emplace(this->creatureID, boost::make_shared<Creature>(speciesList.find(creatureTag), fieldID, x, y));
93                 //actionList.push_back(creatureList[this->creatureID]);
94                 creatureList[this->creatureID]->PlusWait(100, TRUE);
95                 do
96                 {
97                         this->creatureID++;
98                 } while(creatureList.find(this->creatureID) != creatureList.end());
99                 return true;
100         }
101
102         bool GameWorld::xmlSaveAir(void)
103         {
104                 std::ofstream ofs("lib-Vanilla\\Air.xml");
105                 assert(ofs);
106                 boost::archive::xml_oarchive oa(ofs);
107                 oa << boost::serialization::make_nvp("Airs", this->airList);
108                 ofs.close();
109                 return true;
110         }
111
112         bool GameWorld::xmlSaveAbility(void)
113         {
114                 std::ofstream ofs("lib-Vanilla\\Ability.xml");
115                 assert(ofs);
116                 boost::archive::xml_oarchive oa(ofs);
117                 oa << boost::serialization::make_nvp("Abilities", this->abilityList);
118                 ofs.close();
119                 return true;
120         }
121
122         bool GameWorld::xmlSaveAuthority(void)
123         {
124                 std::ofstream ofs("lib-Vanilla\\Authority.xml");
125                 assert(ofs);
126                 boost::archive::xml_oarchive oa(ofs);
127                 oa << boost::serialization::make_nvp("Authorities", this->authorityList);
128                 ofs.close();
129                 return true;
130         }
131
132         bool GameWorld::xmlSaveBuilding(void)
133         {
134                 std::ofstream ofs("lib-Vanilla\\Building.xml");
135                 assert(ofs);
136                 boost::archive::xml_oarchive oa(ofs);
137                 oa << boost::serialization::make_nvp("Buildings", this->buildingList);
138                 ofs.close();
139                 return true;
140         }
141
142         bool GameWorld::xmlSaveCamp(void)
143         {
144                 std::ofstream ofs("lib-Vanilla\\Camp.xml");
145                 assert(ofs);
146                 boost::archive::xml_oarchive oa(ofs);
147                 oa << boost::serialization::make_nvp("Camps", this->campList);
148                 ofs.close();
149                 return true;
150         }
151
152         bool GameWorld::xmlSaveCreatureTrait(void)
153         {
154                 std::ofstream ofs("lib-Vanilla\\CreatureTrait.xml");
155                 assert(ofs);
156                 boost::archive::xml_oarchive oa(ofs);
157                 oa << boost::serialization::make_nvp("CreatureTraits", this->creatureTraitList);
158                 ofs.close();
159                 return true;
160         }
161
162         bool GameWorld::xmlSaveDungeon(void)
163         {
164                 std::ofstream ofs("lib-Vanilla\\Dungeon.xml");
165                 assert(ofs);
166                 boost::archive::xml_oarchive oa(ofs);
167                 oa << boost::serialization::make_nvp("Dungeons", this->dungeonList);
168                 ofs.close();
169                 return true;
170         }
171
172         bool GameWorld::xmlSaveEffect(void)
173         {
174                 std::ofstream ofs("lib-Vanilla\\Effect.xml");
175                 assert(ofs);
176                 boost::archive::xml_oarchive oa(ofs);
177                 oa << boost::serialization::make_nvp("Effects", this->effectList);
178                 ofs.close();
179                 return true;
180         }
181
182         bool GameWorld::xmlSaveFloor(void)
183         {
184                 std::ofstream ofs("lib-Vanilla\\Floor.xml");
185                 assert(ofs);
186                 boost::archive::xml_oarchive oa(ofs);
187                 oa << boost::serialization::make_nvp("Floors", this->floorList);
188                 ofs.close();
189                 return true;
190         }
191
192         bool GameWorld::xmlSaveFixedArtifact(void)
193         {
194                 std::ofstream ofs("lib-Vanilla\\FixedArtifact.xml");
195                 assert(ofs);
196                 boost::archive::xml_oarchive oa(ofs);
197                 oa << boost::serialization::make_nvp("FixedArtifacts", this->fixedArtifactList);
198                 ofs.close();
199                 return true;
200         }
201
202         bool GameWorld::xmlSaveItemBase(void)
203         {
204                 std::ofstream ofs("lib-Vanilla\\ItemBase.xml");
205                 assert(ofs);
206                 boost::archive::xml_oarchive oa(ofs);
207                 oa << boost::serialization::make_nvp("ItemBases", this->itemBaseList);
208                 ofs.close();
209                 return true;
210         }
211
212         bool GameWorld::xmlSaveItemEgo(void)
213         {
214                 std::ofstream ofs("lib-Vanilla\\ItemEgo.xml");
215                 assert(ofs);
216                 boost::archive::xml_oarchive oa(ofs);
217                 oa << boost::serialization::make_nvp("ItemEgos", this->itemEgoList);
218                 ofs.close();
219                 return true;
220         }
221
222         bool GameWorld::xmlSaveItemTrait(void)
223         {
224                 std::ofstream ofs("lib-Vanilla\\ItemTrait.xml");
225                 assert(ofs);
226                 boost::archive::xml_oarchive oa(ofs);
227                 oa << boost::serialization::make_nvp("ItemTraits", this->itemTraitList);
228                 ofs.close();
229                 return true;
230         }
231
232         bool GameWorld::xmlSaveKarma(void)
233         {
234                 std::ofstream ofs("lib-Vanilla\\Karma.xml");
235                 assert(ofs);
236                 boost::archive::xml_oarchive oa(ofs);
237                 oa << boost::serialization::make_nvp("Karmas", this->karmaList);
238                 ofs.close();
239                 return true;
240         }
241
242         bool GameWorld::xmlSaveQuest(void)
243         {
244                 std::ofstream ofs("lib-Vanilla\\Quest.xml");
245                 assert(ofs);
246                 boost::archive::xml_oarchive oa(ofs);
247                 oa << boost::serialization::make_nvp("Quests", this->questList);
248                 ofs.close();
249                 return true;
250         }
251
252         bool GameWorld::xmlSaveRace(void)
253         {
254                 std::ofstream ofs("lib-Vanilla\\Race.xml");
255                 assert(ofs);
256                 boost::archive::xml_oarchive oa(ofs);
257                 oa << boost::serialization::make_nvp("Races", this->raceList);
258                 ofs.close();
259                 return true;
260         }
261
262         bool GameWorld::xmlSaveSpace(void)
263         {
264                 std::ofstream ofs("lib-Vanilla\\Space.xml");
265                 assert(ofs);
266                 boost::archive::xml_oarchive oa(ofs);
267                 oa << boost::serialization::make_nvp("Spaces", this->spaceList);
268                 ofs.close();
269                 return true;
270         }
271
272         bool GameWorld::xmlSaveSkill(void)
273         {
274                 std::ofstream ofs("lib-Vanilla\\Skill.xml");
275                 assert(ofs);
276                 boost::archive::xml_oarchive oa(ofs);
277                 oa << boost::serialization::make_nvp("Skills", this->skillList);
278                 ofs.close();
279                 return true;
280         }
281
282         bool GameWorld::xmlSaveSpecie(void)
283         {
284                 std::ofstream ofs("lib-Vanilla\\Specie.xml");
285                 assert(ofs);
286                 boost::archive::xml_oarchive oa(ofs);
287                 oa << boost::serialization::make_nvp("Species", this->speciesList);
288                 ofs.close();
289                 return true;
290         }
291
292         bool GameWorld::xmlSaveStartingClass(void)
293         {
294                 std::ofstream ofs("lib-Vanilla\\StartingClass.xml");
295                 assert(ofs);
296                 boost::archive::xml_oarchive oa(ofs);
297                 oa << boost::serialization::make_nvp("StartingClasses", this->startingClassList);
298                 ofs.close();
299                 return true;
300         }
301
302         bool GameWorld::xmlSaveTrapBase(void)
303         {
304                 std::ofstream ofs("lib-Vanilla\\TrapBase.xml");
305                 assert(ofs);
306                 boost::archive::xml_oarchive oa(ofs);
307                 oa << boost::serialization::make_nvp("TrapBases", this->trapBaseList);
308                 ofs.close();
309                 return true;
310         }
311
312         bool GameWorld::XMLSave(void)
313         {
314                 this->xmlSaveAir();
315                 this->xmlSaveAbility();
316                 this->xmlSaveAuthority();
317                 this->xmlSaveBuilding();
318                 this->xmlSaveCamp();
319                 this->xmlSaveCreatureTrait();
320                 this->xmlSaveDungeon();
321                 this->xmlSaveEffect();
322                 this->xmlSaveFloor();
323                 this->xmlSaveFixedArtifact();
324                 this->xmlSaveItemBase();
325                 this->xmlSaveItemEgo();
326                 this->xmlSaveItemTrait();
327                 this->xmlSaveKarma();
328                 this->xmlSaveQuest();
329                 this->xmlSaveRace();
330                 this->xmlSaveSpace();
331                 this->xmlSaveSkill();
332                 this->xmlSaveSpecie();
333                 this->xmlSaveStartingClass();
334                 this->xmlSaveTrapBase();
335                 return true;
336         }
337
338         bool GameWorld::xmlLoadAir()
339         {
340                 std::ifstream ifs("lib-Vanilla\\Air.xml");
341                 assert(ifs);
342                 boost::archive::xml_iarchive ia(ifs);
343                 ia >> BOOST_SERIALIZATION_NVP(airList);
344                 return true;
345         }
346
347         bool GameWorld::xmlLoadAbility()
348         {
349                 std::ifstream ifs("lib-Vanilla\\Ability.xml");
350                 assert(ifs);
351                 boost::archive::xml_iarchive ia(ifs);
352                 ia >> BOOST_SERIALIZATION_NVP(abilityList);
353                 return true;
354         }
355
356         bool GameWorld::xmlLoadAuthority()
357         {
358                 std::ifstream ifs("lib-Vanilla\\Authority.xml");
359                 assert(ifs);
360                 boost::archive::xml_iarchive ia(ifs);
361                 ia >> BOOST_SERIALIZATION_NVP(authorityList);
362                 return true;
363         }
364
365         bool GameWorld::xmlLoadBuilding()
366         {
367                 std::ifstream ifs("lib-Vanilla\\Building.xml");
368                 assert(ifs);
369                 boost::archive::xml_iarchive ia(ifs);
370                 ia >> BOOST_SERIALIZATION_NVP(buildingList);
371                 return true;
372         }
373
374         bool GameWorld::xmlLoadCamp()
375         {
376                 std::ifstream ifs("lib-Vanilla\\Camp.xml");
377                 assert(ifs);
378                 boost::archive::xml_iarchive ia(ifs);
379                 ia >> BOOST_SERIALIZATION_NVP(campList);
380                 return true;
381         }
382
383         bool GameWorld::xmlLoadCreatureTrait()
384         {
385                 std::ifstream ifs("lib-Vanilla\\CreatureTrait.xml");
386                 assert(ifs);
387                 boost::archive::xml_iarchive ia(ifs);
388                 ia >> BOOST_SERIALIZATION_NVP(creatureTraitList);
389                 return true;
390         }
391
392         bool GameWorld::xmlLoadDungeon()
393         {
394                 std::ifstream ifs("lib-Vanilla\\Dungeon.xml");
395                 assert(ifs);
396                 boost::archive::xml_iarchive ia(ifs);
397                 ia >> BOOST_SERIALIZATION_NVP(dungeonList);
398                 return true;
399         }
400
401         bool GameWorld::xmlLoadEffect()
402         {
403                 std::ifstream ifs("lib-Vanilla\\Effect.xml");
404                 assert(ifs);
405                 boost::archive::xml_iarchive ia(ifs);
406                 ia >> BOOST_SERIALIZATION_NVP(effectList);
407                 return true;
408         }
409
410         bool GameWorld::xmlLoadFloor()
411         {
412                 std::ifstream ifs("lib-Vanilla\\Floor.xml");
413                 assert(ifs);
414                 boost::archive::xml_iarchive ia(ifs);
415                 ia >> BOOST_SERIALIZATION_NVP(floorList);
416                 return true;
417         }
418
419         bool GameWorld::xmlLoadFixedArtifact()
420         {
421                 std::ifstream ifs("lib-Vanilla\\FixedArtifact.xml");
422                 assert(ifs);
423                 boost::archive::xml_iarchive ia(ifs);
424                 ia >> BOOST_SERIALIZATION_NVP(fixedArtifactList);
425                 return true;
426         }
427
428         bool GameWorld::xmlLoadItemBase()
429         {
430                 std::ifstream ifs("lib-Vanilla\\ItemBase.xml");
431                 assert(ifs);
432                 boost::archive::xml_iarchive ia(ifs);
433                 ia >> BOOST_SERIALIZATION_NVP(itemBaseList);
434                 return true;
435         }
436
437         bool GameWorld::xmlLoadItemEgo()
438         {
439                 std::ifstream ifs("lib-Vanilla\\ItemEgo.xml");
440                 assert(ifs);
441                 boost::archive::xml_iarchive ia(ifs);
442                 ia >> BOOST_SERIALIZATION_NVP(itemEgoList);
443                 return true;
444         }
445
446         bool GameWorld::xmlLoadItemTrait()
447         {
448                 std::ifstream ifs("lib-Vanilla\\ItemTrait.xml");
449                 assert(ifs);
450                 boost::archive::xml_iarchive ia(ifs);
451                 ia >> BOOST_SERIALIZATION_NVP(itemTraitList);
452                 return true;
453         }
454
455         bool GameWorld::xmlLoadKarma()
456         {
457                 std::ifstream ifs("lib-Vanilla\\Karma.xml");
458                 assert(ifs);
459                 boost::archive::xml_iarchive ia(ifs);
460                 ia >> BOOST_SERIALIZATION_NVP(karmaList);
461                 return true;
462         }
463
464         bool GameWorld::xmlLoadQuest()
465         {
466                 std::ifstream ifs("lib-Vanilla\\Quest.xml");
467                 assert(ifs);
468                 boost::archive::xml_iarchive ia(ifs);
469                 ia >> BOOST_SERIALIZATION_NVP(questList);
470                 return true;
471         }
472
473         bool GameWorld::xmlLoadRace()
474         {
475                 std::ifstream ifs("lib-Vanilla\\Race.xml");
476                 assert(ifs);
477                 boost::archive::xml_iarchive ia(ifs);
478                 ia >> BOOST_SERIALIZATION_NVP(raceList);
479                 return true;
480         }
481
482         bool GameWorld::xmlLoadSpace()
483         {
484                 std::ifstream ifs("lib-Vanilla\\Space.xml");
485                 assert(ifs);
486                 boost::archive::xml_iarchive ia(ifs);
487                 ia >> BOOST_SERIALIZATION_NVP(spaceList);
488                 return true;
489         }
490
491         bool GameWorld::xmlLoadSkill()
492         {
493                 std::ifstream ifs("lib-Vanilla\\Skill.xml");
494                 assert(ifs);
495                 boost::archive::xml_iarchive ia(ifs);
496                 ia >> BOOST_SERIALIZATION_NVP(skillList);
497                 return true;
498         }
499
500         bool GameWorld::xmlLoadSpecie()
501         {
502                 std::ifstream ifs("lib-Vanilla\\Specie.xml");
503                 assert(ifs);
504                 boost::archive::xml_iarchive ia(ifs);
505                 ia >> BOOST_SERIALIZATION_NVP(speciesList);
506                 return true;
507         }
508
509         bool GameWorld::xmlLoadStartingClass()
510         {
511                 std::ifstream ifs("lib-Vanilla\\StartingClass.xml");
512                 assert(ifs);
513                 boost::archive::xml_iarchive ia(ifs);
514                 ia >> BOOST_SERIALIZATION_NVP(startingClassList);
515                 return true;
516         }
517
518         bool GameWorld::xmlLoadTrapBase()
519         {
520                 std::ifstream ifs("lib-Vanilla\\TrapBase.xml");
521                 assert(ifs);
522                 boost::archive::xml_iarchive ia(ifs);
523                 ia >> BOOST_SERIALIZATION_NVP(trapBaseList);
524                 return true;
525         }
526
527         void GameWorld::XMLLoad(void)
528         {
529                 this->xmlLoadAir();
530                 this->xmlLoadAbility();
531                 this->xmlLoadAuthority();
532                 this->xmlLoadBuilding();
533                 this->xmlLoadCamp();
534                 this->xmlLoadCreatureTrait();
535                 this->xmlLoadDungeon();
536                 this->xmlLoadEffect();
537                 this->xmlLoadFloor();
538                 this->xmlLoadFixedArtifact();
539                 this->xmlLoadItemBase();
540                 this->xmlLoadItemEgo();
541                 this->xmlLoadItemTrait();
542                 this->xmlLoadKarma();
543                 this->xmlLoadQuest();
544                 this->xmlLoadRace();
545                 this->xmlLoadSpace();
546                 this->xmlLoadSkill();
547                 this->xmlLoadSpecie();
548                 this->xmlLoadStartingClass();
549                 this->xmlLoadTrapBase();
550         }
551
552         Authority *GameWorld::GetAuthority(TAG tag)
553         {
554                 return &(*authorityList[tag]);
555         }
556
557         CreatureTrait *GameWorld::GetCreatureTrait(TAG tag)
558         {
559                 return &(*creatureTraitList[tag]);
560         }
561
562         Effect *GameWorld::GetEffect(TAG tag)
563         {
564                 return &(*effectList[tag]);
565         }
566
567         FixedArtifact *GameWorld::GetFixedArtifact(TAG tag)
568         {
569                 return &(*fixedArtifactList[tag]);
570         }
571
572         Floor *GameWorld::GetFloor(TAG tag)
573         {
574                 return &(*floorList[tag]);
575         }
576
577         ItemBase *GameWorld::GetItemBase(TAG tag)
578         {
579                 return &(*itemBaseList[tag]);
580         }
581
582         ItemEgo *GameWorld::GetItemEgo(TAG tag)
583         {
584                 return &(*itemEgoList[tag]);
585         }
586
587         ItemTrait *GameWorld::GetItemTrait(TAG tag)
588         {
589                 return &(*itemTraitList[tag]);
590         }
591
592         Karma *GameWorld::GetKarma(TAG tag)
593         {
594                 return &(*karmaList[tag]);
595         }
596
597         Skill *GameWorld::GetSkill(TAG tag)
598         {
599                 return &(*skillList[tag]);
600         }
601
602         Species *GameWorld::GetSpecies(TAG tag)
603         {
604                 return &(*speciesList[tag]);
605         }
606
607         TrapBase *GameWorld::GetTrapBase(TAG tag)
608         {
609                 return &(*trapBaseList[tag]);
610         }
611
612         Building *GameWorld::GetBuilding(TAG tag)
613         {
614                 return &(*buildingList[tag]);
615         }
616
617         Camp *GameWorld::GetCamp(TAG tag)
618         {
619                 return &(*campList[tag]);
620         }
621
622         Dungeon *GameWorld::GetDungeon(TAG tag)
623         {
624                 return &(*dungeonList[tag]);
625         }
626
627         Item *GameWorld::GetItem(ID id)
628         {
629                 return &(*itemList[id]);
630         }
631
632         Field *GameWorld::GetField(ID id)
633         {
634                 return &(*fieldList[id]);
635         }
636
637         Creature *GameWorld::GetCreature(ID id)
638         {
639                 return &(*creatureList[id]);
640         }
641
642         std::map<TAG, boost::shared_ptr<Ability>> *GameWorld::GetAbilityList(void)
643         {
644                 return &(this->abilityList);
645         }
646
647         Quest *GameWorld::GetQuest(TAG tag)
648         {
649                 return &(*questList[tag]);
650         }
651
652         GAME_TIME GameWorld::GetGameTime(void)
653         {
654                 return this->gameTime;
655         }
656
657         void GameWorld::WipeCreature(ID id)
658         {
659                 creatureList.erase(id);
660         }
661
662         CREATURE_IT GameWorld::GetPlayerCreature(void)
663         {
664                 return this->playerIt;
665         }
666
667         ACTION_LIST* GameWorld::GetActionList(void)
668         {
669                 return &(this->actionList);
670         }
671
672         Creature *GameWorld::GetCreatureFromPosition(ID fieldID, Coordinates *positionPtr)
673         {
674                 CREATURE_IT creatureIt;
675                 creatureIt = this->creatureList.begin();
676                 while(creatureIt != this->creatureList.end())
677                 {
678                         if(creatureIt->second->GetPosition() == *positionPtr && fieldID == creatureIt->second->GetFieldID()) return (creatureIt->second.get());
679                         creatureIt++;
680                 }
681                 return NULL;
682                 
683         }
684
685         Floor *GameWorld::GetFloorFromPosition(ID fieldID, Coordinates *positionPtr)
686         {
687                 Square *square = fieldList[fieldID].get()->GetSquare(positionPtr->GetX(), positionPtr->GetY());
688                 if(!square) return NULL;                
689                 TAG tag = square->GetFloorTag();
690                 return &(*floorList[tag]);
691         }
692
693         std::map<TAG, boost::shared_ptr<Floor>> *GameWorld::GetFloorList(void)
694         {
695                 return &floorList;
696         }
697
698         std::map<TAG, boost::shared_ptr<Species>> *GameWorld::GetSpeciesList(void)
699         {
700                 return &speciesList;
701         }
702
703         CREATURE_LIST *GameWorld::GetCreatureList(void)
704         {
705                 return &creatureList;
706         }
707
708 }