This site is in archival mode. A replacement is being developed. In the meantime, please use the PBW2 Forums for community discussions. The replacement software for this site will use a unified account system with PBW2, and any newly created threads will carry over.
Welcome to Spaceempires.net
Login or Register

Search
Modules
· Content
· Downloads
· Forums
· Game Info
· Image Gallery
· Links
· Shipyards
· Topics
· Staff

User Info
· Welcome, Anonymous
Membership:
· New: Astorre
· New Today: 0
· New Yesterday: 0
· Overall: 3155

People Online:
· Visitors: 164
· Members: 0
· Total: 164

  

Spaceempires.net :: Script to return # of players with higher tech level :: View topic
Forum FAQ :: Search :: Memberlist :: Usergroups :: Profile :: Log in to check your private messages :: Log in


Script to return # of players with higher tech level

 
Post new topic   Reply to topic    Spaceempires.net Forum Index -> SEV Modding Discussion
View previous topic :: View next topic  
Author Message
arthurtuxedo
Space Emperor


Joined: Sep 09, 2007

PostPosted: Wed Aug 13, 2014 12:32 am    Post subject: Script to return # of players with higher tech level Reply with quote

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

PostPosted: Wed Aug 13, 2014 2:16 am    Post subject: Re: Script to return # of players with higher tech level Reply with quote

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

PostPosted: Tue Aug 26, 2014 10:35 pm    Post subject: Reply with quote

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

PostPosted: Tue Aug 26, 2014 10:40 pm    Post subject: Reply with quote

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

PostPosted: Wed Aug 27, 2014 1:30 am    Post subject: Reply with quote

ekolis wrote:
Did you call the Tech_Catchup function in the main event loop in Script_Main_ExternalEvents.txt?

I most certainly did not! Wink

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

PostPosted: Wed Aug 27, 2014 2:31 am    Post subject: Reply with quote

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
Moderator


Joined: Nov 04, 2003
Location: Minnesota

PostPosted: Wed Aug 27, 2014 4:27 am    Post subject: Reply with quote

Tech diffusion! Nice!

Ekolis we need this for FrEee Very Happy


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

PostPosted: Wed Aug 27, 2014 5:41 pm    Post subject: Reply with quote

It works! Thanks for the help!

Back to top
arthurtuxedo
Space Emperor


Joined: Sep 09, 2007

PostPosted: Wed Aug 27, 2014 5:55 pm    Post subject: Reply with quote

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

PostPosted: Wed Aug 27, 2014 11:52 pm    Post subject: Reply with quote

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

PostPosted: Thu Aug 28, 2014 5:12 am    Post subject: Reply with quote

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

PostPosted: Thu Aug 28, 2014 6:42 am    Post subject: Reply with quote

We could totally do this in FrEee as well, since the game supports scripting... Wink

That's no space station - it's a spreadsheet!


Back to top
edge8400
Space Emperor


Joined: Dec 08, 2010

PostPosted: Fri Aug 29, 2014 6:52 pm    Post subject: Reply with quote

Nice. I could see where adding a check for alliances could make the catch up vary. Will have to bookmark this Smile

Back to top
Display posts from previous:   
Post new topic   Reply to topic    Spaceempires.net Forum Index -> SEV Modding Discussion All times are GMT
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB
All logos and trademarks used on this site, all comments and stories posted for reading, all files hosted for download,
and all art work hosted for viewing are property of their respective owners; all the rest copyright 2003-2010 Nolan Kelly.
Syndicate news: SpaceEmpires.net News RSS Feed - Syndicate forums: SpaceEmpires.net Forums RSS Feed
Page Generation: 0.93 Seconds