View previous topic :: View next topic |
Author |
Message |
arthurtuxedo Space Emperor

Joined: Sep 09, 2007
|
Posted: Wed Aug 13, 2014 12:32 am Post subject: Script to return # of players with higher tech level |
|
|
Hi all,
I am trying to implement a script which would grant 2% of RP's toward any tech level that other empires have already researched. I think I have figured out how to grant the RP's by modifying SJ and ekolis' research breakthrough script, but cannot figure out how to cycle through the players and count how many have a higher tech level.
I know it will involve the "Sys_Get_Empire_Research_Tech_Level" function and presume it will use the "for playerIdx := 1 to Sys_Get_Number_Of_Players() do" function, but have no idea what the syntax should look like.
Can someone who knows about scripting point me in the right direction?
Back to top |
|
 |
Zwo_Dvoongar Space Emperor

Joined: Feb 02, 2011
|
Posted: Wed Aug 13, 2014 2:16 am Post subject: Re: Script to return # of players with higher tech level |
|
|
arthurtuxedo wrote: | Hi all,
I am trying to implement a script which would grant 2% of RP's toward any tech level that other empires have already researched. I think I have figured out how to grant the RP's by modifying SJ and ekolis' research breakthrough script, but cannot figure out how to cycle through the players and count how many have a higher tech level.
I know it will involve the "Sys_Get_Empire_Research_Tech_Level" function and presume it will use the "for playerIdx := 1 to Sys_Get_Number_Of_Players() do" function, but have no idea what the syntax should look like.
Can someone who knows about scripting point me in the right direction? |
Well, you're already on the right track. I've only done AI scripts, so I don't know every detail. You'll want to nest your for-next loops.
for playerIdx := 1 to Sys_Get_Number_Of_Players() do
for playerIdy := 1 to Sys_Get_Number_Of_Players() do
if playerIdx <> playerIdy then
for tech_test_id = 1 to TOTAL_NUMBER_TECHS do
// Compare level of playerIdx to level of playerIdy
// If playerIdx has less, grant bonus
next tech_test_id
endif
next playerIdy
next playerIdx
That's the general strategy I'd use. I don't know exactly how the game assigns tech id's to techs, but I'd guess it just numbers them sequentially, and straightforward. That's about the only part I see that could easily turn out buggy, if the game does something strange instead.
Checking the scripting pdf, I found
Sys_Get_Tech_Area_Count
Sys_Get_Tech_By_Index
Sys_Get_Tech_Area_Name
So even that part shouldn't be too bad.
set TOTAL_NUMBER_TECHS := Sys_Get_Tech_Area_Count()
should handle that issue.
(Actually, it might be better to set some "TOTAL_PLAYERS" variable to := Sys_Get_Number_Of_Players(), so it isn't repeating that function all the time.)
Back to top |
|
 |
arthurtuxedo Space Emperor

Joined: Sep 09, 2007
|
Posted: Tue Aug 26, 2014 10:35 pm Post subject: |
|
|
This is what I came up with, but it doesn't seem to be working:
Code: | function Tech_Catchup returns boolean
vars
playerIdx: long
playerIdy: long
techIdx: long
techID: long
rpCost: real
techName: string
playerATech: long
playerBTech: long
begin
// loop through the players with one nested loop, e.g. compare player 1 to player 2, then 3, etc. then player 2 to player 1, then 2, then 3, etc.
for playerIdx := 1 to Sys_Get_Number_Of_Players() do
for playerIdy := 1 to Sys_Get_Number_Of_Players() do
if playerIdx <> playerIdy then
// loop through the tech areas
for techIdx := 1 to Sys_Get_Tech_Area_Count() do
set techID := Sys_Get_Tech_By_Index(techIdx)
// set variable equal to each player's tech level
set playerATech := Sys_Get_Empire_Research_Tech_Level(playerIdx, techID)
set playerBTech := Sys_Get_Empire_Research_Tech_Level(playerIdy, techID)
// check if player B has higher tech level than player A
if playerBTech > playerATech then
// catch up by 2% per turn toward the next tech level for each player that is at least 1 level ahead
set rpCost := Sys_Get_Empire_Research_Tech_Area_Cost_For_Next_Level(playerIdx, techID)
call Sys_Change_Empire_Research_Tech_Area_Accomplished_Amount(playerIdx, techIdx, rpCost * 0.02)
endif
endfor
endif
endfor
endfor
return true
end |
I added #include Script_DJAS_Tech_Catchup.txt to Script_MainExternalEvents, compiled it, and included the .csf in GameTypes/DJASv101+/Data, which I assume is the correct way to implement it.
Any ideas where I might have gone wrong?
Back to top |
|
 |
ekolis Virtual Guru

Joined: Aug 04, 2003 Location: Cincinnati, OH, USA
|
Posted: Tue Aug 26, 2014 10:40 pm Post subject: |
|
|
Did you call the Tech_Catchup function in the main event loop in Script_Main_ExternalEvents.txt?
That's no space station - it's a spreadsheet!
Back to top |
|
 |
arthurtuxedo Space Emperor

Joined: Sep 09, 2007
|
Posted: Wed Aug 27, 2014 1:30 am Post subject: |
|
|
ekolis wrote: | Did you call the Tech_Catchup function in the main event loop in Script_Main_ExternalEvents.txt? |
I most certainly did not!
How do I do that? Remember I'm pretty much a scripting virgin.
Back to top |
|
 |
ekolis Virtual Guru

Joined: Aug 04, 2003 Location: Cincinnati, OH, USA
|
Posted: Wed Aug 27, 2014 2:31 am Post subject: |
|
|
So there should be a "function Main returns boolean" somewhere in there... put a "call Tech_Catchup()" line right before the "call External_Events()" in that function.
That's no space station - it's a spreadsheet!
Back to top |
|
 |
Combat_Wombat Moderator


Joined: Nov 04, 2003 Location: Minnesota
|
Posted: Wed Aug 27, 2014 4:27 am Post subject: |
|
|
Tech diffusion! Nice!
Ekolis we need this for FrEee 
Co-Lead of the FrEee project an open-source Space Empires IV clone
Author of Invasion! for Space Empires IV
Back to top |
|
 |
arthurtuxedo Space Emperor

Joined: Sep 09, 2007
|
Posted: Wed Aug 27, 2014 5:41 pm Post subject: |
|
|
It works! Thanks for the help!
Back to top |
|
 |
arthurtuxedo Space Emperor

Joined: Sep 09, 2007
|
Posted: Wed Aug 27, 2014 5:55 pm Post subject: |
|
|
I can already see this will make playing against the AI even easier. At some point I'll need to learn to script well enough to overhaul it and get it to actually attack instead of just turtling up. Society type balance will need adjustment, too, since Scientist, Berzerker, and Salvager research bonuses and penalties take on a new dimension with tech diffusion.
Back to top |
|
 |
Zwo_Dvoongar Space Emperor

Joined: Feb 02, 2011
|
Posted: Wed Aug 27, 2014 11:52 pm Post subject: |
|
|
arthurtuxedo wrote: | It works! Thanks for the help! |
Congrats!
Pretty snazzy idea. Glad you got it running. Same script as what you posted?
Back to top |
|
 |
arthurtuxedo Space Emperor

Joined: Sep 09, 2007
|
Posted: Thu Aug 28, 2014 5:12 am Post subject: |
|
|
Yep, no change. Btw I like your term "tech diffusion", mind if I use it?
Back to top |
|
 |
ekolis Virtual Guru

Joined: Aug 04, 2003 Location: Cincinnati, OH, USA
|
Posted: Thu Aug 28, 2014 6:42 am Post subject: |
|
|
We could totally do this in FrEee as well, since the game supports scripting... 
That's no space station - it's a spreadsheet!
Back to top |
|
 |
edge8400 Space Emperor

Joined: Dec 08, 2010
|
Posted: Fri Aug 29, 2014 6:52 pm Post subject: |
|
|
Nice. I could see where adding a check for alliances could make the catch up vary. Will have to bookmark this 
Back to top |
|
 |
|