Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
blob: d9a7c4f1fde74f856f76957fcd7acf3dbad3ac16 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
   base/savegame.cc
   This file is part of the Osirion project and is distributed under
   the terms and conditions of the GNU General Public License version 2
*/

#include "base/savegame.h"
#include "base/ship.h"

namespace game {
	
void SaveGame::player_to_stream(core::Player *player, std::ostream & os)
{
	if (!os.good())
		return;
	
	os << "[player]" << std::endl;
	// player name
	os << "name=" << player->name() << std::endl;
	// credit
	os << "credits=" << player->credits() << std::endl;
	os << std::endl;
}

void SaveGame::ship_to_stream(Ship *ship, std::ostream & os)
{
	if (!os.good())
		return;
	
	os << "[ship]" << std::endl;
	os << "model=" << ship->shipmodel()->label() << std::endl;
	// ship zone
	os << "zone=" << ship->zone()->label()<< std::endl;
	// ship location
	os << "location=" << ship->location() << std::endl;
	// ship orientation
	os << "forward=" << ship->axis().forward() << std::endl;
	os << "left=" << ship->axis().left() << std::endl;
	os << "up=" << ship->axis().up() << std::endl;
	// ship is docked at spawn on load
	os << "docked=";
	if (ship->dock() && (ship->dock() == ship->spawn())) {
		os << "yes";
	} else if (ship->state() == core::Entity::Destroyed) {
		os << "yes";
	} else {
		os << "no";
	}
	os << std::endl;
	// ship spawn
	os << "spawn=";
	if (ship->spawn()) {
		os << ship->spawn()->zone()->label() << ":" << ship->spawn()->label();
	}
	os << std::endl;
}

void SaveGame::inventory_to_stream(core::Inventory *inventory, std::ostream & os)
{
	if (!os.good())
		return;
	
	if(!inventory)
		return;
	
	for (core::Inventory::Items::iterator it = inventory->items().begin(); 
			it != inventory->items().end(); ++it) 
	{
		const core::Item *item = (*it);
		
		os << std::endl;
		os << "[item]" << std::endl;
		// item InfoType label
		os << "type=" << item->info()->type()->label() << std::endl;
		// item Info label
		os << "label=" << item->info()->label() << std::endl;
		os << "amount=" << item->amount() << std::endl;
		os << "price=" << item->price() << std::endl;
		os << "tradeable=" << (item->flag_is_set(core::Item::Tradeable) ? "yes" : "no") << std::endl;
	}
}

} // namespace game