trystero49
Prince
- Joined
- Apr 30, 2012
- Messages
- 515
Edit: Because my question got moved to a separate thread, I'd like to point out that these questions are made in reaction to this post:
OK, this thread has a lot of useful information but it is a little arcane for someone who doesn't know programming very well. So I'm going to ask some questions and hopefully someone can answer?
So, m_pCityBuildings is some kind of pointer, and then -> is the deference operator. But I don't understand what m_pCityBuildings is pointing to. Presumably some kind of array?
instead? Why is it necessary to have the pointer and deference? The same goes for the pointer and derefence to SetNumRealBuilding. Does m_pCityBuildings point to an array of functions? I guess it would help if I knew what m_p stood for.
I have questions about the actual defined event too, but I'll ask them after this question so the thread doesn't get bogged down in a bunch of parallel questions.
Spoiler :Adding this code to the CvCity.cpp file inside of CvCity::CreateBuilding(BuildingTypes eBuildingType) function after the line:
fires an event each time a building is created. I'm not sure if there are any edge cases I missed - I don't know what will happen if you grant the building through lua, say - but it should fire on at least purchasing and production.Code:m_pCityBuildings->SetNumRealBuilding(eBuildingType, m_pCityBuildings->GetNumRealBuilding(eBuildingType) + 1);
The parameters are: City X coordinate, City Y coordinate, Building ID, Player ID, City ID.
Code:// STRABO - Adding new GameEvent: StraboOnBuildingCreated ICvEngineScriptSystem1* pkScriptSystem = gDLL->GetScriptSystem(); if(pkScriptSystem) { CvLuaArgsHandle args; args->Push(this->getX()); args->Push(this->getY()); args->Push(eBuildingType); args->Push(kPlayer.GetID()); args->Push(GetID()); bool bResult; LuaSupport::CallHook(pkScriptSystem, "StraboOnBuildingCreated", args.get(), bResult); }
I tested with the following lua code:
Code:function OnBuildingCreated(Xcoord, Ycoord, buildingID, ownerID, cityID) print("OnBuildingCreated"); local pPlayer = Players[ ownerID ]; print("Player: " .. Locale.ConvertTextKey(pPlayer:GetCivilizationShortDescriptionKey())); local pBuilding = GameInfo.Buildings[ buildingID ]; print("Building: " .. Locale.ConvertTextKey(GameInfo.Buildings[ buildingID ].Description)); local pCity = pPlayer:GetCityByID( cityID ); print("City: " .. pCity:GetName() ); end GameEvents.StraboOnBuildingCreated.Add(OnBuildingCreated)
I did not test the X,Y coordinates yet, so I don't know for sure that they're working, but I at least know that all the other parameters work and that the building fires appropriately.
OK, this thread has a lot of useful information but it is a little arcane for someone who doesn't know programming very well. So I'm going to ask some questions and hopefully someone can answer?
Code:
m_pCityBuildings->SetNumRealBuilding(eBuildingType, m_pCityBuildings->GetNumRealBuilding(eBuildingType) + 1);
So, m_pCityBuildings is some kind of pointer, and then -> is the deference operator. But I don't understand what m_pCityBuildings is pointing to. Presumably some kind of array?
Code:
SetNumRealBuilding(eBuildingType, m_pCityBuildings->GetNumRealBuilding(eBuildingType) + 1)[Code]
This part is what sets the number of buildings in the city of a specific building type to however many there were before plus one more. But why not do
[Code]SetNumRealBuilding(eBuildingType, GetNumRealBuilding(eBuildingType) + 1)
instead? Why is it necessary to have the pointer and deference? The same goes for the pointer and derefence to SetNumRealBuilding. Does m_pCityBuildings point to an array of functions? I guess it would help if I knew what m_p stood for.
I have questions about the actual defined event too, but I'll ask them after this question so the thread doesn't get bogged down in a bunch of parallel questions.