C++ Mounts add variables

zxmatzx

Intermediate OT User
Joined
Dec 1, 2010
Messages
124
Best answers
5
Reaction score
33
Hello,
Im working on a advanced mount system, and need to add some new properties to mounts. My knowledge in C++ is almost none. I know what i can do(logic), but don't know how to do. I was looking some files(mounts.cpp, mounts.h, player.cpp, game.cpp) and following the mounts data logic trying to understand how it works.
I found a function that return the infos from xml, im needing only to add new variables to my .xml file, but i know, if the Mounts::loadFromXml()(in mounts.cpp), don't assign values to the new variables i can't access it from the function.
This is the function that i found: Game.GetMounts().

I need some help to add those new variables to loadFromXml(), Game.GetMounts().

What i know i need to do:
Add new variables in struct Mount in Mounts.h to recive the values from loadFromXml()
Change loadFromXml() to read the new values in .xml file and assign to new variables
Change Game.GetMounts() to read new variables and return too.

But i don't know how to do in C++.
Is possible put a lua-like table? Like:
XML:
<mount id="1" clientid="368" name="Widow Queen" speed="20" premium="yes" properties="maxLevel = 10, xpGainRate = 2.0, speedModifier = 2" />
I think this way, i don't need to make changes if i need to add new properties.
If it doesn't work, i now the variables that i need(names and value types).

I know i can use Game.GetMounts(), get mountId from it, make a table and use the id to get mount info in Lua, but im trying to do this with C++. Im already reading/learning C++, i think this will be very helpfull.
Thanks for atention.

--EDIT
I realized that I will have to modify the toggleMount function in player.cpp too, because when level up the mounts, they would have their speeds changed, and would not use the speed base as the function does. Maybe something like:
C++:
if (currentMount->speed != 0) {
newSpeed = currentMount->speed + (currrentMount->speedModifier(new propertie in .xml) * mountLevel) //Sorry for this, idk how to declare and sum variables in C++
            g_game.changeSpeed(this, newSpeed);
}
mountLevel variable = Player Storage Value, maybe a table like:
Lua:
--                    [mountId] = Storage Number
mount_level_storages = {
                        [1] = 1000,
                        [2] = 1001,
                        [3] = 1003,
                       }
In lua? In C++? Where would be better? Lua i guess...

bump

bump
I think i can do this, maybe with some orientation, i will try start code this today, any help will be nice.
 
Last edited:
OP
Z

zxmatzx

Intermediate OT User
Joined
Dec 1, 2010
Messages
124
Best answers
5
Reaction score
33
Hello,
I finished my code today, i think its working Okay, i did some test and goes all well. I would like someone take a look, and give me some tips, about errors, improvements, bugs, any help.

Im using a fresh TFS 1.2 sources, with the following commits:
-Sorry about this mess on GitHub, im learning how to use-

Using this XML tag:
XML:
 <mount id="1" clientid="368" name="Widow Queen" speed="20" premium="yes" speedModifier="10" levelStorage="3000" maxLevel="5" />
To change speed, set player storageId 3000, to level and the speed will be:
newSpeed = BaseMountSpeed + (speedModifier * valueInLevelStorage)
20 + (10 * 5[if mount level has 5]) = 70
If mount has level 0 or less, player will recive only BaseMountSpeed

Thank you.
 
OP
Z

zxmatzx

Intermediate OT User
Joined
Dec 1, 2010
Messages
124
Best answers
5
Reaction score
33
Hi,
I found a bug, but i dont know How can happens... In mounts.xml, speed atribute is 20, but player only gain half(10), If i change speed to 10 then gain only 5, i wrote the code, i dont divide the speed value by 2... What can be?
 
OP
Z

zxmatzx

Intermediate OT User
Joined
Dec 1, 2010
Messages
124
Best answers
5
Reaction score
33
Bump
Still looking for some help.
 
OP
Z

zxmatzx

Intermediate OT User
Joined
Dec 1, 2010
Messages
124
Best answers
5
Reaction score
33
Hi,
I found a bug, but i dont know How can happens... In mounts.xml, speed atribute is 20, but player only gain half(10), If i change speed to 10 then gain only 5, i wrote the code, i dont divide the speed value by 2... What can be?
Could not figure out why this happens, anyone?
Still looking for Review in my code.
Thanks.
 

Stigma

Veteran OT User
Joined
Feb 14, 2015
Messages
4,707
Best answers
415
Reaction score
2,270
Could not figure out why this happens, anyone?
Still looking for Review in my code.
Thanks.
There's nothing wrong with the code, speed gets divided by 2 for display in client, the real speed is *2 what you see in your client skill window.
 
OP
Z

zxmatzx

Intermediate OT User
Joined
Dec 1, 2010
Messages
124
Best answers
5
Reaction score
33
There's nothing wrong with the code, speed gets divided by 2 for display in client, the real speed is *2 what you see in your client skill window.
Realy thanks Bro!
 
Top