Skip to content

Commit

Permalink
Revert "Add files via upload (endless-sky#50)" (endless-sky#55)
Browse files Browse the repository at this point in the history
This reverts commit 8ce8c13.
  • Loading branch information
Hadron1776 committed Jul 12, 2017
1 parent 8ce8c13 commit 5158b65
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 94 deletions.
83 changes: 21 additions & 62 deletions source/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,9 @@ namespace {

int RadarType(const Ship &ship, int step)
{
if(ship.GetPersonality().IsTarget() && !ship.IsDestroyed())
{
// If a ship is a "target," double-blink it a few times per second.
int count = (step / 6) % 7;
if(count == 0 || count == 2)
return Radar::SPECIAL;
}
if(ship.IsDisabled() || (ship.IsOverheated() && ((step / 20) % 2)))
return Radar::INACTIVE;
if(ship.GetGovernment()->IsPlayer() || (ship.GetPersonality().IsEscort() && !ship.GetGovernment()->IsEnemy()))
if(ship.GetGovernment()->IsPlayer() || ship.GetPersonality().IsEscort())
return Radar::PLAYER;
if(!ship.GetGovernment()->IsEnemy())
return Radar::FRIENDLY;
Expand Down Expand Up @@ -522,23 +515,20 @@ void Engine::Step(bool isActive)
info.SetString("target name", "no target");
info.SetString("target type", "");
info.SetString("target government", "");
info.SetString("mission target", "");
info.SetBar("target shields", 0.);
info.SetBar("target hull", 0.);
}
else
{
const Font &font = FontSet::Get(14);
if(target->GetSystem() == player.GetSystem() && target->Cloaking() < 1.)
targetUnit = target->Facing().Unit();
info.SetSprite("target sprite", target->GetSprite(), targetUnit, target->GetFrameIndex(step));
info.SetString("target name", font.TruncateMiddle(target->Name(), 150));
info.SetString("target name", target->Name());
info.SetString("target type", target->ModelName());
if(!target->GetGovernment())
info.SetString("target government", "No Government");
else
info.SetString("target government", target->GetGovernment()->GetName());
info.SetString("mission target", target->GetPersonality().IsTarget() ? "(mission target)" : "");

int targetType = RadarType(*target, step);
info.SetOutlineColor(Radar::GetColor(targetType));
Expand Down Expand Up @@ -570,7 +560,7 @@ void Engine::Step(bool isActive)
info.SetBar("target hull", 0.);
}
}
if(target && target->IsTargetable() && target->GetSystem() == currentSystem
if(target && !target->IsDestroyed() && target->GetSystem() == currentSystem
&& (flagship->CargoScanFraction() || flagship->OutfitScanFraction()))
{
double width = max(target->Width(), target->Height());
Expand Down Expand Up @@ -654,7 +644,6 @@ const list<ShipEvent> &Engine::Events() const
void Engine::Draw() const
{
GameData::Background().Draw(center, centerVelocity, zoom);
static const Set<Color> &colors = GameData::Colors();

// Draw any active planet labels.
for(const PlanetLabel &label : labels)
Expand All @@ -665,12 +654,12 @@ void Engine::Draw() const
for(const auto &it : statuses)
{
static const Color color[6] = {
*colors.Get("overlay friendly shields"),
*colors.Get("overlay hostile shields"),
*colors.Get("overlay outfit scan"),
*colors.Get("overlay friendly hull"),
*colors.Get("overlay hostile hull"),
*colors.Get("overlay cargo scan")
Color(0., .5, 0., .25),
Color(.5, .15, 0., .25),
Color(.5, .5, .5, .25),
Color(.45, .5, 0., .25),
Color(.5, .3, 0., .25),
Color(.7, .7, .7, .25)
};
Point pos = it.position * zoom;
double radius = it.radius * zoom;
Expand All @@ -685,7 +674,7 @@ void Engine::Draw() const
if(highlightSprite)
{
Point size(highlightSprite->Width(), highlightSprite->Height());
const Color &color = *colors.Get("flagship highlight");
const Color &color = *GameData::Colors().Get("flagship highlight");
// The flagship is always in the dead center of the screen.
OutlineShader::Draw(highlightSprite, Point(), size, color, highlightUnit, highlightFrame);
}
Expand Down Expand Up @@ -758,8 +747,8 @@ void Engine::Draw() const
Point pos(Screen::Right() - 80, Screen::Bottom());
const Sprite *selectedSprite = SpriteSet::Get("ui/ammo selected");
const Sprite *unselectedSprite = SpriteSet::Get("ui/ammo unselected");
Color selectedColor = *colors.Get("bright");
Color unselectedColor = *colors.Get("dim");
Color selectedColor = *GameData::Colors().Get("bright");
Color unselectedColor = *GameData::Colors().Get("dim");
for(const pair<const Outfit *, int> &it : ammo)
{
pos.Y() -= 30.;
Expand Down Expand Up @@ -790,7 +779,7 @@ void Engine::Draw() const
if(Preferences::Has("Show CPU / GPU load"))
{
string loadString = to_string(static_cast<int>(load * 100. + .5)) + "% CPU";
Color color = *colors.Get("medium");
Color color = *GameData::Colors().Get("medium");
font.Draw(loadString,
Point(-10 - font.Width(loadString), Screen::Height() * -.5 + 5.), color);
}
Expand Down Expand Up @@ -884,7 +873,7 @@ void Engine::EnterSystem()
fleet.Get()->Place(*system, ships);

const Fleet *raidFleet = system->GetGovernment()->RaidFleet();
if(raidFleet && raidFleet->GetGovernment() && raidFleet->GetGovernment()->IsEnemy())
if(raidFleet && raidFleet->GetGovernment())
{
// Find out how attractive the player's fleet is to pirates. Aside from a
// heavy freighter, no single ship should attract extra pirate attention.
Expand Down Expand Up @@ -1349,22 +1338,6 @@ void Engine::CalculateStep()
// If this "projectile" is a ship explosion, it always explodes.
if(!gov)
closestHit = 0.;
else if(projectile.GetWeapon().IsPhasing() && projectile.Target())
{
// "Phasing" projectiles that have a target will never hit any other ship.
shared_ptr<Ship> target = projectile.TargetPtr();
if(target && target->GetSystem() == player.GetSystem()
&& target->Zoom() == 1. && target->Cloaking() < 1.)
{
Point offset = projectile.Position() - target->Position();
double range = target->GetMask(step).Collide(offset, projectile.Velocity(), target->Facing());
if(range < 1.)
{
closestHit = range;
hit = target;
}
}
}
else
{
double triggerRadius = projectile.GetWeapon().TriggerRadius();
Expand All @@ -1388,17 +1361,13 @@ void Engine::CalculateStep()
hitVelocity = ship->Velocity();
}
}
// "Phasing" projectiles can pass through asteroids.
if(!projectile.GetWeapon().IsPhasing())
// Check if the projectile hits an asteroid that is closer than the
// ship that it hit (if any).
double closestAsteroid = asteroids.Collide(projectile, step, closestHit, &hitVelocity);
if(closestAsteroid < closestHit)
{
// Check if the projectile hits an asteroid that is closer than
// the ship that it hit (if any).
double closestAsteroid = asteroids.Collide(projectile, step, closestHit, &hitVelocity);
if(closestAsteroid < closestHit)
{
closestHit = closestAsteroid;
hit = nullptr;
}
closestHit = closestAsteroid;
hit = nullptr;
}
}

Expand All @@ -1411,18 +1380,12 @@ void Engine::CalculateStep()
// If this projectile has a blast radius, find all ships within its
// radius. Otherwise, only one is damaged.
double blastRadius = projectile.GetWeapon().BlastRadius();
bool isSafe = projectile.GetWeapon().IsSafe();
if(blastRadius)
{
// Even friendly ships can be hit by the blast, unless it is a
// "safe" weapon.
// Even friendly ships can be hit by the blast.
Point hitPos = projectile.Position() + closestHit * projectile.Velocity();
for(Body *body : shipCollisions.Circle(hitPos, blastRadius))
{
if(isSafe && projectile.Target() != body
&& !projectile.GetGovernment()->IsEnemy(body->GetGovernment()))
continue;

shared_ptr<Ship> ship = reinterpret_cast<Ship *>(body)->shared_from_this();
int eventType = ship->TakeDamage(projectile, ship != hit);
if(eventType)
Expand All @@ -1432,10 +1395,6 @@ void Engine::CalculateStep()
// Cloaked ships can be hit be a blast, too.
for(Body *body : cloakedCollisions.Circle(hitPos, blastRadius))
{
if(isSafe && projectile.Target() != body
&& !projectile.GetGovernment()->IsEnemy(body->GetGovernment()))
continue;

shared_ptr<Ship> ship = reinterpret_cast<Ship *>(body)->shared_from_this();
int eventType = ship->TakeDamage(projectile, ship != hit);
if(eventType)
Expand Down
22 changes: 11 additions & 11 deletions source/NPC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,17 @@ void NPC::Save(DataWriter &out) const
out.BeginChild();
{
// Break the text up into paragraphs.
for(const string &line : Format::Split(dialogText, "\n\t"))
out.Write(line);
size_t begin = 0;
while(true)
{
size_t pos = dialogText.find("\n\t", begin);
if(pos == string::npos)
pos = dialogText.length();
out.Write(dialogText.substr(begin, pos - begin));
if(pos == dialogText.length())
break;
begin = pos + 2;
}
}
out.EndChild();
}
Expand Down Expand Up @@ -320,19 +329,10 @@ bool NPC::IsLeftBehind(const System *playerSystem) const

bool NPC::HasFailed() const
{
static const int mustLiveFor = ShipEvent::SCAN_CARGO | ShipEvent::SCAN_OUTFITS | ShipEvent::BOARD;

for(const auto &it : actions)
{
if(it.second & failIf)
return true;

// If we still need to perform an action that requires the NPC ship be
// alive, then that ship being destroyed should cause the mission to fail.
if((~it.second & succeedIf & mustLiveFor) && (it.second & ShipEvent::DESTROY))
return true;
}

return false;
}

Expand Down
20 changes: 1 addition & 19 deletions source/Personality.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ namespace {
static const int APPEASING = (1 << 22);
static const int MUTE = (1 << 23);
static const int OPPORTUNISTIC = (1 << 24);
static const int TARGET = (1 << 25);
static const int SKYBOUND = (1 << 26);

static const map<string, int> TOKEN = {
{"pacifist", PACIFIST},
Expand All @@ -74,9 +72,7 @@ namespace {
{"harvests", HARVESTS},
{"appeasing", APPEASING},
{"mute", MUTE},
{"opportunistic", OPPORTUNISTIC},
{"target", TARGET},
{"skybound", SKYBOUND}
{"opportunistic", OPPORTUNISTIC}
};

double DEFAULT_CONFUSION = 10.;
Expand Down Expand Up @@ -260,13 +256,6 @@ bool Personality::IsUninterested() const



bool Personality::IsSkybound() const
{
return flags & SKYBOUND;
}



bool Personality::IsSurveillance() const
{
return flags & SURVEILLANCE;
Expand Down Expand Up @@ -302,13 +291,6 @@ bool Personality::IsEscort() const



bool Personality::IsTarget() const
{
return flags & TARGET;
}



bool Personality::IsMute() const
{
return flags & MUTE;
Expand Down
2 changes: 0 additions & 2 deletions source/Personality.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ class Personality {
bool IsFleeing() const;
bool IsDerelict() const;
bool IsUninterested() const;
bool IsSkybound() const;

// Non-combat goals:
bool IsSurveillance() const;
Expand All @@ -68,7 +67,6 @@ class Personality {

// Special flags:
bool IsEscort() const;
bool IsTarget() const;
bool IsMute() const;

// Current inaccuracy in this ship's targeting:
Expand Down

0 comments on commit 5158b65

Please sign in to comment.