diff --git a/python/CFReputation/__init__.py b/python/CFReputation/__init__.py index 39b0c6e01..79a5c35bb 100644 --- a/python/CFReputation/__init__.py +++ b/python/CFReputation/__init__.py @@ -5,7 +5,7 @@ import Crossfire _dict_name = 'CFReputationConnection' -def _init_schema(con, version, *init_files): +def _init_schema(con, version, *schema_files): con.execute("PRAGMA journal_mode=WAL;"); con.execute("PRAGMA synchronous=NORMAL;"); con.execute("CREATE TABLE IF NOT EXISTS schema(version INT);"); @@ -14,7 +14,7 @@ def _init_schema(con, version, *init_files): if curr < version: Crossfire.Log(Crossfire.LogInfo, "Initializing factions schema %d->%d" % (curr, version)) - for f in init_files: + for f in schema_files: with open(f) as initfile: con.executescript(initfile.read()) con.commit() @@ -24,10 +24,14 @@ def _get_sql_path(f): "python/CFReputation/sql", f) def _init_db(): + schema_files = map(_get_sql_path, ["schema.sql"]) init_files = map(_get_sql_path, ["init.sql", "gods.sql"]) db_path = os.path.join(Crossfire.LocalDirectory(), "factions.db") con = sqlite3.connect(':memory:') - _init_schema(con, 1, *init_files) + _init_schema(con, 1, *schema_files) + for f in init_files: + with open(f) as initfile: + con.executescript(initfile.read()) Crossfire.GetSharedDictionary()[_dict_name] = con def _get_db(): diff --git a/python/CFReputation/sql/gods.sql b/python/CFReputation/sql/gods.sql index 0263dc327..11472b82b 100644 --- a/python/CFReputation/sql/gods.sql +++ b/python/CFReputation/sql/gods.sql @@ -1,51 +1,54 @@ -insert into regions values ('Valriel', 'ALL', 0.25); -insert into relations values ('Valriel', 'angel', 1); -insert into relations values ('Valriel', 'demon', -1); -insert into regions values ('Gorokh', 'ALL', 0.25); -insert into relations values ('Gorokh', 'demon', 1); -insert into relations values ('Gorokh', 'angel', -1); -insert into regions values ('Devourers', 'ALL', 0.25); -insert into relations values ('Devourers', 'undead', 1); -insert into relations values ('Devourers', 'none', -1); -insert into regions values ('Sorig', 'ALL', 0.25); -insert into relations values ('Sorig', 'air_elemental', 1); -insert into relations values ('Sorig', 'none', -1); -insert into regions values ('Ruggilli', 'ALL', 0.25); -insert into relations values ('Ruggilli', 'consuming_fire_creatures', 1); -insert into relations values ('Ruggilli', 'chaotic_water_creatures', -1); -insert into regions values ('Ixalovh', 'ALL', 0.25); -insert into relations values ('Ixalovh', 'chaotic_water_creatures', 1); -insert into relations values ('Ixalovh', 'consuming_fire_creatures', -1); -insert into regions values ('Gaea', 'ALL', 0.25); -insert into relations values ('Gaea', 'animal', 1); -insert into relations values ('Gaea', 'bird', 1); -insert into relations values ('Gaea', 'slime', 1); -insert into relations values ('Gaea', 'insect', 1); -insert into relations values ('Gaea', 'reptile', 1); -insert into relations values ('Gaea', 'water_elemental', 1); -insert into relations values ('Gaea', 'earth_elemental', 1); -insert into relations values ('Gaea', 'air_elemental', 1); -insert into relations values ('Gaea', 'fire_elemental', 1); -insert into relations values ('Gaea', 'undead', -1); -insert into relations values ('Gaea', 'unnatural', -1); -insert into regions values ('Valkyrie', 'ALL', 0.25); -insert into relations values ('Valkyrie', 'human', 1); -insert into relations values ('Valkyrie', 'troll', 1); -insert into relations values ('Valkyrie', 'unnatural', -1); -insert into relations values ('Valkyrie', 'angel', -1); -insert into relations values ('Valkyrie', 'demon', -1); -insert into relations values ('Valkyrie', 'undead', -1); -insert into regions values ('Mostrai', 'ALL', 0.25); -insert into relations values ('Mostrai', 'dwarf', 1); -insert into relations values ('Mostrai', 'goblin', -1); -insert into relations values ('Mostrai', 'giant', -1); -insert into regions values ('Lythander', 'ALL', 0.25); -insert into relations values ('Lythander', 'faerie', 1); -insert into relations values ('Lythander', 'goblin', -1); -insert into relations values ('Lythander', 'troll', -1); -insert into regions values ('Gnarg', 'ALL', 0.25); -insert into relations values ('Gnarg', 'goblin', 1); -insert into relations values ('Gnarg', 'giant', 1); -insert into relations values ('Gnarg', 'troll', 1); -insert into relations values ('Gnarg', 'faerie', -1); -insert into relations values ('Gnarg', 'dwarf', -1); +INSERT OR REPLACE INTO regions VALUES +('Valriel', 'ALL', 0.25), +('Gorokh', 'ALL', 0.25), +('Devourers', 'ALL', 0.25), +('Sorig', 'ALL', 0.25), +('Ruggilli', 'ALL', 0.25), +('Ixalovh', 'ALL', 0.25), +('Gaea', 'ALL', 0.25), +('Valkyrie', 'ALL', 0.25), +('Mostrai', 'ALL', 0.25), +('Lythander', 'ALL', 0.25), +('Gnarg', 'ALL', 0.25); + +INSERT OR REPLACE INTO relations VALUES +('Valriel', 'angel', 1), +('Valriel', 'demon', -1), +('Gorokh', 'demon', 1), +('Gorokh', 'angel', -1), +('Devourers', 'undead', 1), +('Devourers', 'none', -1), +('Sorig', 'air_elemental', 1), +('Sorig', 'none', -1), +('Ruggilli', 'consuming_fire_creatures', 1), +('Ruggilli', 'chaotic_water_creatures', -1), +('Ixalovh', 'chaotic_water_creatures', 1), +('Ixalovh', 'consuming_fire_creatures', -1), +('Gaea', 'animal', 1), +('Gaea', 'bird', 1), +('Gaea', 'slime', 1), +('Gaea', 'insect', 1), +('Gaea', 'reptile', 1), +('Gaea', 'water_elemental', 1), +('Gaea', 'earth_elemental', 1), +('Gaea', 'air_elemental', 1), +('Gaea', 'fire_elemental', 1), +('Gaea', 'undead', -1), +('Gaea', 'unnatural', -1), +('Valkyrie', 'human', 1), +('Valkyrie', 'troll', 1), +('Valkyrie', 'unnatural', -1), +('Valkyrie', 'angel', -1), +('Valkyrie', 'demon', -1), +('Valkyrie', 'undead', -1), +('Mostrai', 'dwarf', 1), +('Mostrai', 'goblin', -1), +('Mostrai', 'giant', -1), +('Lythander', 'faerie', 1), +('Lythander', 'goblin', -1), +('Lythander', 'troll', -1), +('Gnarg', 'goblin', 1), +('Gnarg', 'giant', 1), +('Gnarg', 'troll', 1), +('Gnarg', 'faerie', -1), +('Gnarg', 'dwarf', -1); diff --git a/python/CFReputation/sql/init.sql b/python/CFReputation/sql/init.sql index 8f39d6533..95850925e 100644 --- a/python/CFReputation/sql/init.sql +++ b/python/CFReputation/sql/init.sql @@ -1,36 +1,11 @@ -CREATE TABLE IF NOT EXISTS schema(version INT); - -CREATE TABLE regions( - faction TEXT, - region TEXT, -- region name (or 'ALL') this faction controls - influence NUMERIC, - CONSTRAINT influence_range CHECK(influence BETWEEN 0 AND 1) -); - -CREATE TABLE relations( - faction TEXT, - race TEXT, - attitude NUMERIC, - PRIMARY KEY (faction, race), - CONSTRAINT attitude_range CHECK(attitude BETWEEN -1 AND 1) -); - -CREATE TABLE reputations( - name TEXT, -- player name - faction TEXT, - reputation NUMERIC, - PRIMARY KEY (name, faction), - CONSTRAINT reputation_range CHECK(reputation BETWEEN -1 AND 1) -); - -INSERT INTO regions VALUES +INSERT OR REPLACE INTO regions VALUES ('Dragons', 'ALL', 0.4), ('Scorn', 'scorn', 0.5), ('Scorn', 'scornarena', 0.5), ('Scorn', 'scorncounty', 0.5), ('Scorn', 'scornoldcity', 0.5); -INSERT INTO relations VALUES +INSERT OR REPLACE INTO relations VALUES ('Dragons', 'dragon', 1), ('Dragons', 'faerie', -1), ('Dragons', 'human', -1), @@ -43,5 +18,3 @@ INSERT INTO relations VALUES ('Scorn', 'troll', -1), ('Scorn', 'undead', -1), ('Scorn', 'unnatural', -1); - -INSERT INTO schema VALUES(1); diff --git a/python/CFReputation/sql/schema.sql b/python/CFReputation/sql/schema.sql new file mode 100644 index 000000000..bc517113b --- /dev/null +++ b/python/CFReputation/sql/schema.sql @@ -0,0 +1,25 @@ +CREATE TABLE IF NOT EXISTS schema(version INT); + +CREATE TABLE regions( + faction TEXT, + region TEXT, -- region name (or 'ALL') this faction controls + influence NUMERIC, + CONSTRAINT influence_range CHECK(influence BETWEEN 0 AND 1) +); + +CREATE TABLE relations( + faction TEXT, + race TEXT, + attitude NUMERIC, + PRIMARY KEY (faction, race) +); + +CREATE TABLE reputations( + name TEXT, -- player name + faction TEXT, + reputation NUMERIC, + PRIMARY KEY (name, faction), + CONSTRAINT reputation_range CHECK(reputation BETWEEN -1 AND 1) +); + +INSERT INTO schema VALUES(1);