Emmanuel BENOîT
56eddcc4f0
* Added a set of tables which define game updates and their targets. These definitions replace the old enumerate type. Added a set of triggers which automatically create specific update tables, insert missing entries, etc... when game update types are being manipulated. * Removed manual insertion of game updates from empire creation function and universe generator. * Added registration of core update targets (i.e. planets and empires), updated all existing game update processing functions and added type registrations * Created Maven project for game updates control components, moved existing components from the -simple project, rewritten most of what they contained, added new components for server-side update batch processing
51 lines
No EOL
1.5 KiB
PL/PgSQL
51 lines
No EOL
1.5 KiB
PL/PgSQL
-- LegacyWorlds Beta 6
|
|
-- PostgreSQL database scripts
|
|
--
|
|
-- Game updates - planet income and upkeep
|
|
--
|
|
-- Copyright(C) 2004-2010, DeepClone Development
|
|
-- --------------------------------------------------------
|
|
|
|
|
|
CREATE OR REPLACE FUNCTION sys.process_planet_money_updates( c_tick BIGINT )
|
|
RETURNS VOID
|
|
STRICT VOLATILE
|
|
SECURITY INVOKER
|
|
AS $$
|
|
DECLARE
|
|
rec RECORD;
|
|
incme REAL;
|
|
BEGIN
|
|
FOR rec IN SELECT p.name_id AS id , p.population AS pop ,
|
|
( ph.current / p.population )::REAL AS happiness ,
|
|
( ea.planet_id IS NULL ) AS produces_income
|
|
FROM sys.updates su
|
|
INNER JOIN verse.planets_updates vu
|
|
USING ( update_id , updtype_id , updtgt_id )
|
|
INNER JOIN verse.planets p
|
|
USING ( name_id )
|
|
INNER JOIN verse.planet_happiness ph ON ph.planet_id = p.name_id
|
|
INNER JOIN verse.planet_money pm ON pm.planet_id = p.name_id
|
|
LEFT OUTER JOIN emp.abandon ea ON ea.planet_id = p.name_id
|
|
WHERE su.update_last = c_tick AND su.update_state = 'PROCESSING'
|
|
FOR UPDATE OF p, pm
|
|
LOOP
|
|
IF rec.produces_income THEN
|
|
incme := verse.compute_income( rec.pop , rec.happiness ,
|
|
verse.get_raw_production( rec.id , 'CASH' )
|
|
);
|
|
ELSE
|
|
incme := 0;
|
|
END IF;
|
|
UPDATE verse.planet_money
|
|
SET income = incme ,
|
|
upkeep = verse.get_planet_upkeep( rec.id )
|
|
WHERE planet_id = rec.id;
|
|
END LOOP;
|
|
END;
|
|
$$ LANGUAGE plpgsql;
|
|
|
|
SELECT sys.register_update_type( 'Planets' , 'PlanetMoney' ,
|
|
'Planets'' income and upkeep are being updated.' ,
|
|
'process_planet_money_updates'
|
|
); |