1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * Additional copyright for this file:
8  * Copyright (C) 1995-1997 Presto Studios, Inc.
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23  *
24  */
25 
26 #include "pegasus/gamestate.h"
27 #include "pegasus/ai/ai_area.h"
28 #include "pegasus/items/biochips/mapchip.h"
29 #include "pegasus/neighborhood/neighborhood.h"
30 
31 namespace Pegasus {
32 
33 MapChip *g_map = 0;
34 
MapChip(const ItemID id,const NeighborhoodID neighborhood,const RoomID room,const DirectionConstant direction)35 MapChip::MapChip(const ItemID id, const NeighborhoodID neighborhood, const RoomID room, const DirectionConstant direction) :
36 		BiochipItem(id, neighborhood, room, direction) {
37 	g_map = this;
38 	setItemState(kMapUnavailable);
39 }
40 
~MapChip()41 MapChip::~MapChip() {
42 	g_map = 0;
43 }
44 
writeToStream(Common::WriteStream * stream)45 void MapChip::writeToStream(Common::WriteStream *stream) {
46 	return _image.writeToStream(stream);
47 }
48 
readFromStream(Common::ReadStream * stream)49 void MapChip::readFromStream(Common::ReadStream *stream) {
50 	return _image.readFromStream(stream);
51 }
52 
select()53 void MapChip::select() {
54 	BiochipItem::select();
55 	moveToMapLocation(GameState.getCurrentNeighborhood(), GameState.getCurrentRoom(), GameState.getCurrentDirection());
56 	_image.show();
57 }
58 
takeSharedArea()59 void MapChip::takeSharedArea() {
60 	_image.show();
61 }
62 
giveUpSharedArea()63 void MapChip::giveUpSharedArea() {
64 	_image.hide();
65 }
66 
deselect()67 void MapChip::deselect() {
68 	BiochipItem::deselect();
69 	_image.unloadImage();
70 }
71 
moveToMapLocation(const NeighborhoodID neighborhood,const RoomID room,const DirectionConstant dir)72 void MapChip::moveToMapLocation(const NeighborhoodID neighborhood, const RoomID room, const DirectionConstant dir) {
73 	AirQuality airQuality;
74 
75 	if (g_neighborhood)
76 		airQuality = g_neighborhood->getAirQuality(room);
77 	else
78 		airQuality = kAirQualityGood;
79 
80 	switch (neighborhood) {
81 	case kMarsID:
82 		if (airQuality == kAirQualityVacuum) {
83 			if (room >= kMars35 && room <= kMars39) {
84 				setItemState(kMapEngaged);
85 				if (isSelected() && g_AIArea && g_AIArea->getMiddleAreaOwner() == kBiochipSignature)
86 					_image.loadGearRoomIfNecessary();
87 			} else {
88 				setItemState(kMapEngaged);
89 				if (isSelected() && g_AIArea && g_AIArea->getMiddleAreaOwner() == kBiochipSignature)
90 					_image.loadMazeIfNecessary();
91 			}
92 
93 			_image.moveToMapLocation(neighborhood, room, dir);
94 		} else {
95 			_image.unloadImage();
96 			setItemState(kMapUnavailable);
97 		}
98 		break;
99 	default:
100 		_image.unloadImage();
101 		setItemState(kMapUnavailable);
102 		break;
103 	}
104 }
105 
106 } // End of namespace Pegasus
107