Lemma Soft Forums

Supporting creators of visual novels and story-based games since 2003.


Visit our new games list, blog aggregator, IRC, and wiki.
Activation problem? Email [email protected]
It is currently Sat May 18, 2013 6:31 am

All times are UTC - 5 hours [ DST ]


Forum rules


Ask questions about one topic per thread, and use a descriptive subject. "NotImplemented error in script.rpy" is a good subject, "Tom's problems" is not. Remember to include all of traceback.txt or error.txt when reporting a problem, as well as the relevant lines of script. Use the [code] tag to format scripts.



Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Fri May 04, 2012 9:49 am 
Veteran

Joined: Sat Feb 26, 2011 9:36 am
Posts: 264
Location: Κωνσταντινούπολη, Βασιλεύα των Ρωμαύων
Projects: Rzeczpospolita Polska 1647
So for instance I have these scripts that defines the agricultural productivity of the economy in one year:

Code:
label Agricultural_Equations:
   
    $ Serf_Efficiency = Demography_Serf_AV*500/Total_Land_Aristocracy_AV + Serfdom*2
    if Serf_Efficiency >= 100:
        $ Serf_Efficiency = 100
    else:
        pass
    $ Grain_Produced_Serfs = Serf_Efficiency * Agricultural_Land_Aristocracy_AV * (100 + Serf_Grain_Modifier) * 0.0001
    $ Cash_Crop_Produced_Serfs = Serf_Efficiency * Cash_Crop_Land_Aristocracy_AV * (100 + Serf_Cash_Crop_Modifier) * 0.0001
    $ Cattle_Produced_Serfs = Serf_Efficiency * Pasture_Land_Aristocracy_AV * (100 + Serf_Cattle_Modifier) * 0.0001
   
    $ Yeomanry_Efficiency = Demography_Yeomanry_AV*500/Total_Aristocracy_Land_AV - Serfdom*2
    if Yeomanry_Efficiency >= 100:
        $ Yeomanry_Efficiency = 100
    else:
        pass
    $ Grain_Produced_Yeomanry = Yeomanry_Efficiency * Agricultural_Land_Aristocracy_AV * (100 + Yeomanry_Grain_Modifier) * 0.0001
    $ Cash_Crop_Produced_Yeomanry = Yeomanry_Efficiency * Cash_Crop_Land_Aristocracy_AV * (100 + Yeomanry_Cash_Crop_Modifier) * 0.0001
    $ Cattle_Produced_Yeomanry = Yeomanry_Efficiency * Pasture_Land_Aristocracy_AV * (100 + Yeomanry_Cattle_Modifier) * 0.01
   
    $ SOE_Grain_Efficiency = Demography_SOE_Labor_Agriculture_AV*500/Agricultural_Land_State_Owned + State_Property*2
    if SOE_Grain_Efficiency >= 100:
        $ SOE_Grain_Efficiency = 100
    else:
        pass
    $ SOE_Cash_Crop_Efficiency = Demography_SOE_Labor_Cash_Crop_AV*500/Cash_Crop_Land_State_Owned + State_Property*2
    if SOE_Cash_Crop_Efficiency >= 100:
        $ SOE_Cash_Crop_Efficiency = 100
    else:
        pass
    $ SOE_Cattle_Efficiency = Demography_SOE_Labor_Pasture_AV*500/Pasture_Land_State_Owned + State_Property*2   
    if SOE_Cattle_Efficiency  >= 100:
        $ SOE_Cattle_Efficiency  = 100
    else:
        pass
    $ Grain_Produced_SOE = SOE_Grain_Efficiency * Agricultural_Land_State_Owned_AV * (100 + SOE_Grain_Modifier) * 0.0001
    $ Cash_Crop_Produced_SOE = SOE_Cash_Crop_Efficiency * Cash_Crop_Land_State_Owned_AV * (100 + SOE_Cash_Crop_Modifier) * 0.0001
    $ Cattle_Produced_SOE = SOE_Cattle_Efficiency * Pasture_Land_Aristocracy_State_Owned * (100 + SOE_Cattle_Modifier) * 0.0001
   
    $ Grain_Produced_Total = Grain_Produced_Serfs + Grain_Produced_Yeomanry + Grain_Produced_SOE
    $ Cash_Crop_Produced_Total = Cash_Crop_Produced_Serfs + Cash_Crop_Produced_Yeomanry + Cash_Crop_Produced_SOE
    $ Cattle_Produced_Total = Cattle_Produced_Serfs + Cattle_Produced_Yeomanry + Cattle_Produced_SOE
    $ Food_Produced_Total = Cattle_Produced_Total + Grain_Produced_Total
    $ Food_Demanded_Total = Pop
    $ Food_Surplus = Food_Produced_Total - Food_Demanded_Total


(Note: While most variable names are self explanatory, there are a few less intuitive bits:

- SOE = State-Owned Enterprises.
- AV = Absolute Value
- Efficiencies are in percentage, so I have to divide them by 100 in formulae involving them to get the real value of the underlying variable)

Is there anything I can do to optimize it, i.e. make the whole thing less cumbersome?

Thanks in advance!

_________________
One Province Minor - 120 class variables and still counting!

Because there is no such thing as too many variables.


Top
 Profile Send private message  
 
PostPosted: Fri May 04, 2012 4:08 pm 
Ren'Py Creator
User avatar

Joined: Mon Feb 02, 2004 10:58 am
Posts: 10766
Location: Kings Park, NY
Completed: Moonlight Walks
Projects: Ren'Py
Two changes:

1) You probably want to have one big python block, rather than a lot of small ones.
2) This is purely stylistic, but you may wat to make use of min()

for example:

Code:
    python:
        Serf_Efficiency = min(100, Demography_Serf_AV*500/Total_Land_Aristocracy_AV + Serfdom*2)
        Grain_Produced_Serfs = Serf_Efficiency * Agricultural_Land_Aristocracy_AV * (100 + Serf_Grain_Modifier) * 0.0001
        Cash_Crop_Produced_Serfs = Serf_Efficiency * Cash_Crop_Land_Aristocracy_AV * (100 + Serf_Cash_Crop_Modifier) * 0.0001
        Cattle_Produced_Serfs = Serf_Efficiency * Pasture_Land_Aristocracy_AV * (100 + Serf_Cattle_Modifier) * 0.0001


You might also want to make the code work instead of numbers, rather than percentages - but that would be to just get some of the multipliers out of there.

_________________
Another Old-Fashioned Bishoujo Gamer
Supporting creators since 2004; Code > Drama
(When was the last time you backed up your game?)
"It is not the critic who counts; not the man who points out how the strong man stumbles, or where the doer of deeds could have done them better. The credit belongs to the man who is actually in the arena, whose face in marred by dust and sweat and blood; who strives valiantly; who errs, who comes short again and again, because there is no effort without error and shortcoming" - Theodore Roosevelt


Top
 Profile Send private message  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


Who is online

Users browsing this forum: Google [Bot]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Protected by Anti-Spam ACP
Powered by phpBB® Forum Software © phpBB Group