KAZESUI'S PROFILE

Doing Super Programming
on Super Computers
for Super Performance
The Curse of Cpt. Lovele...
Nautical-themed cephalopod-pirate-based action-shmup.

Search

Filter

[RM2K3] DynRPG Compiling Error

author=McBick
Is there a reason I can't include the if statements in a callback that is called multiple times? From my understanding nothing will happen, at worst it will check a single line of execution. I think the battle callbacks are only called 30 times a second, so that means the callback will be called 30 times a second? This seems quite negligible as even the weakest CPUs could run millions of lines of code a second.


This is just a code thing, as there shouldn't be any performance issues from this (that aside, I would have thought it would be called 60 times a second, as rm2k3 otherwise generally runs at a fixed 60 FPS if it is able to keep up. Never checked for battles though).

While it's not going to be a performance issue, it will look like a curiosity though, since that if will be processed many times for no real reason. Ideally, you wouldn't need to go back and forth between the callback functions, since one would ideally just allocate it once and then use it in the other function. If you have a variable amount of text you might want to add. It's up to your discretion to do so or not though, and your plugin should function perfectly fine without doing this as well.

Another little tip which requires minimal change and keeps the code in the battle callback
if(!myImage["winStats"]){
    myImage["winStats"] = RPG::Image::create(320, 64);
    myImage["winparty"] = RPG::Image::create(320, 64);
    ...
    myText["winStats"] = RPG::Image::create(160, 16);
    ...
}

since you only allocate all images at once, you only need to check for one of your images. Either all of the images will have been allocated or none of them. This will prevent a little bit of code clutter from have a long list of if statements.

[RM2K3] DynRPG Compiling Error

author=McBick
std::map<int,RPG::Image*> images;
images[0] = RPG::Image::create();
images[0] = RPG::Image::create(); //A crash should happen here
RPG::Image::destroy(images[0]);
From what I studied this should not work. At least from my understanding you can not declare the same key twice, but perhaps I misunderstood this?

You're half right. That you cannot declare the same key twice is true, but a declaration of the key is actually only done the first time. If you would use the "insert" method, it would probably have failed, but not when using the subscript operator (the square brackets). What actually happens is that when you use this, it will first check if a key exists for they key you give, and if it does not exist, it will create a key. This is what happens the first time, but the second time it just gives you access to the pointer variable without trying to create another key.


author=Kazesui
You do not need the std::map data structure to use the if check. To be honest, if you have two static images which you use and you don't loop through a for loop anyway, it would generally make sense to give them more specific names and use them directly as a variable

Yes, I have learned this upon cleaning up my code. I have kept the map structure only for any HUD text now, but have since changed the objects for the window graphics to each have their own variable.

author=McBick
author=Kazesui
RPG::Image* image;
image = RPG::Image::create();
if(!image) //Error cannot convert image from RPG::Image to type bool.
    image = RPG::Image::create();
RPG::Image::destroy(image);
I'm not sure how this is supposed to work as the if condition will always be false and the destroy function will always be called immediately after creating the Image. Also this does not compile.

You sure you remembered to make "image" an RPG::Image* rather than an RPG::Image? While I don't have a compiler to validate with at the moment (or rather, I don't have one compatible with DynRPG), I'm pretty sure this should compile.
Also, the code was just for demonstrative purpose rather than being something which can actually be used. I was simply trying to make sure you didn't think you needed the map data structure to make the if statement work (which in this code example should be perpetually false, as you say).

author=McBick
std::map<std::string, RPG::Image*> myImage;
std::map<int, RPG::Image*> myText;
if(!myImage["winStats"])
    myImage["winStats"] = RPG::Image::create(320, 64);
if(!myImage["winParty"])
    myImage["winparty"] = RPG::Image::create(320, 64);
...
if(!myText["winStats"])
    myText["winStats"] = RPG::Image::create(160, 16);
...

I have no destroy functions as the code will never create multiples of the same Image objects.

I'm going to assume that the std::maps are global and that the ifs are within a callback function (I believe it should crash if this was all global). There's no need for the if statements at this point, since the keys can't exist at the point of the check, and as long as you're not using a callback which is called multiple times (which you shouldn't anyway for something meant to be allocated once like here). Apart from that, as mentioned, this should be fine.

[RM2K3] DynRPG Compiling Error

author=McBick
I believe with the map function it is impossible to have multiples of the same key too, so this should protect me from memory leaks too

The map data structure does not really protect you from memory leaks as it the value can be overwritten the exact same way a regular variable can
std::map<int,RPG::Image*> images;
images[0] = RPG::Image::create();
images[0] = RPG::Image::create();
RPG::Image::destroy(images[0]);

The code above also leads to a memory leak. The key does not protect you. Just as a side note
RPG::Image* image;
image = RPG::Image::create();
if(!image)
    image = RPG::Image::create();
RPG::Image::destroy(image);

This code does not lead to a memory leak. You do not need the std::map data structure to use the if check. To be honest, if you have two static images which you use and you don't loop through a for loop anyway, it would generally make sense to give them more specific names and use them directly as a variable, like RPG::Image* battleHUD or something (they still need to be global though). You might already understand this, but I'm just trying to attack it from various angles, since there still seems to be some confusion given how keys do not give protection against memory leaks.

author=McBick
I think I know why there aren't really any plug-ins that change the default battle system though. There are many issues with the order in which rm2k3 changes battle variables and such. I would have been better off just making my battle system exist independently from the default battle system. Unfortunately that would mean the removal of battle events as well unless I really went out of my way to parse monster group pages and battle events, which would be very time consuming.


That's probably part of it, along with the fact that most of the C++ developers here probably don't understand the battle system all too well, and the ones which do don't code C++ all too well. That, and it probably is tricky to make something nice and generic which could be useful for other people based on the default battle system without limiting the ways a plugin user can make changes to the system to fit their specific needs. It's a lot easier to hack together something which does what you need for your own game than to something which is generic enough for a random person to be able to incorporate it in a useful manner in their own game which won't require them to learn about a lot of quirks and conditions to be able to use the plugin. The default battle system just doesn't make this easy.

[RM2K3] DynRPG Compiling Error

author=McBick
If I run this code only once at start up will there ever be a need to destroy these objects?

Nope, if you load the pictures once at the start, preferably with the onInitFinished() callback, then you do not need to destroy the images at all, and this would be a lot better than recreating the images all the time.

author=McBick
author=Kazesui
Note that if you assign RPG::Image::create() to a pointer variable before having used destroy on the previous image (assuming there was one), you will have a memory leak since none of the other methods will fully deallocate the memory.

This does not appear to be true as I have created multiple Image objects without ever destroying them only to later destroy them, usually in a different callback. I haven't had any memory leaks and I have been checking constantly for them to be sure. Perhaps I am misunderstanding what you mean though?

I'm not saying you need to destroy the images each frame, nor that you have to destroy them within the same callback. I've been advocating the opposite pretty much the entire time. What I'm saying is something along the lines of this
RPG::Image* ptr;
ptr = RPG::Image::create();
ptr = RPG::Image::create();
RPG::Image::destroy(ptr);

This code creates a memory leak. RPG::Image::create() has been called twice, but "ptr" can only store one address, meaning the memory of the first object is lost. Both images are not destroyed upon calling RPG::Image::destroy. Of course, if you have your if statements to check if an image already exist, then you won't be creating new images before having called a destroy function first.

[RM2K3] DynRPG Compiling Error

author=McBick
@Kazesui
I am cleaning up some of my code and I was wondering how bad is leaving something like this?
void destroyImages() //Checks and destroys any existing Image objects
    {
        if(myImage[0]) //Is there a better way of doing this?
           {
               RPG::Image::destroy(myImage[0]);
               myImage[0] = NULL;
           }
           if(myImage[1])
           {
               RPG::Image::destroy(myImage[1]);
               myImage[1] = NULL;
           }
           for(int i=0; i<8; i++)
           {
               if(myText[i])
               {
                   RPG::Image::destroy(myText[i]);
                   myText[i] = NULL;
               }
           }
    }
void getCustomWindows(std::string loc[], RPG::Window* currentWindow)
    {
        //This function is called every frame, I think? it exists in onBattleStatusWindowDrawn
        CBS::destroyImages(); 
        if(!myImage[0]) //Load Window Image
        {
            myImage[0] = RPG::Image::create();
            myImage[0]->loadFromFile(loc[3]);
            myImage[0]->useMaskColor = true;
        }
        RPG::screen->canvas->draw(0, 140, myImage[0]);
        if(!myText[0]) //Load Text Image
        {
            myText[0] = RPG::Image::create(320, 80);
            myText[0]->setSystemPalette();
            myText[0]->useMaskColor = true;
        }
//The rest of the script builds the text onto the window and such.
...
}

Basically my question is, how bad is it to create and destroy the same objects every frame, especially considering these are Image objects and will be redrawn every frame? It actually only destroys the Image if it exists, but it will always exist since they're created right after the destroy function is called, so it is an endless cycle until the condition to call getCustomWindows becomes false. I have this destroy function at the beginning of all my functions that create Image objects, so I don't have to worry about memory leaks or keeping track of them. Something to note is that the Images aren't dynamic, so I can't just call the function once as it needs to be updated constantly to take into account any changes.

After reviewing this code I have noticed it is a very crude way of doing what I want. Right now I am almost finished with this plugin and just want to fix any bug fixes and release it, at least the first iteration of it. I want to know if this current method I have will cause issues for people who use it though. In my current testing I haven't run into any more issues, but I also haven't done extensive testing with battle events. I plan to do some battle event testing as well, but only things related to message boxes and battle animations as they are the most likely to break my plugin.


You'd probably need to have a relatively old computer by todays standard for it to be a problem, so you're probably fine as far as this specific plugin is concerned, but as a coding practice, this is pretty terrible. Loading data from file as well as allocating memory are relatively expensive operations. If you have graphics with animations, the standard thing to do is to load a full spritesheet (like a charset file) and then copy a subset of that bigger image into a tinier image which you want to display. It's also standard to re-use graphic were possible (you only need to load the graphic for a single slime king if you have multiple of them in a battle. You can simply just use the same image a draw it at multiple spots), but for your plugin, doing this would probably be overkill, as it will add code complexity.
You want to load the graphics once and keep them all the way until they're not used anymore. In your case, that means you should be loading the images at the start of a battle and then keep the graphics until the end of the battle at which point you could dispose of all of the battle graphics. Also note here that loading a graphic does not mean that you have to use that particular graphic when you load it. Ultimately, it's first when you decide to use "RPG::screen->canvas->draw()" that this has an impact on what is seen by the player.

As for your code snippets, in general you're not guaranteed to have consecutive numbers for a std::map structure, so normally you would something called an iterator to loop through them instead. Apart from that, it looks fine. It's possible to drop the if statements if you can guarantee that these pieces of code can never be reached when an myImage and my_Text has no image to delete, but if this cannot be guaranteed or the code is complicated enough that it's unreasonable to enforce it, having if statements like this is perfectly fine. If in doubt, have if statements to prevent the game from arbitrarily crashing.

[RM2K3] DynRPG Compiling Error

author=McBick
I am confused now. If I am to understand, a basic array will work for the following code then? If I don't use a vector and use an array variable then wouldn't it not have a size method?
int speed[12]; //Will the following code work with this variable?
...
std::priority_queue<int> queue;
for(int i = 0; i < 12; i++)
{  
    int value = i;
    if(i<4 && RPG::Actor::partyMember(i)){
        value += RPG::Actor->partyMember(i)->getAgility() * 100;
        queue.push(value)
    }
    if(i>3 &&RPG::monsters[i])
        value += RPG::monsters[i]->getAgility() * 100;
        queue.push(value)
}

... 

int temp = queue.top();  
int currentId = temp % 100;
bool mon = false;
if(currentId > 3) // currentId will still be from 4 to 11 for monsters
    mon = true; 
...


The array was superfluous in the first place, since you can just directly add it to the priority_queue, and exchange the size for 12 like you do. I added in the array on the assumption that there is a way to query how many monsters and heroes are already given in the battle, but given how you can spawn new monsters I guess there might not be a good way of getting just getting the monsters in a neat fashion.

author=McBick
I didn't think about that. Perhaps I will leave it as is then. I have noticed that every time I change a section of my plugin, it creates new issues that need to be fixed. This process has caused me to rewrite much of my code, albeit much more cleanly and efficient, but it has delayed the release of my plugin.

It's a trade-off of learning new things and improving vs getting something done. It's good not to over focus on the first thing, as you can get things done and then improve while trying to get another thing done. This way you both learn and get things done.

author=McBick
Is it not possible to do this in DynRPG? For example:
void onFrame(RPG::Scene* scene)
{
    if(scene == RPG::SCENE_BATTLE && 00884800 == 0021) //Random memory value for example
    {
         00884800 = 0031; //new memory value
         ...
    }
}

As for finding the memory values I need, I was going to use a hex viewer.

First thing first, that's not how scene works. Scene does not contain arbitrary progress of the respective scene, just which scene the game is currently in, so this won't work.

Secondly, you can't find something in memory which is not stored to memory, not even at the time of the onFrame callback which is called once per frame. The skill set required to pull this one off is more similar to that required to create the DynRPG SDK in the first place, not just use it.
Finding the instruction memory is also not trivial to find, since it does not change. I don't think hex viewer is going to cut it, since you need to monitor the execution flow the assembly code of the rm2k3 program itself to figure out where the damage calculation instructions are stored. Most likely you would need something along the lines of a debugger or a disassembly program.

Again, I strongly recommend against trying to do this, since you're very unlikely to get anywhere meaningful with it at this stage (but if you want to sink an arbitrary amount of time into it nonetheless, debugger and disassembly is probably the way to go).

[RM2K3] DynRPG Compiling Error

author=Kazesui
All arrays have a size, but not a size method. The size method of e.g. std::vector<int> will return the number of elements in the array, not the number of bytes.


So if I am to understand it would be more efficient to do something like this then?
std::vector<int> speed;
for(int i=0; i<12; i++)
{
if(i<4 &&RPG::Actor::partyMember(i))
    speed.push_back(RPG::Actor->partyMember(i)->getAgility())
if(i>3 &&RPG::monsters[i])
    speed.push_back(RPG::monsters->getAgility())
}
std::priority_queue<int> queue;
for(int i = 0; i < speed.size(); i++){  
    int value = i  
    value += 100 * speed[i] 
    queue.push(value)
}

... 

int temp = queue.top();  
int currentId = temp % 100; 
queue.pop();  accessible
if(queue.empty()){
}


There is no need for the std::vector, as you could directly do the stuff in priority_queue. Using priority_queue alleviates some of the need for doing a search for which battler is next up since the next one will always be on top and can simply be removed when done. If you need a battler to get a second turn you could simply just push the same battler back into the queue with whatever value it's supposed to have (super high for double attack, with half agility for a second attack of a boss character or the like).

That said, you could use a std::vector and and max_element as well. It is less efficient than using a priority queue, but efficiency does not really mean much with such small numbers. For the sake of explaining it, max_element (or your for loop search, as I believe the implementation is similar) has an algorithmic complexity of O(n), which means that the order of operations needed to perform this algorithm scales linearly with the number of elements.
The priority queue is slightly different and scale as O(log(n)).

Let's say the agility of your battlers as uniformly distributed among the 12 possible entries, and that you actually have the full 12 battlers acting out in a battle. Finding the battler with the highest agility 12 times for one round of the battle will likely cost around 84 operations. Doing the same thing with priority_queue would be around 55 operations (note that this is very, very simplified and ignores many things). Now, the difference between executing 72 operations or 43 operations on any moderately modern cpu is probably going to be on the order of micro to nano seconds, and it's not even happening all at once since all 12 battlers don't act at once anyway, so there's no real reason to think about this at the moment.

Personally, I think using it, can lead to cleaner and nicer code which is easier to keep bug-free, but that assumes that you'll be able to use it that way, and it's hard to dictate how you're supposed to use it from snippets, so I'm just trying to guide you as to how you could use it, but using it wrong will probably lead to less maintainable code, which is another reason why I say just go with what seems right to you at the moment as long as it doesn't break things, and then write another plugin later where you try something new, using new data structures and the like, and as you keep doing this, you'll learn more stuff and figure out why stuff you did in the past was weird. This happens to everyone and I'm not sure it helps trying to rush into the path of "clean code" since you need to go through dirty code to get why clean code is clean in the first place.

author=McBick
I am trying to write new variables to be used in the battle calculations in the default battle system. Once I find the memory values that calculate damage in rm2k3 I would like to convert them into pointers, so that I can change those values and write my own battle algorithm. So I need to find a way to write to memory addresses. For example:
int damage = algorithm; //This would be the new formula for damage.
00681422 = damage; //I am aware this would not work, but how would I do something like this?
//This is a random memory value to show what I am trying to do
//Ideally I would overwrite values that exist in rm2k3, so I can 
//create my own damage algorithm. I am aware I would have to change multiple
//memory values to get this to work, but I need to know the proper way
//to alter memory values first


This will probably not work, since rm2k3 is likely computing this damage on the fly, which means there is no place in memory you could alter the value to change the damage output. As mentioned before, since this step probably happens somewhere after "onDoBattlerAction()" and before "onBattlerActionDone()", meaning you have no way of changing the value while it is in memory. The only way to deal with this would be to replace the instruction memory of the algorithm itself which computes the damage.

The way I imagine this would be dealt with, would be to inject assembly code at the point where the damage calculation is supposed to happen (finding it will probably require 3rd party software for analyzing the execution of the data already), then have that assembly code goto the your new algorithm, and then you jump right after the point at which the damage calculation is supposed to be done, and pray there are no funky flags inbetween which will crash the game for not having happened. To be honest, I think it's far too soon for you to attempt this, and you might be better off asking for help from some people who create patches, or just simulate this with additional skills.

[RM2K3] DynRPG Compiling Error

author=McBick
After doing some research would something like this be even better then?
//In this example speed[] stores the agility values of all battlers
mValue = *std::max_element(speed, speed+12); //Finds the highest value in the array?
currentBattler = std::distance(speed, std::find(speed, speed+12, mValue)); //Finds the index value for speed which is the battler id


This also looks perfectly fine. There are many ways to solve a problem, and I just provided one which I could think of from the top of my mind, but this is no worse if you like the looks of this.

author=McBick
How is this:
std::priority_queue<int> queue;
for(int i = 0; i < bAGI.size(); i++){  
    int value = i  
    value += 100 * bAGI[i] 
    queue.push(value)
}

... 

int temp = queue.top();  
int currentId = temp % 100; 
queue.pop();  accessible
if(queue.empty()){
}

different from this?
std::priority_queue<int> bTurn;
for(int n : {bAGI[0], bAGI[1]... BAGI[11]}
    bTurn.push(n);
for(int i=0; i<12; i++)
    if(bAGI[i] == bTurn)
        curBattler = i;

The latter method seems to be cleaner, to me at least, but perhaps I am not understanding the method you listed? Also due to custom skills it is important to keep track of each battler's turn. For example, if a condition or skill allows a battler to take multiple turns it is important that the switch/bool actionTaken, can be changed. That boolean array controls the values of bAGI, so it is easier to give battlers multiple turns in one round.

Functionally, you should end up at the same place, and performance should not be a concern since the number of battlers is so low that it should not make a meaningful performance problem.
Your method allocates 12 space for 12 battlers regardless of whether 12 battlers are used or not, while the approach I proposed only takes into account the active battlers. Also, your loop to determine the current battler pretty much defeats the purpose of using this data structure, so it looks pretty ugly as a programmer.
bAGI[i] == bTurn

I would have imagined that this would break as well, as it's not intuitive to me that applying a comparison to bTurn will return the value of the top element, you would need to adjust that to.
bAGI[i] == bTurn.top()

Unless you've tested it, and it works as intended. In that case, the documentation might just have been a bit lacking in defining how their comparison operators have been defined.
In the end though, you should go with what makes you comfortable, since it is your code in the end, and as long as it is working as intended, you shouldn't have to worry too much about what programmers tell you (unless you'd plan to go full professional or hobby programming, rather than just an occasional plugin).

author=McBick
The problem with your method is that I am unsure what you mean by bAGI must be a data structure with a size method. From my understanding, all arrays have a size, size being the number of bytes in the memory of the array?


All arrays have a size, but not a size method. The size method of e.g. std::vector<int> will return the number of elements in the array, not the number of bytes.
int speed[12] = {};

This array has no size method, so it could not have been used in the look I proposed. You can still get the size of this array, but now you have to use another function called "sizeof". In this could you would do
sizeof(speed) / 4;

Note that it is divided by 4 since each integer (with some exceptions which should not be relevant to you) will have 4 require 4 bytes. This is assuming you want to return the number of elements rather than the actual bytes used.
You can also use
sizeof(speed) / sizeof(int)

If you do not know the number of bytes used by the variable type in question. Trivial here of course, since your array is set to a static 12, meaning there is no need to query the size of it, as it is not dynamic, but for dynamic data structures, this would be more relevant, but these tend to have a size() method anyway.

Now, for your bigger code snippet
speed[i] = RPG::Actor::partyMember(i)->getAgility();

This probably returns the database agility not the agility for the battle. If you plan to have agility buffs and debuffs, you probably need to extract the agility from the Battler of the corresponding actor, not the actor from the database. At the very least, I would test this specifically. Same thing applies to monsters.

Apart from that. If it works as intended it should probably be fine. Again, no need to implement my proposal as long as it works. There are a number of inefficiencies with the code, but functionality comes before form and will serve good for learning as well. That, and if it already works, you'll probably break it before being able to fix it again if you start changing core parts of it, which could be a waste of time if you just want it to work.

author=McBick
On another note, I have a question about memory. How is memory allocated in general, specifically when declaring a variable during run time? For example:
void function() {
int v = 5;
}

Where would the memory value of "v" be stored and how would I locate that memory besides pointing to "v"? Also is there a way to convert a memory location into a pointer? For example, I want to store 0x28 in memory address XXXXXXX. Is it possible to convert that memory location into a pointer so I could do something like:
ptr = 0x28;

How would this be done?

Tackling your last question first:
Yes, it can be done, and no, you should probably not be doing this, at least not as proposed.
In your particular code example, the second the function "function" is called, it will allocate integer v to the stack for the execution of that function. Once it leaves that function, the memory of v is deallocated.
If you would do something along the lines of
int* foo(){
   int v = 5;
   return &v;
}

int* v_ptr = foo(); // You are no pointing to the memory of variable v
// But the value is not going to be 5 for very long, since the variable is already out of scope


Depending on what you want to achieve, there are a couple of ways to go about it. If you pass in pointers to your function, you can work directly on them and the values will persist after you leave the function (but what the pointer is pointing at can not have been declared in that function).
If you want to create a variable which persists in a function, you need to put it on the heap. You could do this with the new operator, which returns an address to that variable, but at that point, you need to return the pointer and keep track of it, since it will otherwise lead to a memory leak.

[RM2K3] DynRPG Compiling Error

author=McBick
The code for the first issue you mentioned is actually in the previous code I posted. Also if there aren't 12 battlers then the default value of 0 is used and ignores the nonexistent battler.

Without knowing where those snippets are relative to each other, it's hard to determine if they're doing the right thing or not. This goes back to the scope thing I mentioned, as a lot the time thing which seem irrelevant might be more relevant in the end.

author=McBick
I am unfamiliar with the use of std::priority_queue structure. Is something like this what you mean?
std::priority_queue<int> bTurn;
for(int n : {bAGI[0], bAGI[1]... BAGI[11]}
    bTurn.push(n);
for(int i=0; i<12; i++)
    if(bAGI[i] == bTurn)
        curBattler = i;
//Battlers are stored as Hero(0-3) and Monster(4-11)
//for the variables of bAGI[Battler Index] and curBattler

priority_queue is a data structure which automatically sorts itself every time you add an entry to it. By adding the agility for all battlers at once, these would all be sorted and can be accessed on at a time to handle their actions. The following snippet ought to give a rough idea as to how it could possibly be used.
std::priority_queue<int> queue;
for(int i = 0; i < bAGI.size(); i++){  // Note, this assume bAGI is a data structure with a size method
    int value = i  // Store the id of the battler in value
    value += 100 * bAGI[i]  // store the agi of the battler * 100 in the value. The multiplication avoids the agi from messing with the battler id
    queue.push(value)
}

... 

int temp = queue.top();  // retrieves the top element
int currentId = temp % 100;  // do this to retrieve the id of the battler
// Let current battler do an action
queue.pop();  // this removes the current top element, making the next one accessible
if(queue.empty()){
    // End of round, refill the queue to start a new round
}

This would allow for some nice and clean code easy to maintain, but it would also mean that any agility buffs or debuffs will be ignored during the execution of the current round (e.g. if the fastest battler gives the slowest battler an agility buff, the slowest battler will still be taking the last action of that round, with the buff first kicking in for the next round of actions).

author=McBick
As for my issue with the incorrect turn order, I think I have narrowed it down to the order of operations during battle. I think I have to change which callback the battle initiation takes place, this is what sets up the switches at the start of the battle for the turn order to be called and properly function. I think the issue is that the function getCurrentBattler is being called too early and due to the way the rm2k3 battle code is executed it messes up the synchronicity of my code.


That could very well be. I have no experience with modding the default battle system, so I do not know a whole lot about the underlying order of operations which take place there, but I imagine that this is not readily accessible for stuff like the damage calculation, which probably happens somewhere between onBattlerDoAction and onBattlerActionDone, with no good hook to mess with it.

[RM2K3] DynRPG Compiling Error

I see your code should figure out which battler has the highest agility, but I don't see any code which modifies the bAGI for the battler who just took a turn, meaning curBattler should always be the one with the highest agility.

Another problem I see is that you require 12 battlers to have taken their turns for the turns to reset, but there's no guarantee that there will be that many battlers (or that all of them are alive).

These might be adressed somewhere, but I don't see these things addressed in the code here. A side note as to how I would handle this instead, I would probably use a std::priority_queue structure to deal with the selection.
At the start of each round, I would take the battler agility, multiply it by 100 and then add the battler id. This way, the structure will sort on the agility and you can get the id by using "value % 100" (same like the mod operation in rm2k3), and after I get the current battler, I'd just pop the top element, and keep doing this until the queue is empty, at which point I would refill it again.