5 * Created by Alyssa Milburn on Tue May 25 2004.
6 * Copyright (c) 2004 Alyssa Milburn. All rights reserved.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
21 #include "CameraPart.h"
31 MetaRoom
* const Camera::getMetaRoom() {
32 return world
.map
.getMetaRoom(metaroom
);
35 void Camera::goToMetaRoom(unsigned int m
) {
37 moveTo(getMetaRoom()->x(), getMetaRoom()->y());
40 void Camera::goToMetaRoom(unsigned int m
, int _x
, int _y
, cameratransition transition
) {
48 void Camera::moveTo(int _x
, int _y
, panstyle pan
) {
49 // TODO: we don't break tracking according to trackingstyle.. atm updateTracking() calls this, also
53 MetaRoom
*m
= world
.map
.metaRoomAt(x
, y
);
62 void MainCamera::moveTo(int _x
, int _y
, panstyle pan
) {
65 Camera::moveTo(_x
, _y
, pan
);
67 for (std::vector
<AgentRef
>::iterator i
= floated
.begin(); i
!= floated
.end(); i
++) {
69 (*i
)->moveTo((*i
)->x
+ xoffset
, (*i
)->y
+ yoffset
);
73 void MainCamera::addFloated(AgentRef a
) {
78 void MainCamera::delFloated(AgentRef a
) {
80 std::vector
<AgentRef
>::iterator i
= std::find(floated
.begin(), floated
.end(), a
);
81 if (i
== floated
.end()) return;
85 void Camera::trackAgent(AgentRef a
, int xp
, int yp
, trackstyle s
, cameratransition transition
) {
91 void Camera::checkBounds() {
92 MetaRoom
*m
= getMetaRoom();
95 if (m
->wraparound()) {
96 // handle wrapping around, if necessary
97 if (x
< (int)m
->x()) {
98 moveTo(x
+ m
->width(), y
);
99 } else if (x
> (int)m
->x() + (int)m
->width()) {
100 moveTo(x
- m
->width(), y
);
103 // refuse to move beyond the boundaries
104 if (x
< (int)m
->x()) {
106 } else if (x
+ getWidth() > m
->x() + m
->width()) {
107 moveTo(m
->x() + m
->width() - getWidth(), y
);
111 // refuse to move beyond the boundaries
112 if (y
< (int)m
->y()) {
114 } else if (y
+ getHeight() > m
->y() + m
->height()) {
115 moveTo(x
, m
->y() + m
->height() - getHeight());
119 void Camera::tick() {
123 void Camera::updateTracking() {
124 if (!trackedagent
) return;
126 // TODO: not very intelligent :) also, are int casts correct?
127 int trackx
= (int)trackedagent
->x
+ ((int)trackedagent
->getWidth() / 2) - (int)(getWidth() / 2);
128 int tracky
= (int)trackedagent
->y
+ ((int)trackedagent
->getHeight() / 2) - (int)(getHeight() / 2);
129 moveTo(trackx
, tracky
);
132 unsigned int const MainCamera::getWidth() {
133 if ((!getMetaRoom()) || (backend
->getMainSurface()->getWidth() < getMetaRoom()->width()))
134 return backend
->getMainSurface()->getWidth();
136 return getMetaRoom()->width();
139 unsigned int const MainCamera::getHeight() {
140 if ((!getMetaRoom()) || (backend
->getMainSurface()->getHeight() < getMetaRoom()->height()))
141 return backend
->getMainSurface()->getHeight();
143 return getMetaRoom()->height();
146 unsigned int const PartCamera::getWidth() {
147 // TODO: update from ZOOM values
148 return part
->cameraWidth();
151 unsigned int const PartCamera::getHeight() {
152 // TODO: update from ZOOM values
153 return part
->cameraHeight();