/** * * @author OLiver */ unsigned PreviewMinimap::CalcPixelColor(const MapPoint pt, const unsigned t) { unsigned color = 0; // Baum an dieser Stelle? unsigned char landscape_obj = objects[GetMMIdx(pt)]; if(landscape_obj >= 0xC4 && landscape_obj <= 0xC6) color = VaryBrightness(TREE_COLOR, VARY_TREE_COLOR); // Granit an dieser Stelle? else if(landscape_obj == 0xCC || landscape_obj == 0xCD) color = VaryBrightness(GRANITE_COLOR, VARY_GRANITE_COLOR); // Ansonsten die jeweilige Terrainfarbe nehmen else { color = TerrainData::GetColor(lt, TerrainData::MapIdx2Terrain(t == 0 ? terrain1[GetMMIdx(pt)] : terrain2[GetMMIdx(pt)])); // Schattierung const int shading = shadows[GetMMIdx(pt)] - 0x40; int r = GetRed(color) + shading; int g = GetGreen(color) + shading; int b = GetBlue(color) + shading; if(r < 0) r = 0; if(r > 255) r = 255; if(g < 0) g = 0; if(g > 255) g = 255; if(b < 0) b = 0; if(b > 255) b = 255; color = MakeColor(0xFF, unsigned(r), unsigned(g), unsigned(b)); } return color; }
/** * Additional stuff we need to do before drawing (in this case: update the map) */ void IngameMinimap::BeforeDrawing() { // Ab welcher Knotenanzahl (Teil der Gesamtknotenanzahl) die Textur komplett neu erstellt werden soll static const unsigned MAX_NODES_UPDATE_DENOMINATOR = 2; // (2 = 1/2, 3 = 1/3 usw.) if(!nodesToUpdate.empty()) { // Komplette Textur neu erzeugen, weil es zu viele Knoten sind? if(nodesToUpdate.size() >= map_width * map_height / MAX_NODES_UPDATE_DENOMINATOR) { // Ja, alles neu erzeugen UpdateAll(); for(MapPoint p(0, 0); p.y < map_height; p.y++) for(p.x = 0; p.x < map_width; p.x++) nodes_updated[GetMMIdx(p)] = false; } else { // Entsprechende Pixel updaten for(std::vector<MapPoint>::iterator it = nodesToUpdate.begin(); it != nodesToUpdate.end(); ++it) { for(unsigned t = 0; t < 2; ++t) { unsigned color = CalcPixelColor(*it, t); map.tex_setPixel((it->x * 2 + t + (it->y & 1)) % (map_width * 2), it->y, GetRed(color), GetGreen(color), GetBlue(color), GetAlpha(color)); } nodes_updated[GetMMIdx(*it)] = false; } } this->nodesToUpdate.clear(); } }
void IngameMinimap::UpdateNode(const MapPoint pt) { if(!nodes_updated[GetMMIdx(pt)]) { nodes_updated[GetMMIdx(pt)] = true; nodesToUpdate.push_back(pt); } }
void PreviewMinimap::CalcShadows(const std::vector<unsigned char>& altitudes) { shadows.resize(map_width * map_height); for(MapPoint pt(0, 0); pt.y < map_height; ++pt.y) { for(pt.x = 0; pt.x < map_width; ++pt.x) shadows[GetMMIdx(pt)] = CalcShading(pt, altitudes); } }
unsigned char PreviewMinimap::CalcShading(const MapPoint pt, const std::vector<unsigned char>& altitudes) const { int altitude = altitudes[GetMMIdx(pt)]; MapPoint tmp = MakeMapPoint(GetNeighbour(Point<int>(pt), Direction::NORTHEAST), map_width, map_height); int A = altitudes[GetMMIdx(tmp)] - altitude; tmp = MakeMapPoint(GetNeighbour2(Point<int>(pt), 0), map_width, map_height); int B = altitudes[GetMMIdx(tmp)] - altitude; tmp = MakeMapPoint(GetNeighbour(Point<int>(pt), Direction::WEST), map_width, map_height); int C = altitudes[GetMMIdx(tmp)] - altitude; tmp = MakeMapPoint(GetNeighbour2(Point<int>(pt), 7), map_width, map_height); int D = altitudes[GetMMIdx(tmp)] - altitude; int shadingS2 = 64 + 9 * A - 3 * B - 6 * C - 9 * D; if(shadingS2 > 128) shadingS2 = 128; else if(shadingS2 < 0) shadingS2 = 0; return shadingS2; }
/** * Update all nodes with the given drawn object */ void IngameMinimap::UpdateAll(const DrawnObject drawn_object) { // Gesamte Karte neu berechnen for(MapCoord y = 0; y < map_height; ++y) { for(MapCoord x = 0; x < map_width; ++x) { MapPoint pt(x, y); for(unsigned t = 0; t < 2; ++t) { if(dos[GetMMIdx(pt)] == drawn_object || (drawn_object == DO_PLAYER && // for DO_PLAYER check for not drawn buildings or roads as there is only the player territory visible ((dos[GetMMIdx(pt)] == DO_BUILDING && !houses) || (dos[GetMMIdx(pt)] == DO_ROAD && !roads)))) { unsigned color = CalcPixelColor(pt, t); map.tex_setPixel((x * 2 + t + (y & 1)) % (map_width * 2), y, GetRed(color), GetGreen(color), GetBlue(color), GetAlpha(color)); } } } } }
/** * Alle Punkte Updaten, bei denen das DrawnObject * gleich dem übergebenen drawn_object ist * * @author OLiver */ void IngameMinimap::UpdateAll(const DrawnObject drawn_object) { // Gesamte Karte neu berechnen for(MapCoord y = 0; y < map_height; ++y) { for(MapCoord x = 0; x < map_width; ++x) { MapPoint pt(x, y); for(unsigned t = 0; t < 2; ++t) { if(dos[GetMMIdx(pt)] == drawn_object || // das gewünschte Objekt (drawn_object == DO_PLAYER && // bei DO_PLAYER auf evtl. nicht gezeichnete Häuser und Straßen ((dos[GetMMIdx(pt)] == DO_BUILDING && !houses) || // achten, da dort auch nur das Player- (dos[GetMMIdx(pt)] == DO_ROAD && !roads)))) // Territorium zu sehen ist! { unsigned color = CalcPixelColor(pt, t); map.tex_setPixel((x * 2 + t + (y & 1)) % (map_width * 2), y, GetRed(color), GetGreen(color), GetBlue(color), GetAlpha(color)); } } } } }
unsigned IngameMinimap::CalcPixelColor(const MapPoint pt, const unsigned t) { unsigned color = 0; Visibility visibility = gwv.GetVisibility(pt); if(visibility == VIS_INVISIBLE) { dos[GetMMIdx(pt)] = DO_INVISIBLE; // Man sieht nichts --> schwarz return 0xFF000000; } else { DrawnObject drawn_object = DO_INVALID; const bool fow = (visibility == VIS_FOW); unsigned char owner; NodalObjectType noType = NOP_NOTHING; FOW_Type fot = FOW_NOTHING; if(!fow) { const MapNode& node = gwv.GetNode(pt); owner = node.owner; if(node.obj) noType = node.obj->GetType(); } else { const FoWNode& node = gwv.GetYoungestFOWNode(pt); owner = node.owner; if(node.object) fot = node.object->GetType(); } // Baum an dieser Stelle? if((!fow && noType == NOP_TREE) || (fow && fot == FOW_TREE)) //-V807 { color = VaryBrightness(TREE_COLOR, VARY_TREE_COLOR); drawn_object = DO_TERRAIN; // Ggf. mit Spielerfarbe if(owner) { drawn_object = DO_PLAYER; if(territory) color = CombineWithPlayerColor(color, owner); } } // Granit an dieser Stelle? else if((!fow && noType == NOP_GRANITE) || (fow && fot == FOW_GRANITE)) { color = VaryBrightness(GRANITE_COLOR, VARY_GRANITE_COLOR); drawn_object = DO_TERRAIN; // Ggf. mit Spielerfarbe if(owner) { drawn_object = DO_PLAYER; if(territory) color = CombineWithPlayerColor(color, owner); } } // Ansonsten die jeweilige Terrainfarbe nehmen else { // Ggf. Spielerfarbe mit einberechnen, falls das von einem Spieler ein Territorium ist if(owner) { // Building? if(((!fow && (noType == NOP_BUILDING || noType == NOP_BUILDINGSITE)) || (fow && (fot == FOW_BUILDING || fot == FOW_BUILDINGSITE)))) drawn_object = DO_BUILDING; /// Roads? else if(IsRoad(pt, visibility)) drawn_object = DO_ROAD; // ansonsten normales Territorium? else drawn_object = DO_PLAYER; if(drawn_object == DO_BUILDING && houses) color = BUILDING_COLOR; /// Roads? else if(drawn_object == DO_ROAD && roads) color = ROAD_COLOR; // ansonsten normales Territorium? else if(territory) // Normales Terrain und Spielerfarbe berechnen color = CombineWithPlayerColor(CalcTerrainColor(pt, t), owner); else // Normales Terrain berechnen color = CalcTerrainColor(pt, t); } else { // Normales Terrain berechnen color = CalcTerrainColor(pt, t); drawn_object = DO_TERRAIN; } } // Bei FOW die Farben abdunkeln if(fow) color = MakeColor(0xFF, GetRed(color) / 2, GetGreen(color) / 2, GetBlue(color) / 2); dos[GetMMIdx(pt)] = drawn_object; } return color; }
/** * * @author OLiver */ unsigned IngameMinimap::CalcPixelColor(const MapPoint pt, const unsigned t) { unsigned color = 0; // Beobeachtender Spieler unsigned char viewing_player = GAMECLIENT.GetPlayerID(); Visibility visibility = gwv.GetVisibility(pt); if(visibility == VIS_INVISIBLE) { dos[GetMMIdx(pt)] = DO_INVISIBLE; // Man sieht nichts --> schwarz return 0xFF000000; } else { DrawnObject drawn_object = DO_INVALID; bool fow = (visibility == VIS_FOW); unsigned char owner; if(!fow) owner = gwv.GetNode(pt).owner; else owner = gwv.GetNode(pt).fow[GAMECLIENT.GetPlayerID()].owner; // Baum an dieser Stelle? if((!fow && gwv.GetNO(pt)->GetGOT() == GOT_TREE) || (fow && gwv.GetFOWObject(pt, viewing_player)->GetType() == FOW_TREE)) //-V807 { color = VaryBrightness(TREE_COLOR, VARY_TREE_COLOR); drawn_object = DO_TERRAIN; // Ggf. mit Spielerfarbe if(owner) { drawn_object = DO_PLAYER; if(territory) color = CombineWithPlayerColor(color, owner); } } // Granit an dieser Stelle? else if((!fow && gwv.GetNO(pt)->GetGOT() == GOT_GRANITE) || (fow && gwv.GetFOWObject(pt, viewing_player)->GetType() == FOW_GRANITE)) { color = VaryBrightness(GRANITE_COLOR, VARY_GRANITE_COLOR); drawn_object = DO_TERRAIN; // Ggf. mit Spielerfarbe if(owner) { drawn_object = DO_PLAYER; if(territory) color = CombineWithPlayerColor(color, owner); } } // Ansonsten die jeweilige Terrainfarbe nehmen else { // Ggf. Spielerfarbe mit einberechnen, falls das von einem Spieler ein Territorium ist if(owner) { // Gebäude? GO_Type got = gwv.GetNO(pt)->GetGOT(); FOW_Type fot = gwv.GetFOWObject(pt, viewing_player)->GetType(); if(((!fow && (got == GOT_NOB_USUAL || got == GOT_NOB_MILITARY || got == GOT_NOB_STOREHOUSE || got == GOT_NOB_SHIPYARD || got == GOT_NOB_HARBORBUILDING || got == GOT_NOB_HQ || got == GOT_BUILDINGSITE)) || (fow && (fot == FOW_BUILDING || fot == FOW_BUILDINGSITE)))) drawn_object = DO_BUILDING; /// Straßen? else if(IsRoad(pt, visibility)) drawn_object = DO_ROAD; // ansonsten normales Territorium? else drawn_object = DO_PLAYER; if(drawn_object == DO_BUILDING && houses) color = BUILDING_COLOR; /// Straßen? else if(drawn_object == DO_ROAD && roads) color = ROAD_COLOR; // ansonsten normales Territorium? else if(territory) // Normales Terrain und Spielerfarbe berechnen color = CombineWithPlayerColor(CalcTerrainColor(pt, t), owner); else // Normales Terrain berechnen color = CalcTerrainColor(pt, t); } else { // Normales Terrain berechnen color = CalcTerrainColor(pt, t); drawn_object = DO_TERRAIN; } } // Bei FOW die Farben abdunkeln if(fow) color = MakeColor(0xFF, GetRed(color) / 2, GetGreen(color) / 2, GetBlue(color) / 2); dos[GetMMIdx(pt)] = drawn_object; } return color; }