[PYTHON] changeResearchProgress python function problem

Darkator

Warlord
Joined
Sep 18, 2020
Messages
214
Location
Poland,EU
In the function changeResearchProgress(itech, ichange, iplayer)
when ichange = player.getCommerceRate (CommerceTypes.COMMERCE_RESEARCH) * 2
it works, but if there is ichange player.getCommerceRate (CommerceTypes.COMMERCE_RESEARCH) / 2 it doesn't work anymore.

And I am asking why when there is division instead of multiplication, it doesn't work anymore.
 
ichange player.getCommerceRate (CommerceTypes.COMMERCE_RESEARCH) / 2
There is no equal sign in there. :confused:
Also there is a wrong space character after function "getCommerceRate" and the arguments in "()".

ichange = player.getCommerceRate(CommerceTypes.COMMERCE_RESEARCH) / 2

Potentially a division may also get you fractions like 0.5 which in an integer would always round down to 0.
That is why code like this often uses artificial multiplication by 100 first before it does division.
Later in your code when you are almost done, you then of course have to divide by 100 again.
 
I don't know if I did it right, but it still doesn't work
code8.png
 
I don't know if I did it right, but it still doesn't work
I am pretty sure this is not correct without even knowin what you really try to do.

for example in line 11:
You are basically dividing by 1000. :confused: :undecide::dunno:
(You divide by 10 and then divide again by 100)

Formulas (multiplications / divisions) are always read / interpreted from left to right.
This has to become 0.
 
I wants to achieve the effect that the total research of the team is divided by the number of its members.
number of members: gc.getTeam (iTeam) .getNumMembers ()
 
The problem is just this here:

iBonusReserach = (... / 10 ... / 100)
----> the same as
iBonusReserach = (whatever you calculate in there) / 1000
---> iBonusReserach most certainly gets always 0.

Buy maybe I simply do not understand your code.
But it seems more like you do not yet understand integers.
 
Last edited:
then what needs to be done for the change Research Progress feature to slow down team research. And she did nothing
 

Attachments

  • code9.png
    code9.png
    60.5 KB · Views: 46
If the DLL is applying normal research and you want a penalty to be applied which is slowing the research rate, shouldn’t the change value you are applying be negative, to claw back some of the research that the DLL gives?
 
And she did nothing

@Darkator


Casting a number smaller than 1 as an integer will turn it into a 0.

-----------------------

Thus what I am trying to tell you is:

Line 11: iBonusReserach = (whatever you calculate in there) / 1000
---> iBonusReserach will be something like 0.001 or maybe even 0.1.
(It will simply be smaller than 1)

Line 12: int (iBonusReserach )
---> int (0.001) is 0
(Integers can not have decimals.)

Line 12: changeReserachProgress (.... int (iBonusReserach ) ...)
---> changeResearchProgress ( .... 0 ....)
(Which in all reasonable "change method implementations" means to do nothing.)

-----------------------

Summary:
Your whole code ends up in:

changeResearchProgress(0)
---> aka do not change
---> aka the complete code does nothing

By the way:
Something like changeResearchProgress(0.9) does not work either - as integer it is simply 0 (because smaller 1).
Something like changeResearchProgress(2) of course does work - because it is an integer larger 0.

-----------------------

Sorry but I simply do not know how else I should explain it. :dunno:
 
Last edited:
from the explanations there is no problem because I understand, but my point is whether it is possible to do so that it slowed down the research in python.
 
from the explanations there is no problem because I understand, ...
Ok, just wanted to make sure you understand why your code will not do anything / fail. :thumbsup:
(It was not sure because of the code you showed.)

If your Python code generates a number that is (absolute) smaller than 0 there is no point in feeding it into a DLL funciton for integers.
The DLL function (reading integers) will always interpret it as 0 and do nothing.

Well sure you could simply implement in Python "changeResearchProgress(-iPenalty)" with iPenalty being an integer like e.g. 5 for 5 team members.
But that would most likely completey stop all Research of your team members and is thus probably a bad idea.

...but my point is whether it is possible to do so that it slowed down the research in python.
The answer I gave below is still valid.
I can not imagine how that should work in Python
Also as I said:
But in DLL such "Yield calculation rules" are a piece of cake.
In DLL you could actually modify "changeResearchProgress" itself.

------

In DLL however you could reprogram the logic to use float instead of integers instead.
(Or you could use "artificial inflation" by multiplying with 100 directly in the DLL methods. This can simply not be done in Python.)

Programming mathematic formulas and algorithms is much easier in a real programming language.
(Python is just a scripting language as you most certainly also know.)

------

Maybe I am simply not creative enough to implement that in pure Python though. :dunno:
(I could however read the code above and tell you why it would not work.)

------

Summary:
Sorry for not being able to give you any better advice than "Go for DLL."
 
Last edited:
if it is impossible it is impossible
I am not claiming that it is not possible at all to do what you want in Python. :dunno:
(All I said is that I can not imagine it by the way you describe it.)

I am not even playing or modding Civ4BTS because I play and mod Civ4Col.
The DLL you use I have never seen. I only work on my own DLL.

The only thing I really saw was that you tried to use "fractions" in an "integer" method.
According to that I tried to explain why your approach of "divisions" could not work.

Summary:

Maybe there is another smart approach to do what you want with another method or another modder has an idea. :thumbsup:

By the way:
Using "changeResearchProgress" by substracting integers should work. (e.g. "-5" for 5 team members.)
Just do not think that is really what you want. It feels a little bit too crude. :dunno:
 
Last edited:
Do you intend to reduce the research rate for a player on a team with 10 members by 19%? That’s what would happen when this ran as you’re applying a penalty twice.
I’d suggest (doing this on phone so tabbing is incorrect),
Code:
iPenalty = 0
if gc.getTeam(iTeam).getNumMembers() > 9:
  iPenalty = 9
elif gc.getTeam(iTeam).getNumMembers() > 0:
  iPenalty = gc.getTeam(iTeam).getNumMembers()
iBonusResearch = player.getCommerceRate(CommerceTypes.COMMERCE_RESEARCH)*iPenalty/100
gc.getTeam(player.getTeam()).changeResearchProgress(iTech, iBonusResearch, iPlayer)

What is the hook you are using to call this function?
 
the penalty for a team of up to 9 members is to be ten times the number of members in percentages
5 team members = 50% penalty
for this, when the number of people reaches more than 10 or ten people, then the penalty reaches 90% and nothing more.
But i guess it doesn't work like i wanted
 
There was a typo in my previous post, 19% should have been 190% and I’d omissions in the lines of code too.

Code:
iPenalty = 0
if gc.getTeam(iTeam).getNumMembers() > 9:
  iPenalty = -90
elif gc.getTeam(iTeam).getNumMembers() > 0:
  iPenalty = gc.getTeam(iTeam).getNumMembers() * -10
iBonusResearch = player.getCommerceRate(CommerceTypes.COMMERCE_RESEARCH)*iPenalty/100
gc.getTeam(player.getTeam()).changeResearchProgress(iTech, iBonusResearch, iPlayer)
should give the percentages you want.
 
Top Bottom