- removed cell marker from popup menu and moved to hotkeys (f2 add f3 remove)

- added a new experiemntal feature called 'follow unit'. select 1 unit then press f4 and when the unit moves the camera tries to look from the units perspective. To turn this off select no unit and press f4.
This commit is contained in:
Mark Vejvoda 2012-09-24 17:13:27 +00:00
parent bde7b5d94d
commit 9e75b9144c
9 changed files with 114 additions and 44 deletions

View File

@ -48,5 +48,8 @@ ReloadINI=f5
TogglePhotoMode=f8
SwitchLanguage=L
SaveGame=f11
BookmarkAdd=f2
BookmarkRemove=f3
CameraFollowSelectedUnit=f4
; === propertyMap File ===

View File

@ -132,8 +132,8 @@ Game::Game() : ProgramState(NULL) {
pauseGamePopupMenuIndex = -1;
saveGamePopupMenuIndex = -1;
loadGamePopupMenuIndex = -1;
markCellPopupMenuIndex = -1;
unmarkCellPopupMenuIndex = -1;
//markCellPopupMenuIndex = -1;
//unmarkCellPopupMenuIndex = -1;
keyboardSetupPopupMenuIndex = -1;
disconnectPlayerPopupMenuIndex = -1;
@ -197,8 +197,8 @@ void Game::resetMembers() {
pauseGamePopupMenuIndex = -1;
saveGamePopupMenuIndex = -1;
loadGamePopupMenuIndex = -1;
markCellPopupMenuIndex = -1;
unmarkCellPopupMenuIndex = -1;
//markCellPopupMenuIndex = -1;
//unmarkCellPopupMenuIndex = -1;
keyboardSetupPopupMenuIndex = -1;
disconnectPlayerPopupMenuIndex = -1;
@ -1307,10 +1307,10 @@ void Game::setupPopupMenus(bool checkClientAdminOverrideOnly) {
joinTeamPopupMenuIndex = menuItems.size()-1;
}
menuItems.push_back(lang.get("MarkCell"));
markCellPopupMenuIndex = menuItems.size()-1;
menuItems.push_back(lang.get("UnMarkCell"));
unmarkCellPopupMenuIndex = menuItems.size()-1;
//menuItems.push_back(lang.get("MarkCell"));
//markCellPopupMenuIndex = menuItems.size()-1;
//menuItems.push_back(lang.get("UnMarkCell"));
//unmarkCellPopupMenuIndex = menuItems.size()-1;
if(allowAdminMenuItems == true){
menuItems.push_back(lang.get("PauseResumeGame"));
@ -2153,6 +2153,26 @@ void Game::tryPauseToggle(bool pauseValue) {
}
}
void Game::startMarkCell() {
int totalMarkedCellsForPlayer = 0;
for(std::map<Vec2i, MarkedCell>::iterator iterMap = mapMarkedCellList.begin();
iterMap != mapMarkedCellList.end(); ++iterMap) {
MarkedCell &bm = iterMap->second;
if(bm.getPlayerIndex() == world.getThisFaction()->getStartLocationIndex()) {
totalMarkedCellsForPlayer++;
}
}
const int MAX_MARKER_COUNT = 5;
if(totalMarkedCellsForPlayer < MAX_MARKER_COUNT) {
isMarkCellEnabled = true;
}
else {
Lang &lang= Lang::getInstance();
console.addLine(lang.get("MaxMarkerCount") + " " + intToStr(MAX_MARKER_COUNT));
}
}
void Game::mouseDownLeft(int x, int y) {
if(this->masterserverMode == true) {
return;
@ -2309,28 +2329,12 @@ void Game::mouseDownLeft(int x, int y) {
else if(result.first == saveGamePopupMenuIndex){
saveGame();
}
else if(result.first == markCellPopupMenuIndex) {
int totalMarkedCellsForPlayer = 0;
for(std::map<Vec2i, MarkedCell>::iterator iterMap = mapMarkedCellList.begin();
iterMap != mapMarkedCellList.end(); ++iterMap) {
MarkedCell &bm = iterMap->second;
if(bm.getPlayerIndex() == world.getThisFaction()->getStartLocationIndex()) {
totalMarkedCellsForPlayer++;
}
}
const int MAX_MARKER_COUNT = 5;
if(totalMarkedCellsForPlayer < MAX_MARKER_COUNT) {
isMarkCellEnabled = true;
}
else {
Lang &lang= Lang::getInstance();
console.addLine(lang.get("MaxMarkerCount") + " " + intToStr(MAX_MARKER_COUNT));
}
}
else if(result.first == unmarkCellPopupMenuIndex) {
isUnMarkCellEnabled = true;
}
//else if(result.first == markCellPopupMenuIndex) {
// startMarkCell();
//}
//else if(result.first == unmarkCellPopupMenuIndex) {
// isUnMarkCellEnabled = true;
//}
}
else if(popupMenuSwitchTeams.mouseClick(x, y)) {
//popupMenuSwitchTeams
@ -3066,6 +3070,23 @@ void Game::processInputText(string text, bool cancelled) {
}
}
void Game::startCameraFollowUnit() {
Selection *selection= gui.getSelectionPtr();
if(selection->getCount() == 1) {
Unit *currentUnit = selection->getUnitPtr(0);
if(currentUnit != NULL) {
currentCameraFollowUnit = currentUnit;
currentCameraFollowUnit->setCameraFollowUnit(true);
}
}
else {
if(currentCameraFollowUnit != NULL) {
currentCameraFollowUnit->setCameraFollowUnit(false);
currentCameraFollowUnit = NULL;
}
}
}
void Game::keyDown(SDL_KeyboardEvent key) {
if(this->masterserverMode == true) {
return;
@ -3106,7 +3127,8 @@ void Game::keyDown(SDL_KeyboardEvent key) {
//printf("SDL [%d] key [%d][%d]\n",configKeys.getSDLKey("SetMarker"),key.keysym.unicode,key.keysym.sym);
bool setMarkerKeyAllowsModifier = false;
if(configKeys.getSDLKey("SetMarker") == SDLK_RALT || configKeys.getSDLKey("SetMarker") == SDLK_LALT) {
if( configKeys.getSDLKey("SetMarker") == SDLK_RALT ||
configKeys.getSDLKey("SetMarker") == SDLK_LALT) {
setMarkerKeyAllowsModifier = true;
}
//if(key == configKeys.getCharKey("RenderNetworkStatus")) {
@ -3188,6 +3210,11 @@ void Game::keyDown(SDL_KeyboardEvent key) {
//reset camera mode to normal
//else if(key == configKeys.getCharKey("ResetCameraMode")) {
else if(isKeyPressed(configKeys.getSDLKey("ResetCameraMode"),key, false) == true) {
if(currentCameraFollowUnit != NULL) {
currentCameraFollowUnit->setCameraFollowUnit(false);
currentCameraFollowUnit = NULL;
}
gameCamera.resetPosition();
}
//pause
@ -3245,6 +3272,15 @@ void Game::keyDown(SDL_KeyboardEvent key) {
decSpeed();
}
}
else if(isKeyPressed(configKeys.getSDLKey("BookmarkAdd"),key, false) == true) {
startMarkCell();
}
else if(isKeyPressed(configKeys.getSDLKey("BookmarkRemove"),key, false) == true) {
isUnMarkCellEnabled = true;
}
else if(isKeyPressed(configKeys.getSDLKey("CameraFollowSelectedUnit"),key, false) == true) {
startCameraFollowUnit();
}
//exit
//else if(key == configKeys.getCharKey("ExitKey")) {
else if(isKeyPressed(configKeys.getSDLKey("ExitKey"),key, false) == true) {

View File

@ -155,8 +155,8 @@ private:
int pauseGamePopupMenuIndex;
int saveGamePopupMenuIndex;
int loadGamePopupMenuIndex;
int markCellPopupMenuIndex;
int unmarkCellPopupMenuIndex;
//int markCellPopupMenuIndex;
//int unmarkCellPopupMenuIndex;
int keyboardSetupPopupMenuIndex;
int disconnectPlayerPopupMenuIndex;
//GLuint statelist3dMenu;
@ -189,6 +189,8 @@ private:
Shared::Graphics::VideoPlayer *videoPlayer;
bool playingStaticVideo;
Unit *currentCameraFollowUnit;
public:
Game();
Game(Program *program, const GameSettings *gameSettings, bool masterserverMode);
@ -337,6 +339,9 @@ private:
void updateNetworkHighligtedCells();
virtual void processInputText(string text, bool cancelled);
void startMarkCell();
void startCameraFollowUnit();
};
}}//end namespace

View File

@ -76,6 +76,7 @@ public:
bool isMeetable() const;
int getCount() const {return selectedUnits.size();}
const Unit *getUnit(int i) const {return selectedUnits[i];}
Unit *getUnitPtr(int i) {return selectedUnits[i];}
const Unit *getFrontUnit() const {return selectedUnits.front();}
Vec3f getRefPos() const;
bool hasUnit(const Unit* unit) const;

View File

@ -401,6 +401,7 @@ Unit::Unit(int id, UnitPathInterface *unitpath, const Vec2i &pos,
this->unitPath = unitpath;
this->unitPath->setMap(map);
this->cameraFollowUnit = false;
//RandomGen random;
random.init(id);
pathFindRefreshCellCount = random.randRange(10,20);
@ -1042,6 +1043,19 @@ void Unit::setTarget(const Unit *unit){
targetRef= unit;
}
bool Unit::getCameraFollowUnit() const {
return cameraFollowUnit;
}
void Unit::setCameraFollowUnit(bool value) {
this->cameraFollowUnit = value;
if(this->cameraFollowUnit == true) {
game->getGameCameraPtr()->setClampDisabled(true);
}
else {
game->getGameCameraPtr()->setClampDisabled(false);
}
}
void Unit::setPos(const Vec2i &pos, bool clearPathFinder) {
if(map->isInside(pos) == false || map->isInsideSurface(map->toSurfCoords(pos)) == false) {
throw megaglest_runtime_error("#3 Invalid path position = " + pos.getString());
@ -1054,14 +1068,14 @@ void Unit::setPos(const Vec2i &pos, bool clearPathFinder) {
this->lastPos= this->pos;
this->pos= pos;
/*
// This code is initial code to make the camera 'follow' a unit
if(this->getId() == 5) {
printf("A fov [%f] [H [%f] [V [%f]\n",game->getGameCameraPtr()->getFov(),game->getGameCameraPtr()->getHAng(),game->getGameCameraPtr()->getVAng());
//if(this->getId() == 5) {
if(cameraFollowUnit == true) {
//printf("A fov [%f] [H [%f] [V [%f]\n",game->getGameCameraPtr()->getFov(),game->getGameCameraPtr()->getHAng(),game->getGameCameraPtr()->getVAng());
game->getGameCameraPtr()->setClampDisabled(true);
//game->getGameCameraPtr()->setClampDisabled(true);
game->getGameCameraPtr()->setFov(45);
//game->getGameCameraPtr()->setFov(45);
if(oldLastPos.x > pos.x) {
game->getGameCameraPtr()->setHAng(270);
game->getGameCameraPtr()->setVAng(-7.6);
@ -1082,9 +1096,8 @@ void Unit::setPos(const Vec2i &pos, bool clearPathFinder) {
game->getGameCameraPtr()->setPos(getCurrVector());
game->getGameCameraPtr()->stop();
printf("B fov [%f] [H [%f] [V [%f]\n",game->getGameCameraPtr()->getFov(),game->getGameCameraPtr()->getHAng(),game->getGameCameraPtr()->getVAng());
//printf("B fov [%f] [H [%f] [V [%f]\n",game->getGameCameraPtr()->getFov(),game->getGameCameraPtr()->getHAng(),game->getGameCameraPtr()->getVAng());
}
*/
map->clampPos(this->pos);
this->meetingPos= pos - Vec2i(1);

View File

@ -456,6 +456,8 @@ private:
RandomGen random;
int pathFindRefreshCellCount;
bool cameraFollowUnit;
public:
Unit(int id, UnitPathInterface *path, const Vec2i &pos, const UnitType *type, Faction *faction, Map *map, CardinalDir placeFacing);
virtual ~Unit();
@ -469,6 +471,9 @@ public:
void setCurrentPathFinderDesiredFinalPos(const Vec2i &finalPos) { currentPathFinderDesiredFinalPos = finalPos; }
Vec2i getCurrentPathFinderDesiredFinalPos() const { return currentPathFinderDesiredFinalPos; }
bool getCameraFollowUnit() const;
void setCameraFollowUnit(bool value);
//const std::pair<const SkillType *,std::vector<Unit *> > & getCurrentAttackBoostUnits() const { return currentAttackBoostUnits; }
const UnitAttackBoostEffectOriginator & getAttackBoostOriginatorEffect() const { return currentAttackBoostOriginatorEffect; }
bool unitHasAttackBoost(const AttackBoost *boost, const Unit *source) const;

View File

@ -297,6 +297,7 @@ Map::Map() {
h=0;
surfaceW=0;
surfaceH=0;
surfaceSize=(surfaceW * surfaceH);
maxPlayers=0;
maxMapHeight=0;
}
@ -374,8 +375,11 @@ Checksum Map::load(const string &path, TechTree *techTree, Tileset *tileset) {
waterLevel= static_cast<float>((header.waterLevel-0.01f)/heightFactor);
title= header.title;
maxPlayers= header.maxFactions;
surfaceW= header.width;
surfaceH= header.height;
surfaceSize=(surfaceW * surfaceH);
w= surfaceW*cellScale;
h= surfaceH*cellScale;
cliffLevel = 0;

View File

@ -218,6 +218,8 @@ private:
int h;
int surfaceW;
int surfaceH;
int surfaceSize;
int maxPlayers;
Cell *cells;
SurfaceCell *surfaceCells;
@ -267,7 +269,8 @@ public:
return (w * h);
}
inline int getSurfaceCellArraySize() const {
return (surfaceW * surfaceH);
//return (surfaceW * surfaceH);
return surfaceSize;
}
inline SurfaceCell *getSurfaceCell(int sx, int sy) const {
int arrayIndex = sy * surfaceW + sx;

View File

@ -1247,7 +1247,7 @@ void UnitUpdater::updateHarvest(Unit *unit, int frameIndex) {
//if resource exausted, then delete it and stop
if (sc->decAmount(1)) {
const ResourceType *rt = r->getType();
//const ResourceType *rt = r->getType();
sc->deleteResource();
world->removeResourceTargetFromCache(unitTargetPos);
@ -1843,8 +1843,8 @@ void UnitUpdater::updateMorph(Unit *unit, int frameIndex) {
else{
unit->update2();
if(unit->getProgress2()>mct->getProduced()->getProductionTime()){
int oldSize = 0;
bool needMapUpdate = false;
//int oldSize = 0;
//bool needMapUpdate = false;
switch(this->game->getGameSettings()->getPathFinderType()) {
case pfBasic: