├── .github ├── path-filters.yml └── workflows │ ├── compute-changes.yml │ └── projects_check.yml ├── commodities ├── food.txt ├── metal.txt ├── plastic.txt ├── clothing.txt ├── electronics.txt ├── equipment.txt ├── industrial.txt ├── medical.txt ├── heavy_metals.txt └── luxury_goods.txt ├── png-strip ├── README.md ├── .editorconfig ├── .gitignore ├── source ├── shared │ ├── DisjointSet.h │ ├── DataFile.h │ ├── DataNode.h │ ├── DataWriter.h │ ├── DisjointSet.cpp │ ├── DataWriter.cpp │ ├── DataNode.cpp │ └── DataFile.cpp ├── file-check.cpp ├── map-component.cpp ├── add-minables.cpp ├── color-converter.cpp ├── map-merge.cpp ├── freetype.cpp ├── blend.cpp ├── dynamic-economy.cpp ├── mapper.cpp ├── commerce.cpp └── worldview.cpp ├── utils └── check_code_style.py └── LICENSE /.github/path-filters.yml: -------------------------------------------------------------------------------- 1 | source_code: 2 | - 'source/**' 3 | -------------------------------------------------------------------------------- /commodities/food.txt: -------------------------------------------------------------------------------- 1 | name "Food" 2 | base 100 3 | bins 24 18 16 18 24 4 | -------------------------------------------------------------------------------- /commodities/metal.txt: -------------------------------------------------------------------------------- 1 | name "Metal" 2 | base 190 3 | bins 30 25 20 25 4 | -------------------------------------------------------------------------------- /commodities/plastic.txt: -------------------------------------------------------------------------------- 1 | name "Plastic" 2 | base 240 3 | bins 40 20 40 4 | -------------------------------------------------------------------------------- /commodities/clothing.txt: -------------------------------------------------------------------------------- 1 | name "Clothing" 2 | base 140 3 | bins 20 60 20 4 | -------------------------------------------------------------------------------- /commodities/electronics.txt: -------------------------------------------------------------------------------- 1 | name "Electronics" 2 | base 590 3 | bins 30 40 30 4 | -------------------------------------------------------------------------------- /commodities/equipment.txt: -------------------------------------------------------------------------------- 1 | name "Equipment" 2 | base 330 3 | bins 30 20 20 30 4 | -------------------------------------------------------------------------------- /commodities/industrial.txt: -------------------------------------------------------------------------------- 1 | name "Industrial" 2 | base 520 3 | bins 20 30 30 20 4 | -------------------------------------------------------------------------------- /commodities/medical.txt: -------------------------------------------------------------------------------- 1 | name "Medical" 2 | base 430 3 | bins 20 20 20 20 20 4 | -------------------------------------------------------------------------------- /png-strip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/endless-sky/endless-sky-tools/HEAD/png-strip -------------------------------------------------------------------------------- /commodities/heavy_metals.txt: -------------------------------------------------------------------------------- 1 | name "Heavy Metals" 2 | base 610 3 | bins 8 12 20 20 20 12 8 4 | -------------------------------------------------------------------------------- /commodities/luxury_goods.txt: -------------------------------------------------------------------------------- 1 | name "Luxury Goods" 2 | base 920 3 | bins 25 20 15 10 10 20 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # endless-sky-tools 2 | Various small programs to help with Endless Sky development. 3 | -------------------------------------------------------------------------------- /.github/workflows/compute-changes.yml: -------------------------------------------------------------------------------- 1 | name: Compute Changes 2 | 3 | on: 4 | workflow_call: 5 | outputs: 6 | source_code: 7 | value: ${{ jobs.changed.outputs.source_code }} 8 | 9 | jobs: 10 | changed: 11 | runs-on: ubuntu-latest 12 | outputs: 13 | source_code: ${{ steps.filter.outputs.source_code }} 14 | steps: 15 | - uses: actions/checkout@v3 16 | with: 17 | fetch-depth: 2 18 | - uses: dorny/paths-filter@v2 19 | id: filter 20 | with: 21 | filters: .github/path-filters.yml 22 | token: ${{ github.token }} 23 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # https://editorconfig.org/ 2 | root = true 3 | 4 | [*] 5 | insert_final_newline = true 6 | trim_trailing_whitespace = true 7 | 8 | # Data files 9 | [data/**.txt] 10 | trim_trailing_whitespace = false 11 | indent_style = tab 12 | 13 | # Code files 14 | [{*.{cpp,h,rc,hpp}, SConstruct, SConscript}] 15 | indent_style = tab 16 | # Except any third-party libraries 17 | [catch.hpp] 18 | indent_style = unset 19 | 20 | # Markdown 21 | [*.md] 22 | trim_trailing_whitespace = false 23 | 24 | # Scripts 25 | [*.{sh,ps1}] 26 | indent_style = space 27 | indent_size = 2 28 | 29 | [*.xml] 30 | indent_style = space 31 | indent_size = 2 32 | 33 | [*.{yml,yaml}] 34 | indent_size = 2 35 | indent_style = space 36 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Binaries 2 | *.exe 3 | 4 | # dlls needed to run the binary 5 | *.dll 6 | 7 | # Build Directories and toolchain-generated files 8 | build/ 9 | obj/ 10 | bin/ 11 | lib/ 12 | x64/ 13 | Debug/ 14 | install/ 15 | Release/ 16 | *.o 17 | *.layout 18 | *.depend 19 | scons-local* 20 | .sconsign.dblite 21 | /*.d 22 | /vcpkg/ 23 | 24 | # OS-specific generated files 25 | .DS_Store 26 | *.db 27 | 28 | # IDEs (no support implied) 29 | .cache 30 | .devcontainer 31 | .vscode 32 | .vs 33 | .metadata 34 | *.psess 35 | *.vsp 36 | *.vspx 37 | *.sap 38 | ipch/ 39 | *.aps 40 | *.ncb 41 | *.opendb 42 | *.opensdf 43 | *.sdf 44 | *.cachefile 45 | *.VC.db 46 | *.VC.VC.opendb 47 | *.suo 48 | *.sln 49 | *.vcxproj* 50 | *.userosscache 51 | *.sln.docstates 52 | *.xcodeproj/** 53 | .idea/ 54 | .idea_modules/ 55 | compile_commands.json 56 | CMakeUserPresets.json 57 | .gitmodules 58 | 59 | # static code analysis 60 | /.scannerwork 61 | -------------------------------------------------------------------------------- /.github/workflows/projects_check.yml: -------------------------------------------------------------------------------- 1 | name: Check 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | pull_request: 8 | types: [opened, synchronize] 9 | 10 | concurrency: 11 | group: ${{ github.ref }}-${{ github.workflow }}-${{ github.event_name }} 12 | cancel-in-progress: true 13 | 14 | jobs: 15 | changed: 16 | uses: ./.github/workflows/compute-changes.yml 17 | 18 | 19 | style_check: 20 | name: Style 21 | runs-on: ubuntu-latest 22 | steps: 23 | - uses: actions/checkout@v3 24 | - uses: editorconfig-checker/action-editorconfig-checker@main 25 | - run: editorconfig-checker 26 | 27 | 28 | check_coding_style: 29 | name: Code Style 30 | needs: changed 31 | if: ${{ needs.changed.outputs.source_code == 'true' }} 32 | runs-on: ubuntu-latest 33 | steps: 34 | - uses: actions/checkout@v3 35 | - uses: actions/setup-python@v4 36 | with: 37 | python-version: '3.x' 38 | - name: Install dependencies 39 | run: pip install regex 40 | - name: Run style checker 41 | run: python ./utils/check_code_style.py 42 | -------------------------------------------------------------------------------- /source/shared/DisjointSet.h: -------------------------------------------------------------------------------- 1 | /* DisjointSet.h 2 | Copyright (c) 2016 by Michael Zahniser 3 | 4 | Endless Sky is free software: you can redistribute it and/or modify it under the 5 | terms of the GNU General Public License as published by the Free Software 6 | Foundation, either version 3 of the License, or (at your option) any later version. 7 | 8 | Endless Sky is distributed in the hope that it will be useful, but WITHOUT ANY 9 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 10 | PARTICULAR PURPOSE. See the GNU General Public License for more details. 11 | 12 | You should have received a copy of the GNU General Public License along with 13 | this program. If not, see . 14 | */ 15 | 16 | #ifndef DISJOINT_SET_H_ 17 | #define DISJOINT_SET_H_ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | 24 | 25 | // Class for tracking connected components. This is a simplified implementation, 26 | // not a fully optimized one, not intended for huge sets. 27 | class DisjointSet { 28 | public: 29 | void Join(const std::string &first, const std::string &second); 30 | bool IsJoined(const std::string &first, const std::string &second) const; 31 | 32 | 33 | private: 34 | void Add(const std::string &token); 35 | const std::string &Root(const std::string &token) const; 36 | 37 | 38 | private: 39 | std::map> entries; 40 | }; 41 | 42 | 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /source/shared/DataFile.h: -------------------------------------------------------------------------------- 1 | /* DataFile.h 2 | Copyright (c) 2014 by Michael Zahniser 3 | 4 | Endless Sky is free software: you can redistribute it and/or modify it under the 5 | terms of the GNU General Public License as published by the Free Software 6 | Foundation, either version 3 of the License, or (at your option) any later version. 7 | 8 | Endless Sky is distributed in the hope that it will be useful, but WITHOUT ANY 9 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 10 | PARTICULAR PURPOSE. See the GNU General Public License for more details. 11 | 12 | You should have received a copy of the GNU General Public License along with 13 | this program. If not, see . 14 | */ 15 | 16 | #ifndef DATA_FILE_H_ 17 | #define DATA_FILE_H_ 18 | 19 | #include "DataNode.h" 20 | 21 | #include 22 | #include 23 | 24 | 25 | 26 | // A class which represents a hierarchical data file. Each line of the file that 27 | // is not empty or a comment is a "node," and the relationship between the nodes 28 | // is determined by indentation: if a node is more indented than the node before 29 | // it, it is a "child" of that node. Otherwise, it is a "sibling." Each node is 30 | // just a collection of one or more tokens that can be interpreted either as 31 | // strings or as floating point values; see DataNode for more information. 32 | class DataFile { 33 | public: 34 | DataFile() = default; 35 | DataFile(const std::string &path); 36 | DataFile(std::istream &in); 37 | 38 | void Load(const std::string &path); 39 | void Load(std::istream &in); 40 | 41 | std::list::const_iterator begin() const; 42 | std::list::const_iterator end() const; 43 | 44 | 45 | private: 46 | void Load(const char *it, const char *end); 47 | 48 | 49 | private: 50 | DataNode root; 51 | }; 52 | 53 | 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /source/file-check.cpp: -------------------------------------------------------------------------------- 1 | /* file-check.cpp 2 | Copyright (c) 2016 by Michael Zahniser 3 | 4 | Endless Sky is free software: you can redistribute it and/or modify it under the 5 | terms of the GNU General Public License as published by the Free Software 6 | Foundation, either version 3 of the License, or (at your option) any later version. 7 | 8 | Endless Sky is distributed in the hope that it will be useful, but WITHOUT ANY 9 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 10 | PARTICULAR PURPOSE. See the GNU General Public License for more details. 11 | 12 | You should have received a copy of the GNU General Public License along with 13 | this program. If not, see . 14 | */ 15 | 16 | // Program to check data files for non-ASCII characters and non-Unix line endings. 17 | // $ g++ --std=c++11 -o file-check file-check.cpp 18 | // $ ./file-check path/to/data/*.txt 19 | 20 | #include 21 | #include 22 | 23 | using namespace std; 24 | 25 | 26 | 27 | int main(int argc, char *argv[]) 28 | { 29 | for(char **it = argv + 1; *it; ++it) 30 | { 31 | ifstream in(*it, ios::binary); 32 | 33 | in.seekg(0, ios::end); 34 | size_t bytes = in.tellg(); 35 | in.seekg(0, ios::beg); 36 | 37 | char *data = new char[bytes]; 38 | in.read(data, bytes); 39 | char *end = data + bytes; 40 | 41 | int line = 1; 42 | int pos = 1; 43 | for(char *cit = data; cit < end; ++cit, ++pos) 44 | { 45 | if(*cit == '\n') 46 | { 47 | ++line; 48 | pos = 0; 49 | } 50 | else if(*cit == '\t') 51 | continue; 52 | else if(*cit < ' ' || *cit == 127) 53 | { 54 | cerr << *it << ":" << line << ":" << pos << ": Invalid character (" << int(*cit) << ")." << endl; 55 | break; 56 | } 57 | } 58 | if(bytes && end[-1] != '\n') 59 | cerr << *it << ": File does not end with a newline." << endl; 60 | 61 | delete [] data; 62 | } 63 | 64 | return 0; 65 | } 66 | 67 | -------------------------------------------------------------------------------- /source/shared/DataNode.h: -------------------------------------------------------------------------------- 1 | /* DataNode.h 2 | Copyright (c) 2014 by Michael Zahniser 3 | 4 | Endless Sky is free software: you can redistribute it and/or modify it under the 5 | terms of the GNU General Public License as published by the Free Software 6 | Foundation, either version 3 of the License, or (at your option) any later version. 7 | 8 | Endless Sky is distributed in the hope that it will be useful, but WITHOUT ANY 9 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 10 | PARTICULAR PURPOSE. See the GNU General Public License for more details. 11 | 12 | You should have received a copy of the GNU General Public License along with 13 | this program. If not, see . 14 | */ 15 | 16 | #ifndef DATA_NODE_H_ 17 | #define DATA_NODE_H_ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | 24 | 25 | // A DataNode is a single line of a DataFile. It consists of one or more tokens, 26 | // which can be interpreted either as strings or as floating point values, and 27 | // it may also have "children," which may each in turn have their own children. 28 | // The tokens of a node are separated by white space, with quotation marks being 29 | // used to group multiple words into a single token. If the token text contains 30 | // quotation marks, it should be enclosed in backticks instead. 31 | class DataNode { 32 | public: 33 | DataNode(const DataNode *parent = nullptr); 34 | DataNode(const DataNode &other); 35 | 36 | DataNode &operator=(const DataNode &other); 37 | 38 | int Size() const; 39 | const std::string &Token(int index) const; 40 | double Value(int index) const; 41 | 42 | bool HasChildren() const; 43 | std::list::const_iterator begin() const; 44 | std::list::const_iterator end() const; 45 | 46 | // Print a message followed by a "trace" of this node and its parents. 47 | int PrintTrace(const std::string &message = "") const; 48 | 49 | 50 | private: 51 | std::list children; 52 | std::vector tokens; 53 | const DataNode *parent = nullptr; 54 | 55 | friend class DataFile; 56 | }; 57 | 58 | 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /source/shared/DataWriter.h: -------------------------------------------------------------------------------- 1 | /* DataWriter.h 2 | Copyright (c) 2014 by Michael Zahniser 3 | 4 | Endless Sky is free software: you can redistribute it and/or modify it under the 5 | terms of the GNU General Public License as published by the Free Software 6 | Foundation, either version 3 of the License, or (at your option) any later version. 7 | 8 | Endless Sky is distributed in the hope that it will be useful, but WITHOUT ANY 9 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 10 | PARTICULAR PURPOSE. See the GNU General Public License for more details. 11 | 12 | You should have received a copy of the GNU General Public License along with 13 | this program. If not, see . 14 | */ 15 | 16 | #ifndef DATA_WRITER_H_ 17 | #define DATA_WRITER_H_ 18 | 19 | #include 20 | #include 21 | 22 | class DataNode; 23 | 24 | 25 | 26 | // This class writes data in a hierarchical format, where an indented line is 27 | // considered the "child" of the first line above it that is less indented. By 28 | // using this class, you can have a function add data to the file without having 29 | // to tell that function what indentation level it is at. This class also 30 | // automatically adds quotation marks around strings if they contain whitespace. 31 | class DataWriter { 32 | public: 33 | DataWriter(); 34 | 35 | string ToString() const; 36 | 37 | template 38 | void Write(const A &a, B... others); 39 | void Write(const DataNode &node); 40 | void Write(); 41 | 42 | void BeginChild(); 43 | void EndChild(); 44 | 45 | void WriteComment(const std::string &str); 46 | void AddLineBreak(); 47 | 48 | // Write a token, without writing a whole line. Use this very carefully. 49 | void WriteToken(const char *a); 50 | void WriteToken(const std::string &a); 51 | template 52 | void WriteToken(const A &a); 53 | 54 | 55 | private: 56 | std::string indent; 57 | static const std::string space; 58 | const std::string *before; 59 | std::ostringstream out; 60 | }; 61 | 62 | 63 | 64 | template 65 | void DataWriter::Write(const A &a, B... others) 66 | { 67 | WriteToken(a); 68 | Write(others...); 69 | } 70 | 71 | 72 | 73 | template 74 | void DataWriter::WriteToken(const A &a) 75 | { 76 | static_assert(std::is_arithmetic::value, 77 | "DataWriter cannot output anything but strings and arithmetic types."); 78 | 79 | out << *before << a; 80 | before = &space; 81 | } 82 | 83 | 84 | 85 | #endif 86 | -------------------------------------------------------------------------------- /source/shared/DisjointSet.cpp: -------------------------------------------------------------------------------- 1 | /* DisjointSet.cpp 2 | Copyright (c) 2016 by Michael Zahniser 3 | 4 | Endless Sky is free software: you can redistribute it and/or modify it under the 5 | terms of the GNU General Public License as published by the Free Software 6 | Foundation, either version 3 of the License, or (at your option) any later version. 7 | 8 | Endless Sky is distributed in the hope that it will be useful, but WITHOUT ANY 9 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 10 | PARTICULAR PURPOSE. See the GNU General Public License for more details. 11 | 12 | You should have received a copy of the GNU General Public License along with 13 | this program. If not, see . 14 | */ 15 | 16 | #include "DisjointSet.h" 17 | 18 | using namespace std; 19 | 20 | 21 | 22 | void DisjointSet::Join(const string &first, const string &second) 23 | { 24 | Add(first); 25 | Add(second); 26 | 27 | string firstRoot = Root(first); 28 | string secondRoot = Root(second); 29 | if(firstRoot == secondRoot) 30 | return; 31 | 32 | vector &firstEntry = entries[firstRoot]; 33 | vector &secondEntry = entries[secondRoot]; 34 | 35 | bool firstIsSmaller = (firstEntry.size() < secondEntry.size()); 36 | vector &smaller = firstIsSmaller ? firstEntry : secondEntry; 37 | vector &larger = firstIsSmaller ? secondEntry : firstEntry; 38 | 39 | const string &newRoot = firstIsSmaller ? secondRoot : firstRoot; 40 | larger.insert(larger.end(), smaller.begin(), smaller.end()); 41 | for(const string &token : smaller) 42 | { 43 | vector &entry = entries[token]; 44 | if(&entry != &smaller) 45 | entry = vector(1, newRoot); 46 | } 47 | smaller = vector(1, newRoot); 48 | } 49 | 50 | 51 | 52 | bool DisjointSet::IsJoined(const string &first, const string &second) const 53 | { 54 | if(first == second) 55 | return true; 56 | 57 | string firstRoot = Root(first); 58 | string secondRoot = Root(second); 59 | if(firstRoot.empty() || secondRoot.empty()) 60 | return false; 61 | 62 | return firstRoot == secondRoot; 63 | } 64 | 65 | 66 | 67 | void DisjointSet::Add(const string &token) 68 | { 69 | vector &entry = entries[token]; 70 | if(entry.empty()) 71 | entry.emplace_back(token); 72 | } 73 | 74 | 75 | 76 | const string &DisjointSet::Root(const string &token) const 77 | { 78 | static const string EMPTY; 79 | auto it = entries.find(token); 80 | return (it == entries.end() || it->second.empty()) ? EMPTY : it->second.front(); 81 | } 82 | -------------------------------------------------------------------------------- /source/shared/DataWriter.cpp: -------------------------------------------------------------------------------- 1 | /* DataWriter.cpp 2 | Copyright (c) 2014 by Michael Zahniser 3 | 4 | Endless Sky is free software: you can redistribute it and/or modify it under the 5 | terms of the GNU General Public License as published by the Free Software 6 | Foundation, either version 3 of the License, or (at your option) any later version. 7 | 8 | Endless Sky is distributed in the hope that it will be useful, but WITHOUT ANY 9 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 10 | PARTICULAR PURPOSE. See the GNU General Public License for more details. 11 | 12 | You should have received a copy of the GNU General Public License along with 13 | this program. If not, see . 14 | */ 15 | 16 | #include "DataWriter.h" 17 | 18 | #include "DataNode.h" 19 | 20 | #if defined _WIN32 21 | #include 22 | #endif 23 | 24 | #include 25 | 26 | using namespace std; 27 | 28 | 29 | 30 | const string DataWriter::space = " "; 31 | 32 | 33 | 34 | DataWriter::DataWriter() 35 | : before(&indent) 36 | { 37 | out.precision(8); 38 | } 39 | 40 | 41 | 42 | string DataWriter::ToString() const 43 | { 44 | return out.str(); 45 | } 46 | 47 | 48 | 49 | void DataWriter::Write(const DataNode &node) 50 | { 51 | for(int i = 0; i < node.Size(); ++i) 52 | WriteToken(node.Token(i).c_str()); 53 | Write(); 54 | 55 | if(node.begin() != node.end()) 56 | { 57 | BeginChild(); 58 | { 59 | for(const DataNode &child : node) 60 | Write(child); 61 | } 62 | EndChild(); 63 | } 64 | } 65 | 66 | 67 | 68 | void DataWriter::Write() 69 | { 70 | out << '\n'; 71 | before = &indent; 72 | } 73 | 74 | 75 | 76 | void DataWriter::BeginChild() 77 | { 78 | indent += '\t'; 79 | } 80 | 81 | 82 | 83 | void DataWriter::EndChild() 84 | { 85 | indent.erase(indent.length() - 1); 86 | } 87 | 88 | 89 | 90 | void DataWriter::WriteComment(const string &str) 91 | { 92 | out << indent << "# " << str << '\n'; 93 | } 94 | 95 | 96 | 97 | void DataWriter::AddLineBreak() 98 | { 99 | out << '\n'; 100 | } 101 | 102 | 103 | 104 | void DataWriter::WriteToken(const char *a) 105 | { 106 | WriteToken(string(a)); 107 | } 108 | 109 | 110 | 111 | void DataWriter::WriteToken(const string &a) 112 | { 113 | // Figure out what kind of quotation marks need to be used for this string. 114 | bool hasSpace = any_of(a.begin(), a.end(), [](char c) { return isspace(c); }); 115 | bool hasQuote = any_of(a.begin(), a.end(), [](char c) { return (c == '"'); }); 116 | // Write the token, enclosed in quotes if necessary. 117 | out << *before; 118 | if(hasQuote) 119 | out << '`' << a << '`'; 120 | else if(hasSpace) 121 | out << '"' << a << '"'; 122 | else 123 | out << a; 124 | before = &space; 125 | } 126 | -------------------------------------------------------------------------------- /source/map-component.cpp: -------------------------------------------------------------------------------- 1 | /* map-component.cpp 2 | Copyright (c) 2016 by Michael Zahniser 3 | 4 | Endless Sky is free software: you can redistribute it and/or modify it under the 5 | terms of the GNU General Public License as published by the Free Software 6 | Foundation, either version 3 of the License, or (at your option) any later version. 7 | 8 | Endless Sky is distributed in the hope that it will be useful, but WITHOUT ANY 9 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 10 | PARTICULAR PURPOSE. See the GNU General Public License for more details. 11 | 12 | You should have received a copy of the GNU General Public License along with 13 | this program. If not, see . 14 | */ 15 | 16 | // map-component: program to extract one connected component (e.g. the territory 17 | // of one species) from the map. You can then edit it and map-merge it back in. 18 | // $ g++ --std=c++11 -o map-component map-component.cpp 19 | // $ ./map-component [...] > 20 | 21 | #include "shared/DisjointSet.cpp" 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | using namespace std; 29 | 30 | void PrintHelp(); 31 | bool IsEmpty(const string &line); 32 | string Token(const string &line, int index = 0); 33 | 34 | 35 | 36 | int main(int argc, char *argv[]) 37 | { 38 | if(argc < 2) 39 | { 40 | PrintHelp(); 41 | return 1; 42 | } 43 | 44 | map systems; 45 | DisjointSet links; 46 | 47 | ifstream in(argv[1]); 48 | string line; 49 | string current; 50 | while(getline(in, line)) 51 | { 52 | // Skip blank lines. 53 | if(IsEmpty(line)) 54 | continue; 55 | // If this line is not indented, it starts a new root object. 56 | if(line[0] > ' ') 57 | current.clear(); 58 | 59 | if(Token(line, 0) == "system") 60 | current = Token(line, 1); 61 | else if(!current.empty() && Token(line, 0) == "link") 62 | links.Join(current, Token(line, 1)); 63 | 64 | if(!current.empty()) 65 | { 66 | systems[current] += line; 67 | systems[current] += '\n'; 68 | } 69 | } 70 | 71 | vector components; 72 | for(char **it = argv + 2; *it; ++it) 73 | components.push_back(*it); 74 | for(const pair &it : systems) 75 | { 76 | bool match = components.empty(); 77 | for(const string &component : components) 78 | match |= links.IsJoined(it.first, component); 79 | 80 | if(match) 81 | cout << it.second << endl; 82 | } 83 | return 0; 84 | } 85 | 86 | 87 | 88 | void PrintHelp() 89 | { 90 | cerr << endl; 91 | cerr << "Usage: $ map-component [...]" << endl; 92 | cerr << " where is the map file to extract a component from," << endl; 93 | cerr << " and is any system in that component." << endl; 94 | cerr << endl; 95 | } 96 | 97 | 98 | 99 | bool IsEmpty(const string &line) 100 | { 101 | for(char c : line) 102 | if(c > ' ') 103 | return false; 104 | return true; 105 | } 106 | 107 | 108 | 109 | string Token(const string &line, int index) 110 | { 111 | string::const_iterator it = line.begin(); 112 | string::const_iterator end = line.end(); 113 | 114 | string token; 115 | for( ; it != end && index >= 0; --index) 116 | { 117 | for( ; it != end && *it <= ' '; ++it) {} 118 | 119 | if(it != end) 120 | { 121 | char quote = '\0'; 122 | if(*it == '"' || *it == '`') 123 | quote = *it; 124 | 125 | if(quote) 126 | { 127 | ++it; 128 | for( ; it != end && *it != quote; ++it) 129 | if(!index) 130 | token += *it; 131 | if(it != end) 132 | ++it; 133 | } 134 | else 135 | { 136 | for( ; it != end && *it > ' '; ++it) 137 | if(!index) 138 | token += *it; 139 | } 140 | } 141 | bool quote = false; 142 | for( ; it != end && *it > ' '; ++it) 143 | if(!index) 144 | token += *it; 145 | } 146 | return token; 147 | } 148 | -------------------------------------------------------------------------------- /source/add-minables.cpp: -------------------------------------------------------------------------------- 1 | /* add-minables.cpp 2 | Copyright (c) 2016 by Michael Zahniser 3 | 4 | Endless Sky is free software: you can redistribute it and/or modify it under the 5 | terms of the GNU General Public License as published by the Free Software 6 | Foundation, either version 3 of the License, or (at your option) any later version. 7 | 8 | Endless Sky is distributed in the hope that it will be useful, but WITHOUT ANY 9 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 10 | PARTICULAR PURPOSE. See the GNU General Public License for more details. 11 | 12 | You should have received a copy of the GNU General Public License along with 13 | this program. If not, see . 14 | */ 15 | 16 | // add-minables: program to add "minables" to a map file. 17 | // $ g++ --std=c++11 -o add-minables add-minables.cpp 18 | // $ ./add-minables < > 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | using namespace std; 28 | 29 | bool StartsWith(const string &line, const string &str) 30 | { 31 | return line.length() >= str.length() && !line.compare(0, str.length(), str); 32 | } 33 | 34 | string Token(const string &line, int index) 35 | { 36 | size_t pos = 0; 37 | 38 | while(pos < line.length()) 39 | { 40 | while(line[pos] <= ' ') 41 | ++pos; 42 | 43 | char quote = 0; 44 | if(line[pos] == '"' || line[pos] == '`') 45 | quote = line[pos++]; 46 | size_t start = pos; 47 | while(pos < line.length() && (quote ? (line[pos] != quote) : (line[pos] > ' '))) 48 | ++pos; 49 | 50 | if(!index--) 51 | return line.substr(start, pos - start); 52 | pos = pos + !!quote; 53 | } 54 | return ""; 55 | } 56 | 57 | double Value(const string &line, int index) 58 | { 59 | double value = 0.; 60 | istringstream(Token(line, index)) >> value; 61 | return value; 62 | } 63 | 64 | 65 | 66 | int main(int argc, char *argv[]) 67 | { 68 | srand(time(nullptr)); 69 | 70 | random_device rd; 71 | mt19937 gen(rd()); 72 | uniform_real_distribution<> real(0., 1.); 73 | 74 | map probability = { 75 | {"aluminum", 0.12}, 76 | {"copper", 0.08}, 77 | {"gold", 0.02}, 78 | {"iron", 0.13}, 79 | {"lead", 0.15}, 80 | {"neodymium", 0.03}, 81 | {"platinum", 0.01}, 82 | {"silicon", 0.2}, 83 | {"silver", 0.05}, 84 | {"titanium", 0.11}, 85 | {"tungsten", 0.06}, 86 | {"uranium", 0.04} 87 | }; 88 | 89 | bool skip = true; 90 | bool previousWasHabitable = false; 91 | bool previousWasAsteroids = false; 92 | int totalCount = 0; 93 | double totalEnergy = 0.; 94 | 95 | string line; 96 | while(getline(cin, line)) 97 | { 98 | if(StartsWith(line, "\thabitable")) 99 | previousWasHabitable = true; 100 | else if(previousWasHabitable) 101 | { 102 | previousWasHabitable = false; 103 | skip = StartsWith(line, "\tbelt"); 104 | totalCount = 0; 105 | totalEnergy = 0.; 106 | if(!skip) 107 | cout << "\tbelt " << static_cast(1000. + 1000. * real(gen)) << '\n'; 108 | } 109 | 110 | if(!skip && StartsWith(line, "\tasteroids")) 111 | { 112 | previousWasAsteroids = true; 113 | int count = Value(line, 2); 114 | double energy = Value(line, 3); 115 | totalCount += count; 116 | totalEnergy += energy * count; 117 | } 118 | else if(previousWasAsteroids) 119 | { 120 | previousWasAsteroids = false; 121 | double meanEnergy = totalCount ? (totalEnergy / totalCount) : 0.; 122 | 123 | map choices; 124 | 125 | // Minables should be much less prevalent than ordinary asteroids. 126 | totalCount /= 4; 127 | for(int i = 0; i < 3; ++i) 128 | { 129 | totalCount = rand() % (totalCount + 1); 130 | if(!totalCount) 131 | break; 132 | 133 | double choice = real(gen); 134 | for(const auto &it : probability) 135 | { 136 | choice -= it.second; 137 | if(choice < 0.) 138 | { 139 | choices[it.first] += totalCount; 140 | break; 141 | } 142 | } 143 | } 144 | for(const auto &it : choices) 145 | { 146 | double energy = (real(gen) + 1.) * meanEnergy; 147 | cout << "\tminables " << it.first << " " << it.second << " " << energy << "\n"; 148 | } 149 | } 150 | cout << line << '\n'; 151 | } 152 | return 0; 153 | } 154 | -------------------------------------------------------------------------------- /source/shared/DataNode.cpp: -------------------------------------------------------------------------------- 1 | /* DataNode.cpp 2 | Copyright (c) 2014 by Michael Zahniser 3 | 4 | Endless Sky is free software: you can redistribute it and/or modify it under the 5 | terms of the GNU General Public License as published by the Free Software 6 | Foundation, either version 3 of the License, or (at your option) any later version. 7 | 8 | Endless Sky is distributed in the hope that it will be useful, but WITHOUT ANY 9 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 10 | PARTICULAR PURPOSE. See the GNU General Public License for more details. 11 | 12 | You should have received a copy of the GNU General Public License along with 13 | this program. If not, see . 14 | */ 15 | 16 | #include "DataNode.h" 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | using namespace std; 24 | 25 | 26 | 27 | DataNode::DataNode(const DataNode *parent) 28 | : parent(parent) 29 | { 30 | tokens.reserve(4); 31 | } 32 | 33 | 34 | 35 | DataNode::DataNode(const DataNode &other) 36 | : children(other.children), tokens(other.tokens) 37 | { 38 | } 39 | 40 | 41 | 42 | DataNode &DataNode::operator=(const DataNode &other) 43 | { 44 | children = other.children; 45 | tokens = other.tokens; 46 | return *this; 47 | } 48 | 49 | 50 | 51 | int DataNode::Size() const 52 | { 53 | return tokens.size(); 54 | } 55 | 56 | 57 | 58 | const string &DataNode::Token(int index) const 59 | { 60 | return tokens[index]; 61 | } 62 | 63 | 64 | 65 | double DataNode::Value(int index) const 66 | { 67 | // Check for empty strings and out-of-bounds indices. 68 | if(static_cast(index) >= tokens.size() || tokens[index].empty()) 69 | { 70 | PrintTrace("Requested token index (" + to_string(index) + ") is out of bounds:"); 71 | return 0.; 72 | } 73 | 74 | // Allowed format: "[+-]?[0-9]*[.]?[0-9]*([eE][+-]?[0-9]*)?". 75 | const char *it = tokens[index].c_str(); 76 | if(*it != '-' && *it != '.' && *it != '+' && !(*it >= '0' && *it <= '9')) 77 | { 78 | PrintTrace("Cannot convert value \"" + tokens[index] + "\" to a number:"); 79 | return 0.; 80 | } 81 | 82 | // Check for leading sign. 83 | double sign = (*it == '-') ? -1. : 1.; 84 | it += (*it == '-' || *it == '+'); 85 | 86 | // Digits before the decimal point. 87 | int64_t value = 0; 88 | while(*it >= '0' && *it <= '9') 89 | value = (value * 10) + (*it++ - '0'); 90 | 91 | // Digits after the decimal point (if any). 92 | int64_t power = 0; 93 | if(*it == '.') 94 | { 95 | ++it; 96 | while(*it >= '0' && *it <= '9') 97 | { 98 | value = (value * 10) + (*it++ - '0'); 99 | --power; 100 | } 101 | } 102 | 103 | // Exponent. 104 | if(*it == 'e' || *it == 'E') 105 | { 106 | ++it; 107 | int64_t sign = (*it == '-') ? -1 : 1; 108 | it += (*it == '-' || *it == '+'); 109 | 110 | int64_t exponent = 0; 111 | while(*it >= '0' && *it <= '9') 112 | exponent = (exponent * 10) + (*it++ - '0'); 113 | 114 | power += sign * exponent; 115 | } 116 | 117 | // Compose the return value. 118 | return copysign(value * pow(10., power), sign); 119 | } 120 | 121 | 122 | 123 | bool DataNode::HasChildren() const 124 | { 125 | return !children.empty(); 126 | } 127 | 128 | 129 | 130 | list::const_iterator DataNode::begin() const 131 | { 132 | return children.begin(); 133 | } 134 | 135 | 136 | 137 | list::const_iterator DataNode::end() const 138 | { 139 | return children.end(); 140 | } 141 | 142 | 143 | 144 | // Print a message followed by a "trace" of this node and its parents. 145 | int DataNode::PrintTrace(const string &message) const 146 | { 147 | if(!message.empty()) 148 | cerr << endl << message << endl; 149 | 150 | int indent = 0; 151 | if(parent) 152 | indent = parent->PrintTrace() + 2; 153 | if(tokens.empty()) 154 | return indent; 155 | 156 | string line(indent, ' '); 157 | for(const string &token : tokens) 158 | { 159 | if(&token != &tokens.front()) 160 | line += ' '; 161 | bool hasSpace = any_of(token.begin(), token.end(), [](char c) { return isspace(c); }); 162 | bool hasQuote = any_of(token.begin(), token.end(), [](char c) { return (c == '"'); }); 163 | if(hasSpace) 164 | line += hasQuote ? '`' : '"'; 165 | line += token; 166 | if(hasSpace) 167 | line += hasQuote ? '`' : '"'; 168 | } 169 | cerr << line << endl; 170 | 171 | return indent; 172 | } 173 | -------------------------------------------------------------------------------- /source/color-converter.cpp: -------------------------------------------------------------------------------- 1 | /* color-converter.cpp 2 | Copyright (c) 2023 by warp-core 3 | 4 | Endless Sky is free software: you can redistribute it and/or modify it under the 5 | terms of the GNU General Public License as published by the Free Software 6 | Foundation, either version 3 of the License, or (at your option) any later version. 7 | 8 | Endless Sky is distributed in the hope that it will be useful, but WITHOUT ANY 9 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 10 | PARTICULAR PURPOSE. See the GNU General Public License for more details. 11 | 12 | You should have received a copy of the GNU General Public License along with 13 | this program. If not, see . 14 | */ 15 | 16 | // A program for converting between the Endless Sky rgba color code format 17 | // and 24-bit hexadecimal HTML colors. 18 | // $ g++ --std=c++11 -o color-converter color-converter.cpp 19 | // $ ./color-converter 20 | // Takes the given ES color and prints to STDOUT the HTML representation. 21 | // $ ./color-converter #RRGGBB 22 | // Takes the given HTML color and prints to STDOUT the ES color representation. 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | using namespace std; 30 | 31 | namespace { 32 | double ParseString(const string &input) 33 | { 34 | // Digits before the decimal point. 35 | int64_t value = 0; 36 | 37 | auto it = input.begin(); 38 | while(*it >= '0' && *it <= '9') 39 | value = (value * 10) + (*it++ - '0'); 40 | 41 | // Digits after the decimal point (if any). 42 | int64_t power = 0; 43 | if(*it == '.') 44 | { 45 | ++it; 46 | while(*it >= '0' && *it <= '9') 47 | { 48 | value = (value * 10) + (*it++ - '0'); 49 | --power; 50 | } 51 | } 52 | 53 | if(*it) 54 | cerr << "Encountered invalid character in numerical value." << endl; 55 | 56 | double result = value; 57 | result *= pow(10., power); 58 | return result; 59 | } 60 | 61 | int HexToDec(const char hex) 62 | { 63 | if(hex >= '0' && hex <= '9') 64 | return hex - '0'; 65 | if(hex >= 'A' && hex <= 'F') 66 | return hex + 10 - 'A'; 67 | if(hex >= 'a' && hex <= 'f') 68 | return hex + 10 - 'a'; 69 | cerr << "Invalid character in hexadecimal sequence: " << hex << endl; 70 | return 0; 71 | } 72 | 73 | string DecToHex(const int input) 74 | { 75 | static const vector conversion = { 76 | "0", 77 | "1", 78 | "2", 79 | "3", 80 | "4", 81 | "5", 82 | "6", 83 | "7", 84 | "8", 85 | "9", 86 | "A", 87 | "B", 88 | "C", 89 | "D", 90 | "E", 91 | "F", 92 | }; 93 | 94 | if(input >= 16) 95 | return DecToHex(input / 16) + conversion[input % 16]; 96 | return conversion[input]; 97 | } 98 | 99 | void PrintHelp() 100 | { 101 | cerr << " : pass three numeric values between 0 and 1, representing a color in the format used" 102 | " in Endless Sky data, and the corresponding HTML color code will be printed to STDOUT." << endl; 103 | cerr << "#RRGGBB: pass a six character hexadecimal representation of a 24-bit color (HTML format), beginning" 104 | " with a '#' symbol and the corresponding Endless Sky color code will be printed to STDOUT." << endl; 105 | cerr << endl; 106 | cerr << "Return values:" << endl; 107 | cerr << " 1: incorrect argument count. Expected 1 or 3." << endl; 108 | cerr << " 2: too few arguments for Endless Sky color code, but HTML code does not begin with '#'." << endl; 109 | cerr << " 3: too few characters in HTML color code." << endl; 110 | } 111 | } 112 | 113 | 114 | 115 | int main(int argc, char *argv[]) 116 | { 117 | if(argc == 2) 118 | { 119 | string html = argv[1]; 120 | 121 | if(html[0] != '#') 122 | { 123 | PrintHelp(); 124 | return 2; 125 | } 126 | if(html.size() < 7) 127 | { 128 | PrintHelp(); 129 | return 3; 130 | } 131 | 132 | double rgb[3]; 133 | for(int i = 1; i < 6; ++i) 134 | rgb[i] = (16 * HexToDec(html[i]) + HexToDec(html[++i])) / 255.; 135 | 136 | for(int i = 0; i < 3; ++i) 137 | { 138 | if(i) 139 | cout << ' '; 140 | cout << rgb[i]; 141 | } 142 | 143 | return 0; 144 | } 145 | 146 | if(argc == 4) 147 | { 148 | int rgb[3]; 149 | for(int i = 0; i < 3; ++i) 150 | rgb[i] = ParseString(argv[i + 1]) * 255; 151 | 152 | string result = "#"; 153 | for(int i = 0; i < 3; ++i) 154 | { 155 | rgb[i] = max(rgb[i], 0); 156 | rgb[i] = min(rgb[i], 255); 157 | string val = DecToHex(rgb[i]); 158 | if(val.size() < 2) 159 | result += "0"; 160 | result += val; 161 | } 162 | 163 | cout << result; 164 | 165 | return 0; 166 | } 167 | 168 | PrintHelp(); 169 | return 1; 170 | } 171 | -------------------------------------------------------------------------------- /source/map-merge.cpp: -------------------------------------------------------------------------------- 1 | /* map-merge.cpp 2 | Copyright (c) 2016 by Michael Zahniser 3 | 4 | Endless Sky is free software: you can redistribute it and/or modify it under the 5 | terms of the GNU General Public License as published by the Free Software 6 | Foundation, either version 3 of the License, or (at your option) any later version. 7 | 8 | Endless Sky is distributed in the hope that it will be useful, but WITHOUT ANY 9 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 10 | PARTICULAR PURPOSE. See the GNU General Public License for more details. 11 | 12 | You should have received a copy of the GNU General Public License along with 13 | this program. If not, see . 14 | */ 15 | 16 | // map-merge: program to merge map data from two or more files. 17 | // $ g++ --std=c++11 -o map-merge map-merge.cpp 18 | // $ ./map-merge ... > 19 | 20 | #include "shared/DataFile.cpp" 21 | #include "shared/DataNode.cpp" 22 | #include "shared/DataWriter.cpp" 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | using namespace std; 31 | 32 | typedef map> Object; 33 | 34 | void PrintHelp(); 35 | void Write(DataWriter &out, const string &root, const map &data, const vector &order); 36 | 37 | 38 | 39 | int main(int argc, char *argv[]) 40 | { 41 | if(argc < 2) 42 | { 43 | PrintHelp(); 44 | return 1; 45 | } 46 | 47 | map galaxies; 48 | map systems; 49 | map planets; 50 | vector others; 51 | 52 | string line; 53 | for(char **it = argv + 1; *it; ++it) 54 | { 55 | DataFile file(*it); 56 | for(const DataNode &node : file) 57 | { 58 | Object *current = nullptr; 59 | if(node.Token(0) == "galaxy") 60 | current = &galaxies[node.Token(1)]; 61 | else if(node.Token(0) == "system") 62 | current = &systems[node.Token(1)]; 63 | else if(node.Token(0) == "planet") 64 | current = &planets[node.Token(1)]; 65 | else 66 | { 67 | others.push_back(node); 68 | continue; 69 | } 70 | 71 | set active; 72 | for(const DataNode &child : node) 73 | { 74 | if(!active.count(child.Token(0))) 75 | { 76 | (*current)[child.Token(0)].clear(); 77 | active.insert(child.Token(0)); 78 | } 79 | (*current)[child.Token(0)].push_back(child); 80 | } 81 | } 82 | } 83 | 84 | static const vector GALAXY = { 85 | "pos", "sprite"}; 86 | static const vector SYSTEM = { 87 | "pos", "government", "music", "habitable", "belt", "link", "asteroids", "minables", 88 | "trade", "fleet", "object"}; 89 | static const vector PLANET = { 90 | "attributes", "landscape", "music", "description", "spaceport", "shipyard", "outfitter", 91 | "required reputation", "bribe", "security", "tribute"}; 92 | 93 | DataWriter out; 94 | Write(out, "galaxy", galaxies, GALAXY); 95 | Write(out, "system", systems, SYSTEM); 96 | Write(out, "planet", planets, PLANET); 97 | 98 | string output = out.ToString(); 99 | // Handle the fact that the map editor always uses backticks for 100 | // descriptions and spaceports even when not required. 101 | static const string FIX[] = {"\n\tdescription \"", "\n\tspaceport \""}; 102 | for(const string &fix : FIX) 103 | { 104 | size_t start = 0; 105 | while(true) 106 | { 107 | size_t pos = output.find(fix, start); 108 | if(pos == string::npos) 109 | break; 110 | 111 | pos += fix.length(); 112 | output[pos - 1] = '`'; 113 | while(pos < output.length() && output[pos] != '\n') 114 | ++pos; 115 | output[pos - 1] = '`'; 116 | start = pos; 117 | } 118 | } 119 | cout << output; 120 | 121 | return 0; 122 | } 123 | 124 | 125 | 126 | void PrintHelp() 127 | { 128 | cerr << endl; 129 | cerr << "Usage: $ map-merge ..." << endl; 130 | cerr << endl; 131 | } 132 | 133 | 134 | 135 | void Write(DataWriter &out, const string &root, const map &data, const vector &order) 136 | { 137 | for(const auto &it : data) 138 | { 139 | out.Write(root, it.first); 140 | out.BeginChild(); 141 | 142 | const Object &object = it.second; 143 | set used; 144 | for(const string &tag : order) 145 | { 146 | used.insert(tag); 147 | 148 | auto oit = object.find(tag); 149 | if(oit == object.end()) 150 | continue; 151 | 152 | for(const DataNode &node : oit->second) 153 | out.Write(node); 154 | } 155 | 156 | for(const auto &oit : object) 157 | if(!used.count(oit.first)) 158 | { 159 | for(const DataNode &node : oit.second) 160 | out.Write(node); 161 | } 162 | 163 | out.EndChild(); 164 | out.AddLineBreak(); 165 | } 166 | } 167 | -------------------------------------------------------------------------------- /source/freetype.cpp: -------------------------------------------------------------------------------- 1 | /* freetype.cpp 2 | Copyright (c) 2016 by Michael Zahniser 3 | 4 | Endless Sky is free software: you can redistribute it and/or modify it under the 5 | terms of the GNU General Public License as published by the Free Software 6 | Foundation, either version 3 of the License, or (at your option) any later version. 7 | 8 | Endless Sky is distributed in the hope that it will be useful, but WITHOUT ANY 9 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 10 | PARTICULAR PURPOSE. See the GNU General Public License for more details. 11 | 12 | You should have received a copy of the GNU General Public License along with 13 | this program. If not, see . 14 | */ 15 | 16 | // g++ -o freetype freetype.cpp `pkg-config --cflags --libs freetype2` 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | #include 23 | #include FT_FREETYPE_H 24 | 25 | using namespace std; 26 | 27 | static const int GLYPHS = 98; 28 | 29 | // static const int FONT_SIZE = 14; 30 | // static const int CHAR_W = 28; 31 | // static const int CHAR_H = 32; 32 | // static const int BASE = 26; 33 | // static const int LEFT = 2; 34 | // static const int DPI = 72; 35 | 36 | static const int FONT_SIZE = 18; 37 | static const int CHAR_W = 36; 38 | static const int CHAR_H = 36; 39 | static const int BASE = 30; 40 | static const int LEFT = 2; 41 | static const int DPI = 72; 42 | 43 | static const int WIDTH = CHAR_W * GLYPHS; 44 | static const int HEIGHT = CHAR_H; 45 | static const int GLYPH_PITCH = CHAR_W; 46 | 47 | static const char *filename = "/usr/share/fonts/truetype/ubuntu-font-family/Ubuntu-R.ttf"; 48 | 49 | 50 | 51 | int main(int argc, char *argv[]) 52 | { 53 | FT_Library library; 54 | FT_Init_FreeType(&library); 55 | 56 | FT_Face face; 57 | FT_New_Face(library, filename, 0, &face); 58 | 59 | FT_Set_Char_Size(face, FONT_SIZE * 64, 0, DPI, 0); 60 | FT_GlyphSlot slot = face->glyph; 61 | 62 | // Hint the font for normal DPI, but render it at high DPI. 63 | FT_Matrix transform; 64 | transform.xx = 0x20000; 65 | transform.xy = 0x00000; 66 | transform.yx = 0x00000; 67 | transform.yy = 0x20000; 68 | FT_Vector offset; 69 | offset.x = 0; 70 | offset.y = 0; 71 | FT_Set_Transform(face, &transform, &offset); 72 | 73 | vector image(WIDTH * HEIGHT, 0); 74 | vector::iterator start = image.begin(); 75 | for(int n = 32; n < 130; ++n) 76 | { 77 | // Map normal quotes to curly quotes. 78 | int trueN = n; 79 | if(n == '\'') 80 | trueN = 0x2019; 81 | if(n == '"') 82 | trueN = 0x201D; 83 | if(n == 128) 84 | trueN = 0x2018; 85 | if(n == 129) 86 | trueN = 0x201C; 87 | FT_Load_Char(face, trueN, FT_LOAD_RENDER | FT_LOAD_FORCE_AUTOHINT); 88 | 89 | // cout << n << '\t' << "'" << char(n) << '\t' << slot->bitmap.width << '\t' 90 | // << slot->bitmap.rows << '\t' << slot->bitmap_left << '\t' 91 | // << slot->bitmap_top << endl; 92 | 93 | // Copy the glyph into the output bitmap. 94 | for(int row = 0; row < slot->bitmap.rows; ++row) 95 | { 96 | int y = BASE - slot->bitmap_top + row; 97 | if(y < 0 || y >= CHAR_H) 98 | continue; 99 | 100 | vector::iterator it = start + WIDTH * (CHAR_H - 1 - y) + LEFT; 101 | // If drawing at 2x resolution, match the 1x resolution alignment. 102 | if(slot->bitmap_left & 1) 103 | ++it; 104 | for(int x = 0; x < slot->bitmap.width; ++x) 105 | *it++ = slot->bitmap.buffer[row * slot->bitmap.pitch + x]; 106 | } 107 | start += GLYPH_PITCH; 108 | } 109 | 110 | ofstream out("font.bmp", ios::out | ios::binary); 111 | out.put('B'); 112 | out.put('M'); 113 | 114 | unsigned size = WIDTH * HEIGHT * 4 + 54; 115 | out.put((size >> 0) & 0xFF); 116 | out.put((size >> 8) & 0xFF); 117 | out.put((size >> 16) & 0xFF); 118 | out.put((size >> 24) & 0xFF); 119 | out.put(0); 120 | out.put(0); 121 | out.put(0); 122 | out.put(0); 123 | out.put(54); 124 | out.put(0); 125 | out.put(0); 126 | out.put(0); 127 | 128 | out.put(40); 129 | out.put(0); 130 | out.put(0); 131 | out.put(0); 132 | out.put((WIDTH >> 0) & 0xFF); 133 | out.put((WIDTH >> 8) & 0xFF); 134 | out.put((WIDTH >> 16) & 0xFF); 135 | out.put((WIDTH >> 24) & 0xFF); 136 | out.put((HEIGHT >> 0) & 0xFF); 137 | out.put((HEIGHT >> 8) & 0xFF); 138 | out.put((HEIGHT >> 16) & 0xFF); 139 | out.put((HEIGHT >> 24) & 0xFF); 140 | out.put(1); 141 | out.put(0); 142 | out.put(4 * 8); 143 | out.put(0); 144 | for(int i = 0; i < 24; ++i) 145 | out.put(0); 146 | 147 | for(vector::iterator it = image.begin(); it != image.end(); ++it) 148 | { 149 | out.put(*it); 150 | out.put(*it); 151 | out.put(*it); 152 | out.put(255); 153 | } 154 | 155 | return 0; 156 | } 157 | -------------------------------------------------------------------------------- /source/shared/DataFile.cpp: -------------------------------------------------------------------------------- 1 | /* DataFile.cpp 2 | Copyright (c) 2014 by Michael Zahniser 3 | 4 | Endless Sky is free software: you can redistribute it and/or modify it under the 5 | terms of the GNU General Public License as published by the Free Software 6 | Foundation, either version 3 of the License, or (at your option) any later version. 7 | 8 | Endless Sky is distributed in the hope that it will be useful, but WITHOUT ANY 9 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 10 | PARTICULAR PURPOSE. See the GNU General Public License for more details. 11 | 12 | You should have received a copy of the GNU General Public License along with 13 | this program. If not, see . 14 | */ 15 | 16 | #include "DataFile.h" 17 | 18 | #if defined _WIN32 19 | #include 20 | #endif 21 | 22 | #include 23 | #include 24 | 25 | using namespace std; 26 | 27 | 28 | 29 | DataFile::DataFile(const string &path) 30 | { 31 | Load(path); 32 | } 33 | 34 | 35 | 36 | DataFile::DataFile(istream &in) 37 | { 38 | Load(in); 39 | } 40 | 41 | 42 | 43 | void DataFile::Load(const string &path) 44 | { 45 | #if defined _WIN32 46 | FILE *file = _wfopen(ToUTF16(path).c_str(), L"rb"); 47 | #else 48 | FILE *file = fopen(path.c_str(), "rb"); 49 | #endif 50 | string data; 51 | if(!file) 52 | return; 53 | 54 | // Find the remaining number of bytes in the file. 55 | size_t start = ftell(file); 56 | fseek(file, 0, SEEK_END); 57 | size_t size = ftell(file) - start; 58 | // Reserve one extra byte in case there is no final '\n'. 59 | data.reserve(size + 1); 60 | data.resize(size); 61 | fseek(file, start, SEEK_SET); 62 | 63 | // Read the file data. 64 | size_t bytes = fread(&data[0], 1, data.size(), file); 65 | if(bytes != data.size()) 66 | throw runtime_error("Error reading file!"); 67 | 68 | // As a sentinel, make sure the file always ends in a newline. 69 | if(data.empty() || data.back() != '\n') 70 | data.push_back('\n'); 71 | 72 | Load(&*data.begin(), &*data.end()); 73 | } 74 | 75 | 76 | 77 | void DataFile::Load(istream &in) 78 | { 79 | vector data; 80 | 81 | static const size_t BLOCK = 4096; 82 | while(in) 83 | { 84 | size_t currentSize = data.size(); 85 | data.resize(currentSize + BLOCK); 86 | in.read(&*data.begin() + currentSize, BLOCK); 87 | data.resize(currentSize + in.gcount()); 88 | } 89 | // As a sentinel, make sure the file always ends in a newline. 90 | if(data.back() != '\n') 91 | data.push_back('\n'); 92 | 93 | Load(&*data.begin(), &*data.end()); 94 | } 95 | 96 | 97 | 98 | list::const_iterator DataFile::begin() const 99 | { 100 | return root.begin(); 101 | } 102 | 103 | 104 | 105 | list::const_iterator DataFile::end() const 106 | { 107 | return root.end(); 108 | } 109 | 110 | 111 | 112 | void DataFile::Load(const char *it, const char *end) 113 | { 114 | vector stack(1, &root); 115 | vector whiteStack(1, -1); 116 | 117 | for( ; it != end; ++it) 118 | { 119 | // Find the first non-white character in this line. 120 | int white = 0; 121 | for( ; *it <= ' ' && *it != '\n'; ++it) 122 | ++white; 123 | 124 | // If the line is a comment, skip to the end of the line. 125 | if(*it == '#') 126 | { 127 | while(*it != '\n') 128 | ++it; 129 | } 130 | // Skip empty lines (including comment lines). 131 | if(*it == '\n') 132 | continue; 133 | 134 | // Determine where in the node tree we are inserting this node, based on 135 | // whether it has more indentation that the previous node, less, or the same. 136 | while(whiteStack.back() >= white) 137 | { 138 | whiteStack.pop_back(); 139 | stack.pop_back(); 140 | } 141 | 142 | // Add this node as a child of the proper node. 143 | list &children = stack.back()->children; 144 | children.emplace_back(stack.back()); 145 | DataNode &node = children.back(); 146 | 147 | // Remember where in the tree we are. 148 | stack.push_back(&node); 149 | whiteStack.push_back(white); 150 | 151 | // Tokenize the line. Skip comments and empty lines. 152 | while(*it != '\n') 153 | { 154 | char endQuote = *it; 155 | bool isQuoted = (endQuote == '"' || endQuote == '`'); 156 | it += isQuoted; 157 | 158 | const char *start = it; 159 | 160 | // Find the end of this token. 161 | while(*it != '\n' && (isQuoted ? (*it != endQuote) : (*it > ' '))) 162 | ++it; 163 | 164 | // It ought to be legal to construct a string from an empty iterator 165 | // range, but it appears that some libraries do not handle that case 166 | // correctly. So: 167 | if(start == it) 168 | node.tokens.emplace_back(); 169 | else 170 | node.tokens.emplace_back(start, it); 171 | if(isQuoted && *it == '\n') 172 | node.PrintTrace("Closing quotation mark is missing:"); 173 | 174 | if(*it != '\n') 175 | { 176 | it += isQuoted; 177 | while(*it != '\n' && *it <= ' ' && *it != '#') 178 | ++it; 179 | 180 | // If a comment is encountered outside of a token, skip the rest 181 | // of this line of the file. 182 | if(*it == '#') 183 | { 184 | while(*it != '\n') 185 | ++it; 186 | } 187 | } 188 | } 189 | } 190 | } 191 | -------------------------------------------------------------------------------- /source/blend.cpp: -------------------------------------------------------------------------------- 1 | /* blend.cpp 2 | Copyright (c) 2016 by Michael Zahniser 3 | 4 | Endless Sky is free software: you can redistribute it and/or modify it under the 5 | terms of the GNU General Public License as published by the Free Software 6 | Foundation, either version 3 of the License, or (at your option) any later version. 7 | 8 | Endless Sky is distributed in the hope that it will be useful, but WITHOUT ANY 9 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 10 | PARTICULAR PURPOSE. See the GNU General Public License for more details. 11 | 12 | You should have received a copy of the GNU General Public License along with 13 | this program. If not, see . 14 | */ 15 | 16 | // g++ --std=c++0x blend.cpp -o blend -lpng 17 | 18 | #include 19 | #include 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | using namespace std; 26 | 27 | uint32_t *Read(const char *path, int *width, int *height); 28 | void Write(const char *path, uint32_t *buffer, int width, int height); 29 | 30 | 31 | 32 | int main(int argc, char *argv[]) 33 | { 34 | if(argc != 4) 35 | { 36 | cout << "Usage: $ blend " << endl; 37 | return 1; 38 | } 39 | 40 | int ow = 0, oh = 0; 41 | uint32_t *op = Read(argv[1], &ow, &oh); 42 | if(!op) 43 | { 44 | cerr << "Unable to read image: " << argv[1] << endl; 45 | return 1; 46 | } 47 | 48 | int aw = 0, ah = 0; 49 | uint32_t *ap = Read(argv[2], &aw, &ah); 50 | if(!op) 51 | { 52 | cerr << "Unable to read image: " << argv[2] << endl; 53 | delete [] op; 54 | return 1; 55 | } 56 | 57 | if(ow != aw || oh != ah) 58 | { 59 | cerr << "Images are different sizes: " << ow << "x" << oh << " versus " 60 | << aw << "x" << ah << "." << endl; 61 | delete [] op; 62 | delete [] ap; 63 | return 1; 64 | } 65 | 66 | for(int y = 0; y < oh; ++y) 67 | { 68 | uint32_t *oit = op + y * ow; 69 | uint32_t *ait = ap + y * aw; 70 | 71 | for(uint32_t *oend = oit + ow; oit != oend; ++oit, ++ait) 72 | { 73 | uint64_t oA = (*oit >> 24) & 0xFF; 74 | uint64_t oR = (*oit >> 16) & 0xFF; 75 | uint64_t oG = (*oit >> 8) & 0xFF; 76 | uint64_t oB = (*oit >> 0) & 0xFF; 77 | 78 | uint64_t aA = (*ait >> 24) & 0xFF; 79 | uint64_t aR = (*ait >> 16) & 0xFF; 80 | uint64_t aG = (*ait >> 8) & 0xFF; 81 | uint64_t aB = (*ait >> 0) & 0xFF; 82 | 83 | oR = min(uint64_t(255), (oR * oA) / 255 + (aR * aA) / 255); 84 | oG = min(uint64_t(255), (oG * oA) / 255 + (aG * aA) / 255); 85 | oB = min(uint64_t(255), (oB * oA) / 255 + (aB * aA) / 255); 86 | 87 | *oit = static_cast((oA << 24) + (oR << 16) + (oG << 8) + (oB << 0)); 88 | } 89 | } 90 | 91 | Write(argv[3], op, ow, oh); 92 | 93 | return 0; 94 | } 95 | 96 | 97 | 98 | uint32_t *Read(const char *path, int *width, int *height) 99 | { 100 | FILE *file = fopen(path, "rb"); 101 | if(!file) 102 | return nullptr; 103 | 104 | // Set up libpng. 105 | png_struct *png = png_create_read_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr); 106 | if(!png) 107 | return nullptr; 108 | 109 | png_info *info = png_create_info_struct(png); 110 | if(!info) 111 | { 112 | png_destroy_read_struct(&png, nullptr, nullptr); 113 | return nullptr; 114 | } 115 | 116 | uint32_t *buffer = nullptr; 117 | if(setjmp(png_jmpbuf(png))) 118 | { 119 | png_destroy_read_struct(&png, &info, nullptr); 120 | delete buffer; 121 | return nullptr; 122 | } 123 | 124 | png_init_io(png, file); 125 | png_set_sig_bytes(png, 0); 126 | 127 | png_read_info(png, info); 128 | *width = png_get_image_width(png, info); 129 | *height = png_get_image_height(png, info); 130 | if(!*width || !*height) 131 | return nullptr; 132 | 133 | // Adjust settings to make sure the result will be a BGRA file. 134 | int colorType = png_get_color_type(png, info); 135 | int bitDepth = png_get_bit_depth(png, info); 136 | 137 | png_set_strip_16(png); 138 | png_set_packing(png); 139 | if(colorType == PNG_COLOR_TYPE_PALETTE) 140 | png_set_palette_to_rgb(png); 141 | if(colorType == PNG_COLOR_TYPE_GRAY && bitDepth < 8) 142 | png_set_expand_gray_1_2_4_to_8(png); 143 | if(colorType & PNG_COLOR_MASK_COLOR) 144 | png_set_bgr(png); 145 | png_read_update_info(png, info); 146 | 147 | // Read the file. 148 | buffer = new uint32_t[*width * *height]; 149 | vector rows; 150 | for(int y = 0; y < *height; ++y) 151 | rows.push_back(reinterpret_cast(buffer + y * *width)); 152 | 153 | png_read_image(png, &rows.front()); 154 | 155 | // Clean up. 156 | png_destroy_read_struct(&png, &info, nullptr); 157 | fclose(file); 158 | 159 | return buffer; 160 | } 161 | 162 | 163 | 164 | void Write(const char *path, uint32_t *buffer, int width, int height) 165 | { 166 | // Set up libpng. 167 | png_struct *png = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr); 168 | if(!png) 169 | return; 170 | 171 | png_info *info = png_create_info_struct(png); 172 | if(!info) 173 | { 174 | png_destroy_read_struct(&png, nullptr, nullptr); 175 | return; 176 | } 177 | 178 | if(setjmp(png_jmpbuf(png))) 179 | { 180 | png_destroy_read_struct(&png, &info, nullptr); 181 | return; 182 | } 183 | 184 | FILE *file = fopen(path, "wb"); 185 | png_init_io(png, file); 186 | png_set_compression_level(png, Z_BEST_COMPRESSION); 187 | 188 | png_set_IHDR(png, info, width, height, 8, 189 | PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE, 190 | PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); 191 | 192 | png_set_bgr(png); 193 | png_write_info(png, info); 194 | 195 | vector rows; 196 | for(int y = 0; y < height; ++y) 197 | rows.push_back(reinterpret_cast(buffer + y * width)); 198 | 199 | png_write_image(png, &rows.front()); 200 | png_write_end(png, NULL); 201 | 202 | // Clean up. 203 | png_destroy_write_struct(&png, &info); 204 | fclose(file); 205 | } 206 | -------------------------------------------------------------------------------- /source/dynamic-economy.cpp: -------------------------------------------------------------------------------- 1 | /* dynamic-economy.cpp 2 | Copyright (c) 2016 by Michael Zahniser 3 | 4 | Endless Sky is free software: you can redistribute it and/or modify it under the 5 | terms of the GNU General Public License as published by the Free Software 6 | Foundation, either version 3 of the License, or (at your option) any later version. 7 | 8 | Endless Sky is distributed in the hope that it will be useful, but WITHOUT ANY 9 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 10 | PARTICULAR PURPOSE. See the GNU General Public License for more details. 11 | 12 | You should have received a copy of the GNU General Public License along with 13 | this program. If not, see . 14 | */ 15 | 16 | // Simulator for the dynamic economy implementation. Every time you press , 17 | // the simulation steps forward another 1000 days. 18 | // $ g++ --std=c++11 -o dynamic-economy dynamic-economy.cpp 19 | // $ ./dynamic-economy path/to/map.txt 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | using namespace std; 31 | 32 | bool StartsWith(const string &line, const string &str) 33 | { 34 | return line.length() >= str.length() && !line.compare(0, str.length(), str); 35 | } 36 | 37 | string Token(const string &line, int index) 38 | { 39 | size_t pos = 0; 40 | 41 | while(pos < line.length()) 42 | { 43 | while(line[pos] <= ' ') 44 | ++pos; 45 | 46 | char quote = 0; 47 | if(line[pos] == '"' || line[pos] == '`') 48 | quote = line[pos++]; 49 | size_t start = pos; 50 | while(pos < line.length() && (quote ? (line[pos] != quote) : (line[pos] > ' '))) 51 | ++pos; 52 | 53 | if(!index--) 54 | return line.substr(start, pos - start); 55 | pos = pos + !!quote; 56 | } 57 | return ""; 58 | } 59 | 60 | double Value(const string &line, int index) 61 | { 62 | double value = 0.; 63 | istringstream(Token(line, index)) >> value; 64 | return value; 65 | } 66 | 67 | double MapColor(double value, double *r, double *g, double *b) 68 | { 69 | value = min(1., max(-1., value)); 70 | if(value < 0.) 71 | { 72 | *r = 0.; 73 | *g = 50. * -value; 74 | *b = 100. * -value; 75 | } 76 | else 77 | { 78 | *r = 100. * value; 79 | *g = 50. * value; 80 | *b = 0.; 81 | } 82 | } 83 | 84 | 85 | 86 | int main(int argc, char *argv[]) 87 | { 88 | if(argc < 2) 89 | return 1; 90 | 91 | mt19937_64 gen; 92 | gen.seed(12345); 93 | normal_distribution normal; 94 | 95 | map posX; 96 | map posY; 97 | map> links; 98 | 99 | double minX = 0.; 100 | double maxX = 0.; 101 | double minY = 0.; 102 | double maxY = 0.; 103 | 104 | string line; 105 | string name; 106 | 107 | ifstream in(argv[1]); 108 | while(getline(in, line)) 109 | { 110 | if(StartsWith(line, "system")) 111 | name = Token(line, 1); 112 | else if(StartsWith(line, "\tpos") && !name.empty()) 113 | { 114 | double x = Value(line, 1); 115 | double y = Value(line, 2); 116 | minX = min(minX, x); 117 | maxX = max(maxX, x); 118 | minY = min(minY, y); 119 | maxY = max(maxY, y); 120 | posX[name] = x; 121 | posY[name] = y; 122 | } 123 | else if(StartsWith(line, "\tlink") && !name.empty()) 124 | links[name].insert(Token(line, 1)); 125 | } 126 | 127 | // Add a slight border around the edges. 128 | const double BORDER = .05; 129 | double xBorder = (maxX - minX) * BORDER; 130 | minX -= xBorder; 131 | maxX += xBorder; 132 | double yBorder = (maxY - minY) * BORDER; 133 | minY -= yBorder; 134 | maxY += yBorder; 135 | 136 | // Figure out the scale to apply to the map to keep dimensions below... 137 | const double MAX_DIMENSION = 900.; 138 | const double RADIUS = 4.; 139 | double scale = MAX_DIMENSION / max(maxX - minX, maxY - minY); 140 | int width = scale * (maxX - minX); 141 | int height = scale * (maxY - minY); 142 | 143 | // Run the simulation repeatedly. 144 | map supply; 145 | map trade; 146 | int DAYS = 1000; 147 | while(true) 148 | { 149 | static const double TRADE = .10; 150 | static const double KEEP = .89; 151 | static const double VOLUME = 10000.; 152 | static const double LIMIT = 100000.; 153 | for(int day = 0; day < DAYS; ++day) 154 | { 155 | for(const auto &it : links) 156 | { 157 | trade[it.first] = TRADE * supply[it.first]; 158 | supply[it.first] *= KEEP; 159 | supply[it.first] += normal(gen) * VOLUME; 160 | } 161 | for(const auto &it : links) 162 | if(it.second.size()) 163 | { 164 | double share = trade[it.first] / it.second.size(); 165 | for(const string &link : it.second) 166 | supply[link] += share; 167 | } 168 | } 169 | // After the first day, step according to the given step size. 170 | if(argc > 2) 171 | DAYS = stoi(argv[2]); 172 | 173 | ofstream out("economy.svg"); 174 | out << "" << endl; 175 | out << "" << endl; 176 | 177 | // Draw the links. 178 | for(const auto &it : posX) 179 | { 180 | string system = it.first; 181 | double x1 = (posX[system] - minX) * scale; 182 | double y1 = (posY[system] - minY) * scale; 183 | for(const string &link : links[system]) 184 | { 185 | // Only draw links in one direction. 186 | if(link <= system) 187 | continue; 188 | double x2 = (posX[link] - minX) * scale; 189 | double y2 = (posY[link] - minY) * scale; 190 | 191 | out << "" << endl; 193 | } 194 | } 195 | 196 | // Draw circles for the systems. 197 | double lowest = 1.; 198 | double highest = -1.; 199 | for(const auto &it : posX) 200 | { 201 | string system = it.first; 202 | double x = (posX[system] - minX) * scale; 203 | double y = (posY[system] - minY) * scale; 204 | double value = erf(supply[it.first] / LIMIT); 205 | lowest = min(value, lowest); 206 | highest = max(value, highest); 207 | double r, g, b; 208 | MapColor(value, &r, &g, &b); 209 | 210 | out << "" << endl; 212 | } 213 | 214 | out << "" << endl; 215 | out.close(); 216 | 217 | cout << "Adjustment range: " << lowest << " to " << highest; 218 | cin.get(); 219 | if(!cin) 220 | break; 221 | } 222 | cout << endl; 223 | return 0; 224 | } 225 | -------------------------------------------------------------------------------- /source/mapper.cpp: -------------------------------------------------------------------------------- 1 | /* mapper.cpp 2 | Copyright (c) 2016 by Michael Zahniser 3 | 4 | Endless Sky is free software: you can redistribute it and/or modify it under the 5 | terms of the GNU General Public License as published by the Free Software 6 | Foundation, either version 3 of the License, or (at your option) any later version. 7 | 8 | Endless Sky is distributed in the hope that it will be useful, but WITHOUT ANY 9 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 10 | PARTICULAR PURPOSE. See the GNU General Public License for more details. 11 | 12 | You should have received a copy of the GNU General Public License along with 13 | this program. If not, see . 14 | */ 15 | 16 | // Program for generating a map of the galaxy, colored by government. 17 | // $ g++ --std=c++11 -o mapper mapper.cpp 18 | // $ ./mapper path/to/map.txt path/to/governments.txt > map.svg 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | using namespace std; 28 | 29 | bool StartsWith(const string &line, const string &str) 30 | { 31 | return line.length() >= str.length() && !line.compare(0, str.length(), str); 32 | } 33 | 34 | string Token(const string &line, int index) 35 | { 36 | size_t pos = 0; 37 | 38 | while(pos < line.length()) 39 | { 40 | while(line[pos] <= ' ') 41 | ++pos; 42 | 43 | char quote = 0; 44 | if(line[pos] == '"' || line[pos] == '`') 45 | quote = line[pos++]; 46 | size_t start = pos; 47 | while(pos < line.length() && (quote ? (line[pos] != quote) : (line[pos] > ' '))) 48 | ++pos; 49 | 50 | if(!index--) 51 | return line.substr(start, pos - start); 52 | pos = pos + !!quote; 53 | } 54 | return ""; 55 | } 56 | 57 | double Value(const string &line, int index) 58 | { 59 | double value = 0.; 60 | istringstream(Token(line, index)) >> value; 61 | return value; 62 | } 63 | 64 | void Color(double &r, double &g, double &b, double value) 65 | { 66 | value = value * 2. - 1.; 67 | if(value < 0.) 68 | { 69 | r = 20. + 20. * value; 70 | g = 80. + 60. * value; 71 | b = 80. - 20. * value; 72 | } 73 | else 74 | { 75 | r = 20. + 80. * value; 76 | g = 80.; 77 | b = 80. - 80. * value; 78 | } 79 | } 80 | 81 | 82 | 83 | int main(int argc, char *argv[]) 84 | { 85 | if(argc <= 1) 86 | return 1; 87 | 88 | map posX; 89 | map posY; 90 | map gov; 91 | map trade; 92 | map> links; 93 | 94 | map govR; 95 | map govG; 96 | map govB; 97 | 98 | double minX = 0.; 99 | double maxX = 0.; 100 | double minY = 0.; 101 | double maxY = 0.; 102 | 103 | string line; 104 | string name; 105 | 106 | // First, read the government file, if any. 107 | string commodity; 108 | double tradeMin = 0.; 109 | double tradeMax = 2000.; 110 | if(argv[2] && argv[3]) 111 | { 112 | commodity = argv[3]; 113 | ifstream in(argv[2]); 114 | 115 | while(getline(in, line)) 116 | if(StartsWith(line, "\tcommodity") && Token(line, 1) == commodity) 117 | { 118 | tradeMin = Value(line, 2); 119 | tradeMax = Value(line, 3); 120 | } 121 | } 122 | else if(argv[2]) 123 | { 124 | ifstream in(argv[2]); 125 | 126 | while(getline(in, line)) 127 | { 128 | if(StartsWith(line, "government")) 129 | name = Token(line, 1); 130 | else if(StartsWith(line, "\tcolor")) 131 | { 132 | govR[name] = Value(line, 1); 133 | govG[name] = Value(line, 2); 134 | govB[name] = Value(line, 3); 135 | } 136 | } 137 | name.clear(); 138 | } 139 | 140 | // Now, parse the map. 141 | ifstream in(argv[1]); 142 | while(getline(in, line)) 143 | { 144 | if(StartsWith(line, "system")) 145 | name = Token(line, 1); 146 | else if(StartsWith(line, "\tpos") && !name.empty()) 147 | { 148 | double x = Value(line, 1); 149 | double y = Value(line, 2); 150 | minX = min(minX, x); 151 | maxX = max(maxX, x); 152 | minY = min(minY, y); 153 | maxY = max(maxY, y); 154 | posX[name] = x; 155 | posY[name] = y; 156 | } 157 | else if(StartsWith(line, "\tgovernment") && !name.empty()) 158 | gov[name] = Token(line, 1); 159 | else if(StartsWith(line, "\tlink") && !name.empty()) 160 | links[name].insert(Token(line, 1)); 161 | else if(StartsWith(line, "\ttrade") && !name.empty() && Token(line, 1) == commodity) 162 | trade[name] = max(0., min(1., (Value(line, 2) - tradeMin) / (tradeMax - tradeMin))); 163 | else if(!StartsWith(line, "\t")) 164 | name.clear(); 165 | } 166 | 167 | // Add a slight border around the edges. 168 | const double BORDER = .05; 169 | double xBorder = (maxX - minX) * BORDER; 170 | minX -= xBorder; 171 | maxX += xBorder; 172 | double yBorder = (maxY - minY) * BORDER; 173 | minY -= yBorder; 174 | maxY += yBorder; 175 | 176 | // Figure out the scale to apply to the map to keep dimensions below... 177 | const double MAX_DIMENSION = 600.; 178 | double scale = MAX_DIMENSION / max(maxX - minX, maxY - minY); 179 | int width = scale * (maxX - minX); 180 | int height = scale * (maxY - minY); 181 | cout << "" << endl; 182 | cout << "" << endl; 183 | 184 | // Draw the links. 185 | for(const auto &it : posX) 186 | { 187 | string system = it.first; 188 | double x1 = (posX[system] - minX) * scale; 189 | double y1 = (posY[system] - minY) * scale; 190 | for(const string &link : links[system]) 191 | { 192 | // Only draw links in one direction. 193 | if(link <= system) 194 | continue; 195 | double x2 = (posX[link] - minX) * scale; 196 | double y2 = (posY[link] - minY) * scale; 197 | 198 | cout << "" << endl; 200 | } 201 | } 202 | 203 | // Draw circles for the systems. 204 | const double RADIUS = 2.; 205 | for(const auto &it : posX) 206 | { 207 | string system = it.first; 208 | double x = (posX[system] - minX) * scale; 209 | double y = (posY[system] - minY) * scale; 210 | double r = 100.; 211 | double g = 100.; 212 | double b = 100.; 213 | auto cit = trade.find(system); 214 | auto git = gov.find(system); 215 | if(cit != trade.end()) 216 | Color(r, g, b, cit->second); 217 | else if(git != gov.end() && govR.find(git->second) != govR.end()) 218 | { 219 | r = 100. * govR[git->second]; 220 | g = 100. * govG[git->second]; 221 | b = 100. * govB[git->second]; 222 | } 223 | else 224 | cerr << system << endl; 225 | 226 | cout << "" << endl; 228 | } 229 | 230 | cout << "" << endl; 231 | return 0; 232 | } 233 | -------------------------------------------------------------------------------- /source/commerce.cpp: -------------------------------------------------------------------------------- 1 | /* commerce.cpp 2 | Copyright (c) 2016 by Michael Zahniser 3 | 4 | Endless Sky is free software: you can redistribute it and/or modify it under the 5 | terms of the GNU General Public License as published by the Free Software 6 | Foundation, either version 3 of the License, or (at your option) any later version. 7 | 8 | Endless Sky is distributed in the hope that it will be useful, but WITHOUT ANY 9 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 10 | PARTICULAR PURPOSE. See the GNU General Public License for more details. 11 | 12 | You should have received a copy of the GNU General Public License along with 13 | this program. If not, see . 14 | */ 15 | 16 | // commerce: program for populating the map with commodity values. 17 | // $ g++ --std=c++11 -o commerce commerce.cpp 18 | // $ ./commerce 19 | // The settings file should contain key-value pairs: 20 | // name 21 | // base 22 | // bins ... 23 | 24 | #include "shared/DataFile.cpp" 25 | #include "shared/DataNode.cpp" 26 | #include "shared/DataWriter.cpp" 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | using namespace std; 38 | 39 | class System { 40 | public: 41 | void Load(const DataNode &node); 42 | 43 | const vector &Links() const; 44 | 45 | void SetTrade(const string &commodity, double value); 46 | 47 | void Write(DataWriter &out) const; 48 | 49 | 50 | private: 51 | string name; 52 | double x; 53 | double y; 54 | vector links; 55 | 56 | map trade; 57 | }; 58 | 59 | class Value { 60 | public: 61 | int minBin; 62 | int maxBin; 63 | int bin; 64 | }; 65 | 66 | 67 | 68 | int main(int argc, char *argv[]) 69 | { 70 | if(argc < 3) 71 | return 1; 72 | 73 | srand(time(NULL)); 74 | 75 | // Load the "settings." 76 | string commodity; 77 | int base = 0; 78 | vector binWeight; 79 | { 80 | DataFile file(argv[2]); 81 | double total = 0.; 82 | for(const DataNode &node : file) 83 | { 84 | if(node.Token(0) == "name" && node.Size() >= 2) 85 | commodity = node.Token(1); 86 | else if(node.Token(0) == "base" && node.Size() >= 2) 87 | base = node.Value(1); 88 | else if(node.Token(0) == "bins" && node.Size() >= 2) 89 | for(int i = 1; i < node.Size(); ++i) 90 | { 91 | binWeight.push_back(node.Value(i)); 92 | total += binWeight.back(); 93 | } 94 | } 95 | if(!base || commodity.empty() || binWeight.empty() || !total) 96 | return 1; 97 | for(double &value : binWeight) 98 | value /= total; 99 | } 100 | 101 | // Load the map file. 102 | map systems; 103 | vector names; 104 | { 105 | DataFile file(argv[1]); 106 | for(const DataNode &node : file) 107 | if(node.Size() >= 2 && node.Token(0) == "system") 108 | { 109 | names.push_back(node.Token(1)); 110 | systems[node.Token(1)].Load(node); 111 | } 112 | } 113 | // Generate the quotas from the weights. 114 | vector binQuota; 115 | for(double weight : binWeight) 116 | binQuota.push_back(ceil(weight * names.size()) + 1); 117 | 118 | // Look for an arrangement that works. 119 | int highBin = binQuota.size(); 120 | map values; 121 | while(true) 122 | { 123 | // We have not assigned any values yet. So, we have our full quota 124 | // remaining, and each star can be assigned to any bin. 125 | vector bin = binQuota; 126 | for(const string &name : names) 127 | { 128 | values[name].minBin = 0; 129 | values[name].maxBin = highBin; 130 | } 131 | 132 | // Keep track of which stars haven't been assigned values yet. 133 | vector unassigned = names; 134 | while(unassigned.size()) 135 | { 136 | // Pick a random star to assign a value to. 137 | int i = rand() % unassigned.size(); 138 | string name = unassigned[i]; 139 | unassigned[i] = unassigned.back(); 140 | unassigned.pop_back(); 141 | 142 | // Find out how many items left in our quota could be assigned to 143 | // this particular star. 144 | int possibilities = 0; 145 | for(int i = values[name].minBin; i < values[name].maxBin; ++i) 146 | possibilities += bin[i]; 147 | if(!possibilities) 148 | break; 149 | 150 | // Pick a random one of those items to assign to it. 151 | int index = rand() % possibilities; 152 | int choice = values[name].minBin; 153 | while(true) 154 | { 155 | index -= bin[choice]; 156 | if(index < 0) 157 | break; 158 | ++choice; 159 | } 160 | --bin[choice]; 161 | 162 | // Record our choice. 163 | values[name].bin = choice; 164 | int minBin = choice; 165 | int maxBin = choice + 1; 166 | 167 | // Starting from this star, trace outwards system by system. Each 168 | // neighboring system must be within 1 of this star's level; each 169 | // system neighboring those, within 2, and so on. 170 | vector source = {name}; 171 | set done = {name}; 172 | while(minBin > 0 || maxBin < highBin) 173 | { 174 | // Widen the min and max unless they are at their widest. 175 | if(minBin > 0) 176 | --minBin; 177 | if(maxBin < highBin) 178 | ++maxBin; 179 | 180 | vector next; 181 | 182 | // Update the min and max for each unvisited neighbor. 183 | for(const string &sourceName : source) 184 | for(const string &name : systems[sourceName].Links()) 185 | { 186 | if(done.find(name) != done.end()) 187 | continue; 188 | done.insert(name); 189 | 190 | values[name].minBin = max(values[name].minBin, minBin); 191 | values[name].maxBin = min(values[name].maxBin, maxBin); 192 | next.push_back(name); 193 | } 194 | 195 | // Now, visit neighbors of those neighbors. 196 | next.swap(source); 197 | } 198 | } 199 | // If there were not any stars that we could not assign values to, we 200 | // are done. Especially if the constraints are rather tight, it may 201 | // take quite a few iterations to find an acceptable solution. Or, it 202 | // may be outright impossible, in qhich case the program hangs. 203 | if(!unassigned.size()) 204 | break; 205 | } 206 | 207 | // Assign each star system a value based on its bin. 208 | map rough; 209 | for(auto &it : values) 210 | rough[it.first] = base + (rand() % 100) + 100 * it.second.bin; 211 | 212 | // Smooth out the values by averaging each system with the average of all 213 | // its neighbors. 214 | for(auto &it : systems) 215 | { 216 | int count = 0; 217 | int sum = 0; 218 | for(const string &link : it.second.Links()) 219 | { 220 | sum += rough[link]; 221 | ++count; 222 | } 223 | if(!count) 224 | sum = rough[it.first]; 225 | else 226 | { 227 | sum += count * rough[it.first]; 228 | sum = (sum + count) / (2 * count); 229 | } 230 | it.second.SetTrade(commodity, sum); 231 | } 232 | 233 | // Write the result. This is not a full map; it needs to be merged into the 234 | // map using the map-merge tool. 235 | DataWriter out; 236 | for(const auto &it : systems) 237 | it.second.Write(out); 238 | string output = out.ToString(); 239 | 240 | { 241 | ofstream file(argv[1]); 242 | file.write(output.data(), output.length()); 243 | } 244 | 245 | return 0; 246 | } 247 | 248 | 249 | 250 | void System::Load(const DataNode &node) 251 | { 252 | links.clear(); 253 | trade.clear(); 254 | name = node.Token(1); 255 | 256 | for(const DataNode &child : node) 257 | { 258 | if(child.Token(0) == "pos" && child.Size() >= 3) 259 | { 260 | x = child.Value(1); 261 | y = child.Value(2); 262 | } 263 | else if(child.Token(0) == "link" && child.Size() >= 2) 264 | links.push_back(child.Token(1)); 265 | else if(child.Token(0) == "trade" && child.Size() >= 3) 266 | trade[child.Token(1)] = child.Value(2); 267 | } 268 | } 269 | 270 | const vector &System::Links() const 271 | { 272 | return links; 273 | } 274 | 275 | void System::SetTrade(const string &commodity, double value) 276 | { 277 | trade[commodity] = value; 278 | } 279 | 280 | void System::Write(DataWriter &out) const 281 | { 282 | out.Write("system", name); 283 | out.BeginChild(); 284 | 285 | out.Write("pos", x, y); 286 | for(const string &link : links) 287 | out.Write("link", link); 288 | for(const auto &it : trade) 289 | out.Write("trade", it.first, it.second); 290 | 291 | out.EndChild(); 292 | out.AddLineBreak(); 293 | } 294 | -------------------------------------------------------------------------------- /source/worldview.cpp: -------------------------------------------------------------------------------- 1 | /* worldview.cpp 2 | Copyright (c) 2016 by Michael Zahniser 3 | 4 | Endless Sky is free software: you can redistribute it and/or modify it under the 5 | terms of the GNU General Public License as published by the Free Software 6 | Foundation, either version 3 of the License, or (at your option) any later version. 7 | 8 | Endless Sky is distributed in the hope that it will be useful, but WITHOUT ANY 9 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 10 | PARTICULAR PURPOSE. See the GNU General Public License for more details. 11 | 12 | You should have received a copy of the GNU General Public License along with 13 | this program. If not, see . 14 | */ 15 | 16 | // Program to generate an HTML file with all planets and graphics. 17 | // $ g++ --std=c++11 -o worldview worldview.cpp 18 | // $ ./worldview path/to/map.txt > worldview.html 19 | 20 | #include "shared/DataFile.cpp" 21 | #include "shared/DataNode.cpp" 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | using namespace std; 33 | 34 | namespace { 35 | double minX = numeric_limits::infinity(); 36 | double minY = numeric_limits::infinity(); 37 | double maxX = -numeric_limits::infinity(); 38 | double maxY = -numeric_limits::infinity(); 39 | 40 | map uses; 41 | } 42 | 43 | class Commodity { 44 | public: 45 | string name; 46 | int low; 47 | int high; 48 | }; 49 | 50 | static const vector commodities = { 51 | {"Food", 100, 600}, 52 | {"Clothing", 140, 440}, 53 | {"Metal", 190, 590}, 54 | {"Plastic", 240, 540}, 55 | {"Equipment", 330, 730}, 56 | {"Medical", 430, 930}, 57 | {"Industrial", 520, 920}, 58 | {"Electronics", 590, 890}, 59 | {"Heavy Metals", 610, 1310}, 60 | {"Luxury Goods", 920, 1520} 61 | }; 62 | 63 | class System { 64 | public: 65 | void Load(const DataNode &node); 66 | 67 | const DataNode *root; 68 | double x; 69 | double y; 70 | string government; 71 | map trade; 72 | vector stars; 73 | vector> planets; 74 | vector links; 75 | set seenPlanets; 76 | }; 77 | 78 | class Planet { 79 | public: 80 | void Load(const DataNode &node); 81 | 82 | string landscape; 83 | string description; 84 | string spaceport; 85 | vector shipyard; 86 | vector outfitter; 87 | }; 88 | 89 | double MaxDistance(const DataNode &node, double d = 1.); 90 | void Draw(const DataNode &node, double x, double y, double scale, const string &name); 91 | 92 | 93 | 94 | int main(int argc, char *argv[]) 95 | { 96 | if(argc < 2) 97 | return 1; 98 | 99 | DataFile file(argv[1]); 100 | 101 | map systems; 102 | map planets; 103 | for(const DataNode &node : file) 104 | { 105 | if(node.Token(0) == "system" && node.Size() >= 2) 106 | systems[node.Token(1)].Load(node); 107 | else if(node.Token(0) == "planet" && node.Size() >= 2) 108 | planets[node.Token(1)].Load(node); 109 | } 110 | 111 | // Draw all systems: 112 | ofstream mapFile("map.svg"); 113 | mapFile << "\n"; 115 | double radius = 120.; 116 | double scale = 2. * (radius - 1.) / max(maxX - minX, maxY - minY); 117 | double centerX = (minX + maxX) / 2.; 118 | double centerY = (minY + maxY) / 2.; 119 | for(const pair &it : systems) 120 | { 121 | const System &system = it.second; 122 | 123 | double x1 = (system.x - centerX) * scale + radius; 124 | double y1 = (system.y - centerY) * scale + radius; 125 | for(const string &link : system.links) 126 | { 127 | // Only draw links in one direction. 128 | if(link <= it.first) 129 | continue; 130 | 131 | map::iterator lit = systems.find(link); 132 | if(lit == systems.end()) 133 | continue; 134 | 135 | double x2 = (lit->second.x - centerX) * scale + radius; 136 | double y2 = (lit->second.y - centerY) * scale + radius; 137 | 138 | mapFile << "\n"; 141 | } 142 | } 143 | mapFile << "\n\n"; 144 | mapFile.close(); 145 | 146 | cout << "World Viewer" << endl; 147 | cout << "" << endl; 148 | cout << "" << endl; 149 | for(const pair &it : systems) 150 | { 151 | size_t count = it.second.planets.size(); 152 | if(!count) 153 | continue; 154 | 155 | cout << "" << endl; 186 | 187 | bool first = true; 188 | for(const pair &planet : it.second.planets) 189 | { 190 | if(!first) 191 | cout << ""; 192 | cout << "" << endl; 222 | cout << ""; 232 | if(!first) 233 | cout << ""; 234 | cout << endl; 235 | 236 | first = false; 237 | } 238 | cout << "" << endl; 239 | } 240 | cout << "
" << it.first; 157 | for(const string &star : it.second.stars) 158 | cout << "
"; 159 | cout << "

Government: " << it.second.government << "

"; 160 | 161 | // Draw system location: 162 | double x = (it.second.x - centerX) * scale + radius; 163 | double y = (it.second.y - centerY) * scale + radius; 164 | 165 | cout << ""; 166 | cout << ""; 167 | cout << ""; 169 | cout << "
\n"; 170 | 171 | cout << ""; 172 | for(const Commodity &commodity : commodities) 173 | { 174 | auto cit = it.second.trade.find(commodity.name); 175 | if(cit == it.second.trade.end()) 176 | continue; 177 | 178 | int price = cit->second; 179 | int third = (commodity.high - commodity.low) / 3; 180 | string color = (price < commodity.low + third) ? "#6699FF" 181 | : (price > commodity.high - third) ? "#FF6666" : "white"; 182 | cout << ""; 184 | } 185 | cout << "
" 183 | << commodity.name << "" << price << "

 

 

 

" << planet.first; 193 | cout << "
\n"; 194 | 195 | const Planet &data = planets[planet.first]; 196 | cout << "

(" << uses[planet.second] << " / " 197 | << uses[data.landscape] << " uses.

"; 198 | 199 | // Draw the star system, with this planet highlighted. 200 | double distance = MaxDistance(*it.second.root); 201 | double scale = min(.03, 116. / distance); 202 | 203 | cout << ""; 204 | Draw(*it.second.root, 120., 120., scale, planet.first); 205 | cout << "\n"; 206 | 207 | if(!data.shipyard.empty()) 208 | { 209 | cout << "

Shipyard:

" << endl; 210 | for(const string &name : data.shipyard) 211 | cout << "

" << name << "

"; 212 | cout << "

 

"; 213 | } 214 | if(!data.outfitter.empty()) 215 | { 216 | cout << "

Outfitter:

" << endl; 217 | for(const string &name : data.outfitter) 218 | cout << "

" << name << "

"; 219 | cout << "

 

"; 220 | } 221 | cout << "
"; 223 | if(!data.landscape.empty()) 224 | cout << ""; 225 | cout << data.description << "
"; 226 | if(data.spaceport.empty()) 227 | cout << "

YOU CANNOT REFUEL HERE.

"; 228 | else 229 | cout << data.spaceport; 230 | cout << "

 

 

 

"; 231 | cout << "
" << endl; 241 | } 242 | 243 | 244 | 245 | void System::Load(const DataNode &node) 246 | { 247 | if(node.Token(0) == "system") 248 | root = &node; 249 | 250 | for(const DataNode &child : node) 251 | { 252 | if(child.Token(0) == "object") 253 | { 254 | if(child.Size() >= 2 && seenPlanets.find(child.Token(1)) == seenPlanets.end()) 255 | { 256 | pair planet; 257 | planet.first = child.Token(1); 258 | for(const DataNode &grand : child) 259 | if(grand.Token(0) == "sprite" && grand.Size() >= 2) 260 | planet.second = grand.Token(1); 261 | planets.push_back(planet); 262 | seenPlanets.insert(planet.first); 263 | } 264 | // Recurse into 265 | Load(child); 266 | } 267 | else if(child.Token(0) == "sprite" && child.Size() >= 2) 268 | { 269 | ++uses[child.Token(1)]; 270 | if(!child.Token(1).compare(0, 5, "star/", 0, 5)) 271 | stars.push_back(child.Token(1)); 272 | } 273 | else if(child.Token(0) == "government" && child.Size() >= 2) 274 | government = child.Token(1); 275 | else if(child.Token(0) == "link" && child.Size() >= 2) 276 | links.push_back(child.Token(1)); 277 | else if(child.Token(0) == "trade" && child.Size() >= 3) 278 | trade[child.Token(1)] = child.Value(2); 279 | else if(child.Token(0) == "pos" && child.Size() >= 3) 280 | { 281 | x = child.Value(1); 282 | minX = min(minX, x); 283 | maxX = max(maxX, x); 284 | 285 | y = child.Value(2); 286 | minY = min(minY, y); 287 | maxY = max(maxY, y); 288 | } 289 | } 290 | } 291 | 292 | 293 | 294 | void Planet::Load(const DataNode &node) 295 | { 296 | for(const DataNode &child : node) 297 | { 298 | if(child.Token(0) == "landscape" && child.Size() >= 2) 299 | { 300 | ++uses[child.Token(1)]; 301 | landscape = child.Token(1); 302 | } 303 | else if(child.Token(0) == "shipyard" && child.Size() >= 2) 304 | shipyard.push_back(child.Token(1)); 305 | else if(child.Token(0) == "outfitter" && child.Size() >= 2) 306 | outfitter.push_back(child.Token(1)); 307 | else if(child.Token(0) == "description" || child.Token(0) == "spaceport" && child.Size() >= 2) 308 | { 309 | string text = "

" + child.Token(1) + "

"; 310 | while(true) 311 | { 312 | size_t pos = text.find('\t'); 313 | if(pos == string::npos) 314 | break; 315 | text.replace(pos, 1, "    "); 316 | } 317 | (child.Token(0) == "description" ? description : spaceport) += text; 318 | } 319 | } 320 | } 321 | 322 | 323 | 324 | double MaxDistance(const DataNode &node, double d) 325 | { 326 | double maximum = d; 327 | 328 | for(const DataNode &child : node) 329 | { 330 | if(child.Token(0) == "object") 331 | { 332 | double thisD = 0.; 333 | for(const DataNode &grand : child) 334 | if(grand.Token(0) == "distance") 335 | thisD = grand.Value(1); 336 | thisD = MaxDistance(child, d + thisD); 337 | if(thisD > maximum) 338 | maximum = thisD; 339 | } 340 | } 341 | return maximum; 342 | } 343 | 344 | 345 | 346 | void Draw(const DataNode &node, double x, double y, double scale, const string &name) 347 | { 348 | if(node.Token(0) == "object" && node.Size() >= 2 && node.Token(1) == name) 349 | { 350 | cout << ""; 352 | } 353 | 354 | for(const DataNode &child : node) 355 | { 356 | if(child.Token(0) == "object") 357 | { 358 | double distance = 0.; 359 | double period = 0.; 360 | double offset = 0.; 361 | for(const DataNode &grand : child) 362 | { 363 | if(grand.Token(0) == "distance") 364 | distance = grand.Value(1); 365 | else if(grand.Token(0) == "period") 366 | period = grand.Value(1); 367 | else if(grand.Token(0) == "offset") 368 | offset = grand.Value(1); 369 | } 370 | 371 | distance *= scale; 372 | distance += 1.; 373 | cout << ""; 375 | 376 | double angle = (offset + 100000. / period) * 0.017453293; 377 | Draw(child, x + distance * sin(angle), y + distance * cos(angle), scale, name); 378 | } 379 | } 380 | } 381 | -------------------------------------------------------------------------------- /utils/check_code_style.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # check_coding_style.py 3 | # Copyright (c) 2022 by tibetiroka 4 | # 5 | # Endless Sky is free software: you can redistribute it and/or modify it under the 6 | # terms of the GNU General Public License as published by the Free Software 7 | # Foundation, either version 3 of the License, or (at your option) any later version. 8 | # 9 | # Endless Sky is distributed in the hope that it will be useful, but WITHOUT ANY 10 | # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 11 | # PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 | # 13 | # You should have received a copy of the GNU General Public License along with 14 | # this program. If not, see . 15 | 16 | import glob 17 | import sys 18 | 19 | import regex as re 20 | 21 | # Script that checks for common code formatting pitfalls not covered by clang-format or other tests. 22 | # The formatting rules are generally based on the guide found at http://endless-sky.github.io/styleguide/styleguide.xml 23 | # Unit tests mandate the existence of several exceptions to these rules. 24 | # 25 | # This checker uses regular expressions. For the sake of simplicity, these expressions represent a rather loose 26 | # interpretation of the rules. 27 | 28 | # String version of the regexes for easy editing 29 | # List of the standard operators that are checked 30 | std_op = "\\+/\\*<>&%=\\|!:\\-" 31 | # Dict of patterns for selection potential formatting issues in full lines. 32 | # These lines don't contain the contents of strings, chars or comments. 33 | # The dict also contains the error description for the patterns. 34 | line_include = {re.compile(regex): description for regex, description in { 35 | # Matches any '{' following an 'if', 'else if', 'for', 'while' or 'switch' statement. 36 | "^(else\\sif|if|else|for|switch|catch|while)\\s?\\(.*{$": "'{' should be on new line", 37 | # Matches any '{' not preceded by a whitespace or '(', except when the '{' is closed on the same line. 38 | "(?' that have no trailing whitespace. 82 | "^[^<>=:]?[" + std_op + "]*[=<>:][^=<>:,\\s\\)\\]}]": "missing whitespace after operator", 83 | # Matches any '(void)' arguments in methods 84 | "\\(void\\)": "do not use void to denote a function with no arguments" 85 | }.items()} 86 | 87 | # Patterns for excluding matches (test()#match) of 'include' 88 | match_exclude = [re.compile(regex) for regex in [ 89 | # Matches any repeating +, - or : operators, or any ::* or ::& references 90 | "^.?([+:-])\\1+|::&|::\\*.?$", 91 | # Matches any matches which have a -> operator surrounded by at most 1 character on either side. 92 | "^.?->.?$", 93 | # Matches any matches which have a character followed by '*(' or '&(' 94 | "^\\w[*&]\\($", 95 | # Matches any exponent-related matches. 96 | "^e[+-]\\d+$" 97 | ]] 98 | # Patterns for excluding segments that had matches in $include 99 | segment_exclude = [re.compile(regex) for regex in [ 100 | # Matches anything inside '<>'; this is a bit of a hack for getting rid of type-related issues 101 | "<.*>", 102 | # Matches any visibility modes; these are followed by ':' marks. 103 | "^(public|protected|private|default):$" 104 | ]] 105 | # Precompiled helper regexes 106 | after_comment = re.compile("[^\\s#]") 107 | whitespace_only = re.compile("^\\s*$") 108 | whitespaces = re.compile("\\s+") 109 | 110 | # List of "" and <> includes to be treated as the other type; 111 | # that is, any listed "" include should be grouped with <> includes, 112 | # and vice versa. 113 | reversed_includes = ["\"opengl.h\""] 114 | # The list of files for which the include checks are skipped. 115 | exclude_include_check = ["source/main.cpp"] 116 | 117 | 118 | # A class representing error messages. 119 | # These are stored in the error_list list to be displayed after all checks are done. 120 | # text: the text where the error originates from 121 | # line: the current line number 122 | # reason: the reason for the error 123 | class Error(object): 124 | 125 | def __init__(self, text, line, reason): 126 | self.text = text.replace('\n', '').replace('\r', '') 127 | self.line = line 128 | self.reason = reason 129 | 130 | def __str__(self): 131 | return f"\tERROR: line {self.line}: {self.reason} in '{self.text}'" 132 | 133 | def __lt__(self, other): 134 | return self.line < other.line 135 | 136 | def __eq__(self, other): 137 | return self.line == other.line and self.text == other.text and self.reason == other.reason 138 | 139 | def __hash__(self): 140 | return self.line 141 | 142 | 143 | # A class representing warning messages. 144 | # These are stored in the error_list list to be displayed after all checks are done. 145 | # text: the text where the warning originates from 146 | # line: the current line number 147 | # reason: the reason for the warning 148 | class Warning(Error): 149 | 150 | def __init__(self, text, line, reason): 151 | Error.__init__(self, text, line, reason) 152 | 153 | def __str__(self): 154 | return f"\tWARNING: line {self.line}: {self.reason} in '{self.text}'" 155 | 156 | 157 | # Checks the format of all source files. 158 | # Parameters: 159 | # file: The path to the file being checked 160 | # lines: The contents of the file, with the trailing line separators 161 | # Returns: A tuple containing the list of errors and warnings found 162 | def check_code_style(file, lines): 163 | issues = check_line_separators(lines) 164 | 165 | lines = [line.removesuffix('\n').removesuffix('\r') for line in lines] 166 | join(issues, check_pre_sanitize(lines, file)) 167 | 168 | segmented_lines = join(issues, sanitize(lines))[2] 169 | sanitized_lines = ["".join(segments) for segments in segmented_lines] 170 | 171 | join(issues, check_global_format(sanitized_lines, lines, file)) 172 | join(issues, check_local_format(sanitized_lines, segmented_lines)) 173 | 174 | return issues 175 | 176 | 177 | # Appends the lists in the second tuple to the lists in the first tuple. Parameters: 178 | # first: the tuple where the lists are expanded 179 | # second: the tuple where the lists are not expanded 180 | # Returns the second tuple for re-use. 181 | def join(first, second): 182 | for (list1, list2) in zip(first, second): 183 | list1 += list2 184 | return second 185 | 186 | 187 | # Sanitizes the contents of the file by removing the contents of strings and comments. 188 | # Also performs some minimal format checking that cannot be done elsewhere. 189 | # Parameters: 190 | # lines: the original contents of the file, without trailing line separators 191 | # file: the path to the file 192 | # skip_checks: whether to skip checks for formatting errors 193 | # Returns a tuple containing the errors, warnings and the sanitized line segments. 194 | def sanitize(lines, skip_checks=False): 195 | errors = [] 196 | warnings = [] 197 | 198 | is_multiline_comment = False 199 | is_string = False 200 | is_char = False 201 | is_raw_string = False 202 | is_raw_string_short = False 203 | line_count = 0 204 | header_found = False 205 | 206 | line_segments = [] 207 | 208 | for line in lines: 209 | line_count += 1 210 | segments = [] 211 | is_escaped = False 212 | # Checking for preprocessor text, except includes 213 | if not is_string and not is_multiline_comment and not is_char and line.lstrip().startswith("#") and not line.lstrip().startswith("#include"): 214 | line_segments.append(segments) 215 | continue 216 | # Start index is the beginning of the sequence to be tested 217 | start_index = 0 218 | # Looking for parts of the file that are not strings or comments 219 | for i in range(len(line)): 220 | char = line[i] 221 | # Handling character escapes 222 | if is_escaped: 223 | is_escaped = False 224 | continue 225 | elif char == '\\': 226 | is_escaped = True 227 | continue 228 | # Handling comments 229 | first_two = line[i:i + 2] 230 | if is_multiline_comment: 231 | if first_two == "*/": 232 | if not skip_checks: 233 | # Checking for space after comment 234 | if i > 0 and line[i - 1] != ' ' and line[i - 1] != '\t': 235 | errors.append(Error(line[i - 1:i + 2], line_count, 236 | "missing space before end of multiline comment")) 237 | # End of comment 238 | is_multiline_comment = False 239 | i += 1 240 | start_index = i + 1 241 | continue 242 | if (not is_string) and first_two == "//": 243 | segments.append(line[start_index:i].rstrip()) 244 | if not skip_checks: 245 | # Checking for space after comment 246 | if len(line) > i + 2: 247 | if re.search(after_comment, line[i + 2:i + 3]): 248 | errors.append(Error(line[i:i + 3], line_count, 249 | "missing space after beginning of single-line comment")) 250 | break 251 | elif (not is_string) and first_two == "/*": 252 | segments.append(line[start_index:i].rstrip()) 253 | is_multiline_comment = True 254 | if not skip_checks: 255 | if header_found and not ( 256 | line[i + 1:].count("*/") >= 1 and (line.endswith(")") or line.endswith("{"))): 257 | errors.append(Error(line.lstrip(), line_count, 258 | "multiline comments should only be used for the copyright header")) 259 | # Checking for space after comment 260 | if len(line) > i + 2 and line[i + 2] != ' ': 261 | errors.append(Error(line[i:i + 3], line_count, 262 | "missing space after beginning of multiline comment")) 263 | header_found = True 264 | continue 265 | # Checking for strings (both standard and raw literals) 266 | elif (not is_string) and char == "'": 267 | if is_char: 268 | start_index = i 269 | else: 270 | segments.append(line[start_index:i + 1]) 271 | is_char = not is_char 272 | elif is_char: 273 | continue 274 | elif char == '"': 275 | if line[i:i + 4] == "\"\"\"\"": 276 | if is_raw_string: 277 | start_index = i + 3 278 | else: 279 | segments.append(line[start_index:i + 1]) 280 | is_raw_string = not is_raw_string 281 | is_string = not is_string 282 | elif line[i - 1:i + 2] == "R\"(": 283 | if is_raw_string: 284 | continue 285 | if is_raw_string_short: 286 | continue 287 | is_raw_string_short = True 288 | is_string = True 289 | segments.append(line[start_index:i + 1]) 290 | elif line[i - 1:i + 1] == ")\"" and is_raw_string_short: 291 | is_raw_string_short = False 292 | is_string = False 293 | start_index = i 294 | else: 295 | if is_raw_string or is_raw_string_short: 296 | continue 297 | if is_string: 298 | start_index = i 299 | else: 300 | segments.append(line[start_index:i + 1]) 301 | is_string = not is_string 302 | else: 303 | if (not is_multiline_comment) and (not is_char) and (not is_escaped) and (not is_string): 304 | segments.append(line[start_index:]) 305 | line_segments.append(segments) 306 | return errors, warnings, line_segments 307 | 308 | 309 | # Tests whether the specified lines use unix-style line endings. Parameters: 310 | # lines: the lines to test, with the terminating line separators. 311 | # Returns a tuple of errors and warnings. 312 | def check_line_separators(lines): 313 | errors = [] 314 | warnings = [] 315 | for index, line in enumerate(lines): 316 | if line.endswith("\r\n"): 317 | errors.append(Error(line, index + 1, "Line separators should use LF only; found CRLF")) 318 | elif line.endswith("\r"): 319 | errors.append(Error(line, index + 1, "Line separators should use LF only; found CR")) 320 | elif not line.endswith("\n"): 321 | errors.append(Error(line, index + 1, "Missing line separator")) 322 | return errors, warnings 323 | 324 | 325 | # Runs checks on the contents of the file before sanitization. Parameters: 326 | # lines: the lines of the file, without the terminating line separators. Contains the contents of strings and comments. 327 | # file: the path to the file 328 | # Returns a tuple of errors and warnings. 329 | def check_pre_sanitize(lines, file): 330 | issues = check_line_format(lines) 331 | join(issues, check_copyright(lines, file)) 332 | return issues 333 | 334 | 335 | # Tests whether the specified file contains any formatting issues. Parameters: 336 | # lines: the lines of the file, without terminating line separators and the contents of strings or comments 337 | # segmented_lines: the segments of each line 338 | # file: the path to the file 339 | # Returns a tuple of errors and warnings. 340 | def check_local_format(lines, segmented_lines): 341 | issues = ([], []) 342 | line_count = 0 343 | for line, segments in zip(lines, segmented_lines): 344 | line_count += 1 345 | line = line.lstrip() 346 | # Removing indentation 347 | if len(segments) > 0: 348 | segments[0] = segments[0].lstrip() 349 | join(issues, check_regex_format(line, segments, line_count)) 350 | return issues 351 | 352 | 353 | # Tests whether the specified line contains any formatting issues, based on the regex tests. Parameters: 354 | # line: the line to test, without the contents of strings or comments 355 | # segments: the segments of the line 356 | # line_count: the position of the line 357 | # Returns a tuple of errors and warnings. 358 | def check_regex_format(line, segments, line_count): 359 | errors = [] 360 | warnings = [] 361 | # Check full-line regexes 362 | for regex, description in line_include.items(): 363 | if check_match(regex, line, line): 364 | errors.append(Error(line, line_count, description)) 365 | for segment in segments: 366 | # Skip empty 367 | if re.match(whitespace_only, segment): 368 | continue 369 | # Check segment regexes 370 | for regex, description in segment_include.items(): 371 | if check_match(regex, segment, segment): 372 | errors.append(Error(segment, line_count, description)) 373 | # Check word regexes 374 | for word in re.split(whitespaces, segment): 375 | word = word.strip() 376 | if word != "": 377 | for regex, description in word_include.items(): 378 | if check_match(regex, word, segment): 379 | errors.append(Error(word, line_count, description)) 380 | return errors, warnings 381 | 382 | 383 | # Checks if the specified regex matches with the text. Parameters: 384 | # regex: the regex to match 385 | # text: the text to match 386 | # segment: the segment the part belongs to 387 | # Returns True if the regex matches; False otherwise. 388 | def check_match(regex, text, segment): 389 | pos = re.search(regex, text) 390 | if pos is not None: 391 | match = text[pos.start():pos.end()] 392 | for temp in match_exclude: 393 | if re.search(temp, match): 394 | return False 395 | else: 396 | for temp in segment_exclude: 397 | if re.search(temp, segment): 398 | return False 399 | return True 400 | return False 401 | 402 | 403 | # Checks certain global formatting properties of files, such as their copyright headers. Parameters: 404 | # sanitized_lines: the sanitized contents of the file 405 | # original_lines: the contents of the file, without sanitization 406 | # file: the path to the file 407 | # Returns a tuple of errors and warnings. 408 | def check_global_format(sanitized_lines, original_lines, file): 409 | issues = ([], []) 410 | if file not in exclude_include_check: 411 | join(issues, check_include(sanitized_lines, original_lines, file)) 412 | return issues 413 | 414 | 415 | # Checks if the copyright header of the file is correct. Parameters: 416 | # lines: the lines to check, without the terminating line separators 417 | # file: the path to the file 418 | # Returns a tuple of errors and warnings. 419 | def check_copyright(lines, file): 420 | errors = [] 421 | warnings = [] 422 | 423 | name = file.split("/")[-1] 424 | # The two halves of the copyright notice. There might be a couple lines of text separating the two halves. 425 | # The bool value stores whether the text is interpreted as a regex. 426 | copyright_begin = [ 427 | ["/* " + name, False], 428 | ["Copyright \\(c\\) \\d{4}(?:(?:-|, )\\d{4})? by .*", True] 429 | ] 430 | copyright_end = [ 431 | ["", False], 432 | ["Endless Sky is free software: you can redistribute it and/or modify it under the", False], 433 | ["terms of the GNU General Public License as published by the Free Software", False], 434 | ["Foundation, either version 3 of the License, or (at your option) any later version.", False], 435 | ["", False], 436 | ["Endless Sky is distributed in the hope that it will be useful, but WITHOUT ANY", False], 437 | ["WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A", False], 438 | ["PARTICULAR PURPOSE. See the GNU General Public License for more details.", False], 439 | ["", False], 440 | ["You should have received a copy of the GNU General Public License along with", False], 441 | ["this program. If not, see .", False], 442 | ["*/", False], 443 | ["", False] 444 | ] 445 | index = 0 446 | error_line = -1 447 | complete = False 448 | for [copyright, is_regex] in copyright_begin: 449 | if is_regex: 450 | if not re.search(copyright, lines[index]): 451 | error_line = index 452 | break 453 | else: 454 | if copyright != lines[index]: 455 | error_line = index 456 | break 457 | index += 1 458 | not_found_error_line = index 459 | if error_line == -1: 460 | index_begin = index 461 | while index_begin < len(lines) - len(copyright_end): 462 | index = index_begin 463 | for [copyright, is_regex] in copyright_end: 464 | if is_regex: 465 | if not re.search(copyright, lines[index]): 466 | error_line = index 467 | break 468 | else: 469 | if copyright != lines[index]: 470 | error_line = index 471 | break 472 | index += 1 473 | if error_line == -1: 474 | complete = True 475 | break 476 | index_begin += 1 477 | error_line = -1 478 | if error_line != -1: 479 | errors.append(Error(lines[error_line], error_line + 1, "invalid or missing copyright header")) 480 | elif not complete: 481 | errors.append(Error(lines[not_found_error_line], not_found_error_line + 1, 482 | "invalid or incomplete copyright header")) 483 | return errors, warnings 484 | 485 | 486 | # Checks whether the specified lines don't exceed the character limit, and consist of ASCII characters only. Parameters: 487 | # lines: the lines to check, without the terminating line separators 488 | # Returns a tuple of errors and warnings. 489 | def check_line_format(lines): 490 | errors = [] 491 | warnings = [] 492 | 493 | line_count = 0 494 | for line in lines: 495 | line_count += 1 496 | if len(line) > 120: 497 | errors.append(Error(line, line_count, "lines should hard wrap at 120 characters")) 498 | for char in line: 499 | if ord(char) < 0 or ord(char) > 127: 500 | errors.append(Error(line, line_count, "files should be plain ASCII")) 501 | break 502 | return errors, warnings 503 | 504 | 505 | # Checks the import statements at the beginning of the file. Parameters: 506 | # sanitized_lines: the lines of the file, without the line separators and the contents of strings and comments 507 | # original_lines: the lines of the file, without the terminating line separators 508 | # file: the path to the file 509 | # Returns a tuple of errors and warnings. 510 | def check_include(sanitized_lines, original_lines, file): 511 | errors = [] 512 | warnings = [] 513 | 514 | # Replacing include statements 515 | for include in reversed_includes: 516 | stripped = include[1:-1] 517 | replacement = '<' + stripped + '>' if include[0] == '"' else '"' + stripped + '"' 518 | 519 | original_lines = [line if line != "#include " + include else "#include " + replacement for line in original_lines] 520 | 521 | name = file.split("/")[-1] 522 | if name.endswith(".cpp"): 523 | name = name[0:-4] + ".h" 524 | 525 | include_lines = [index for index, line in enumerate(sanitized_lines) if line.startswith("#include ")] 526 | groups = [] 527 | previous = -2 528 | for i in include_lines: 529 | if i == previous + 1: 530 | groups[-1].append(i) 531 | else: 532 | groups.append([i]) 533 | previous = i 534 | 535 | if file.endswith(".cpp") and name[0].isupper(): 536 | if len(groups) == 0: 537 | warnings.append(Warning("", 0, "missing include statement for own header file")) 538 | return errors, warnings 539 | elif original_lines[groups[0][0]] != "#include \"" + name + "\"": 540 | warnings.append(Warning(original_lines[groups[0][0]], groups[0][0], 541 | "missing include for own header file")) 542 | if len(groups[0]) > 1: 543 | warnings.append(Warning(original_lines[groups[0][1]], groups[0][1], 544 | "missing empty line after including own header file")) 545 | for group in groups: 546 | quote = original_lines[group[0]].endswith("\"") 547 | for index in group: 548 | if original_lines[index].endswith("\"") != quote: 549 | warnings.append( 550 | Warning(original_lines[index], index, "missing empty line before changing include style")) 551 | break 552 | group_lines = [original_lines[index] for index in group] 553 | for i in range(len(group_lines)): 554 | line = group_lines[i] 555 | if line.count("/") > 0: 556 | if quote: 557 | line = line[0:line.find("\"") + 1] + line[line.rfind("/") + 1:len(line)] 558 | else: 559 | line = line[0:line.find("<") + 1] + line[line.rfind("/") + 1:len(line)] 560 | group_lines[i] = line 561 | for i in range(len(group) - 1): 562 | if group_lines[i].lower() > group_lines[i + 1].lower(): 563 | warnings.append(Warning(group_lines[i], group[i] + 1, "includes are not in alphabetical order")) 564 | return errors, warnings 565 | 566 | 567 | if __name__ == '__main__': 568 | errors = 0 569 | warnings = 0 570 | 571 | files = [] 572 | if len(sys.argv[1:]) > 0: 573 | for pattern in sys.argv[1:]: 574 | files += glob.glob(pattern, recursive=True) 575 | else: 576 | files = glob.glob('**/*.cpp', recursive=True) + glob.glob('**/*.h', recursive=True) 577 | files.sort() 578 | 579 | for file in files: 580 | f = open(file, "r", newline='') 581 | contents = f.readlines() 582 | (e, w) = check_code_style(file, contents) 583 | 584 | errors += len(e) 585 | warnings += len(w) 586 | 587 | e = sorted(set(e)) 588 | w = sorted(set(w)) 589 | if e or w: 590 | print(file) 591 | if e: 592 | print(*e, sep='\n') 593 | if w: 594 | print(*w, sep='\n') 595 | print() 596 | text = "" 597 | if errors > 0: 598 | text += "Found " + str(errors) + " formatting " + ("error" if errors == 1 else "errors") 599 | if warnings > 0: 600 | text += " and " + str(warnings) + " " + ("warning" if warnings == 1 else "warnings") 601 | text += "." 602 | print(text) 603 | exit(1) 604 | if warnings == 0: 605 | print("No formatting errors found.") 606 | else: 607 | print(warnings, "warning" if warnings == 1 else "warnings", "found.") 608 | exit(0) 609 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | {one line to give the program's name and a brief idea of what it does.} 635 | Copyright (C) {year} {name of author} 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | {project} Copyright (C) {year} {fullname} 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------