- 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 TogglePhotoMode=f8
SwitchLanguage=L SwitchLanguage=L
SaveGame=f11 SaveGame=f11
BookmarkAdd=f2
BookmarkRemove=f3
CameraFollowSelectedUnit=f4
; === propertyMap File === ; === propertyMap File ===

View File

@ -132,8 +132,8 @@ Game::Game() : ProgramState(NULL) {
pauseGamePopupMenuIndex = -1; pauseGamePopupMenuIndex = -1;
saveGamePopupMenuIndex = -1; saveGamePopupMenuIndex = -1;
loadGamePopupMenuIndex = -1; loadGamePopupMenuIndex = -1;
markCellPopupMenuIndex = -1; //markCellPopupMenuIndex = -1;
unmarkCellPopupMenuIndex = -1; //unmarkCellPopupMenuIndex = -1;
keyboardSetupPopupMenuIndex = -1; keyboardSetupPopupMenuIndex = -1;
disconnectPlayerPopupMenuIndex = -1; disconnectPlayerPopupMenuIndex = -1;
@ -197,8 +197,8 @@ void Game::resetMembers() {
pauseGamePopupMenuIndex = -1; pauseGamePopupMenuIndex = -1;
saveGamePopupMenuIndex = -1; saveGamePopupMenuIndex = -1;
loadGamePopupMenuIndex = -1; loadGamePopupMenuIndex = -1;
markCellPopupMenuIndex = -1; //markCellPopupMenuIndex = -1;
unmarkCellPopupMenuIndex = -1; //unmarkCellPopupMenuIndex = -1;
keyboardSetupPopupMenuIndex = -1; keyboardSetupPopupMenuIndex = -1;
disconnectPlayerPopupMenuIndex = -1; disconnectPlayerPopupMenuIndex = -1;
@ -1307,10 +1307,10 @@ void Game::setupPopupMenus(bool checkClientAdminOverrideOnly) {
joinTeamPopupMenuIndex = menuItems.size()-1; joinTeamPopupMenuIndex = menuItems.size()-1;
} }
menuItems.push_back(lang.get("MarkCell")); //menuItems.push_back(lang.get("MarkCell"));
markCellPopupMenuIndex = menuItems.size()-1; //markCellPopupMenuIndex = menuItems.size()-1;
menuItems.push_back(lang.get("UnMarkCell")); //menuItems.push_back(lang.get("UnMarkCell"));
unmarkCellPopupMenuIndex = menuItems.size()-1; //unmarkCellPopupMenuIndex = menuItems.size()-1;
if(allowAdminMenuItems == true){ if(allowAdminMenuItems == true){
menuItems.push_back(lang.get("PauseResumeGame")); 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) { void Game::mouseDownLeft(int x, int y) {
if(this->masterserverMode == true) { if(this->masterserverMode == true) {
return; return;
@ -2309,28 +2329,12 @@ void Game::mouseDownLeft(int x, int y) {
else if(result.first == saveGamePopupMenuIndex){ else if(result.first == saveGamePopupMenuIndex){
saveGame(); saveGame();
} }
else if(result.first == markCellPopupMenuIndex) { //else if(result.first == markCellPopupMenuIndex) {
int totalMarkedCellsForPlayer = 0; // startMarkCell();
for(std::map<Vec2i, MarkedCell>::iterator iterMap = mapMarkedCellList.begin(); //}
iterMap != mapMarkedCellList.end(); ++iterMap) { //else if(result.first == unmarkCellPopupMenuIndex) {
MarkedCell &bm = iterMap->second; // isUnMarkCellEnabled = true;
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(popupMenuSwitchTeams.mouseClick(x, y)) { else if(popupMenuSwitchTeams.mouseClick(x, y)) {
//popupMenuSwitchTeams //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) { void Game::keyDown(SDL_KeyboardEvent key) {
if(this->masterserverMode == true) { if(this->masterserverMode == true) {
return; 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); //printf("SDL [%d] key [%d][%d]\n",configKeys.getSDLKey("SetMarker"),key.keysym.unicode,key.keysym.sym);
bool setMarkerKeyAllowsModifier = false; 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; setMarkerKeyAllowsModifier = true;
} }
//if(key == configKeys.getCharKey("RenderNetworkStatus")) { //if(key == configKeys.getCharKey("RenderNetworkStatus")) {
@ -3188,6 +3210,11 @@ void Game::keyDown(SDL_KeyboardEvent key) {
//reset camera mode to normal //reset camera mode to normal
//else if(key == configKeys.getCharKey("ResetCameraMode")) { //else if(key == configKeys.getCharKey("ResetCameraMode")) {
else if(isKeyPressed(configKeys.getSDLKey("ResetCameraMode"),key, false) == true) { else if(isKeyPressed(configKeys.getSDLKey("ResetCameraMode"),key, false) == true) {
if(currentCameraFollowUnit != NULL) {
currentCameraFollowUnit->setCameraFollowUnit(false);
currentCameraFollowUnit = NULL;
}
gameCamera.resetPosition(); gameCamera.resetPosition();
} }
//pause //pause
@ -3245,6 +3272,15 @@ void Game::keyDown(SDL_KeyboardEvent key) {
decSpeed(); 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 //exit
//else if(key == configKeys.getCharKey("ExitKey")) { //else if(key == configKeys.getCharKey("ExitKey")) {
else if(isKeyPressed(configKeys.getSDLKey("ExitKey"),key, false) == true) { else if(isKeyPressed(configKeys.getSDLKey("ExitKey"),key, false) == true) {

View File

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

View File

@ -76,6 +76,7 @@ public:
bool isMeetable() const; bool isMeetable() const;
int getCount() const {return selectedUnits.size();} int getCount() const {return selectedUnits.size();}
const Unit *getUnit(int i) const {return selectedUnits[i];} const Unit *getUnit(int i) const {return selectedUnits[i];}
Unit *getUnitPtr(int i) {return selectedUnits[i];}
const Unit *getFrontUnit() const {return selectedUnits.front();} const Unit *getFrontUnit() const {return selectedUnits.front();}
Vec3f getRefPos() const; Vec3f getRefPos() const;
bool hasUnit(const Unit* unit) 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 = unitpath;
this->unitPath->setMap(map); this->unitPath->setMap(map);
this->cameraFollowUnit = false;
//RandomGen random; //RandomGen random;
random.init(id); random.init(id);
pathFindRefreshCellCount = random.randRange(10,20); pathFindRefreshCellCount = random.randRange(10,20);
@ -1042,6 +1043,19 @@ void Unit::setTarget(const Unit *unit){
targetRef= 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) { void Unit::setPos(const Vec2i &pos, bool clearPathFinder) {
if(map->isInside(pos) == false || map->isInsideSurface(map->toSurfCoords(pos)) == false) { if(map->isInside(pos) == false || map->isInsideSurface(map->toSurfCoords(pos)) == false) {
throw megaglest_runtime_error("#3 Invalid path position = " + pos.getString()); 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->lastPos= this->pos;
this->pos= pos; this->pos= pos;
/*
// This code is initial code to make the camera 'follow' a unit // This code is initial code to make the camera 'follow' a unit
if(this->getId() == 5) { //if(this->getId() == 5) {
printf("A fov [%f] [H [%f] [V [%f]\n",game->getGameCameraPtr()->getFov(),game->getGameCameraPtr()->getHAng(),game->getGameCameraPtr()->getVAng()); 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) { if(oldLastPos.x > pos.x) {
game->getGameCameraPtr()->setHAng(270); game->getGameCameraPtr()->setHAng(270);
game->getGameCameraPtr()->setVAng(-7.6); game->getGameCameraPtr()->setVAng(-7.6);
@ -1082,9 +1096,8 @@ void Unit::setPos(const Vec2i &pos, bool clearPathFinder) {
game->getGameCameraPtr()->setPos(getCurrVector()); game->getGameCameraPtr()->setPos(getCurrVector());
game->getGameCameraPtr()->stop(); 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); map->clampPos(this->pos);
this->meetingPos= pos - Vec2i(1); this->meetingPos= pos - Vec2i(1);

View File

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

View File

@ -297,6 +297,7 @@ Map::Map() {
h=0; h=0;
surfaceW=0; surfaceW=0;
surfaceH=0; surfaceH=0;
surfaceSize=(surfaceW * surfaceH);
maxPlayers=0; maxPlayers=0;
maxMapHeight=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); waterLevel= static_cast<float>((header.waterLevel-0.01f)/heightFactor);
title= header.title; title= header.title;
maxPlayers= header.maxFactions; maxPlayers= header.maxFactions;
surfaceW= header.width; surfaceW= header.width;
surfaceH= header.height; surfaceH= header.height;
surfaceSize=(surfaceW * surfaceH);
w= surfaceW*cellScale; w= surfaceW*cellScale;
h= surfaceH*cellScale; h= surfaceH*cellScale;
cliffLevel = 0; cliffLevel = 0;

View File

@ -218,6 +218,8 @@ private:
int h; int h;
int surfaceW; int surfaceW;
int surfaceH; int surfaceH;
int surfaceSize;
int maxPlayers; int maxPlayers;
Cell *cells; Cell *cells;
SurfaceCell *surfaceCells; SurfaceCell *surfaceCells;
@ -267,7 +269,8 @@ public:
return (w * h); return (w * h);
} }
inline int getSurfaceCellArraySize() const { inline int getSurfaceCellArraySize() const {
return (surfaceW * surfaceH); //return (surfaceW * surfaceH);
return surfaceSize;
} }
inline SurfaceCell *getSurfaceCell(int sx, int sy) const { inline SurfaceCell *getSurfaceCell(int sx, int sy) const {
int arrayIndex = sy * surfaceW + sx; 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 resource exausted, then delete it and stop
if (sc->decAmount(1)) { if (sc->decAmount(1)) {
const ResourceType *rt = r->getType(); //const ResourceType *rt = r->getType();
sc->deleteResource(); sc->deleteResource();
world->removeResourceTargetFromCache(unitTargetPos); world->removeResourceTargetFromCache(unitTargetPos);
@ -1843,8 +1843,8 @@ void UnitUpdater::updateMorph(Unit *unit, int frameIndex) {
else{ else{
unit->update2(); unit->update2();
if(unit->getProgress2()>mct->getProduced()->getProductionTime()){ if(unit->getProgress2()>mct->getProduced()->getProductionTime()){
int oldSize = 0; //int oldSize = 0;
bool needMapUpdate = false; //bool needMapUpdate = false;
switch(this->game->getGameSettings()->getPathFinderType()) { switch(this->game->getGameSettings()->getPathFinderType()) {
case pfBasic: case pfBasic: