View Full Version : More Script Questions
03-15-2008, 01:16 PM
Is there a full list of the events that the game can fire off that I can listen for and act on.
I'm specifcally interested in being informed of when a building enters or leaves a disabled state, and am hoping it is something I could listen for as an event.
I can see that I can register an Event handler with
GameEventmanger.RegisterEvent(IDataID inEventID, IGameEventHandlerScript inEventHandler)
But the only events ids I can currently see are the ones in
Is that an exhaustive list?
As a follow up question, it looks like I can define custom states on sims, and use:
CS_UnitSim.SetStateFlag(TMill.SC5M.ISimStateFlagID inFlagID, bool inValue);
Not that I've tried it yet, but I assume it just hashes FlagIds to booleans internally, and that the ids are the ones in SimStateFlagNameTable.xml - so I could define extra sim states myself (I'm looking at trying setting education levels on sims and state flags look like a way I could do it).
But I cannot see any such property on buildings - so I assume I can't flag buildings as being in a particular state?
03-15-2008, 06:35 PM
One of the Special Maps Display buttons indicates which buildings are disabled when activated. A broken window icon floats over each disabled building.
Click on the building to find the duration of disabled condition.
03-15-2008, 07:28 PM
Its not how the UI shows it that I'm after - but how to deal with it in the code itself.
I can have the code ask the building if it is disabled, that is no great problem. That however, means I have to have some code running in order to ask it. So for example even though I know I have just set a building to be disabled for 24 hours, I need something that will know to call the isDisabled function in 24 hours time. An event mechanism would be perfect - the game engine firing an event notification only when the disabled flag changes, I would register an event listener to catch that event and react to it. That means I'm not chewing up CPU cycles constantly testing whether the building is disabled yet.
Since I posted that mail I found out how to achieve what I want even easier.
mBuilding.AddTargetedActionEvent(mBuilding.GetID() , mBuilding.GetClassID(), mDerelictAbilty, "",
(int)(Game.Instance().Time + (mDerelictDuration * DisplayTimeControl.GetMillisecondsPerHour())));
Tells the building to add an ability to it, and to automatically remove it after the set time. It only took me half the day finding that (Documentation!, Documentation!, Documenation!). So thats that problem over with at leaast, I now don't need to spot the change back to 'enabled' in order to switch of the ability, as it auto switches off now. :)
03-15-2008, 09:47 PM
A further question.
When a sim tries to go to work is when it appears he will also choose where he wants to work, if he doesn't already have a job :
if (workplace == null && !(mSim.Happiness < sEndHookyHappiness))
workplace = mSim.GetWorkplace();
Is there any way of hooking into the FindPlaceToWorkLogic so that I can introduce scripts that has employer/employee preferences? e.g. 1 script I would like to do is to have some workplaces only take on sims who have a good education level, which sims pick up by visiting education estabilshments.
03-16-2008, 05:41 AM
1 script I would like to do is to have some workplaces only take on sims who have a good education level, which sims pick up by visiting education estabilshments.
Problem 1: The first thing a sim appears do to when spawned is seek employment, before visiting any venues. Thereafter, the sim is rarely able to visit any education venues because they are closed after work. They can visit on weekends, but not if they have 7-day jobs. Otherwise, schools are only available to child sims and workers playing hooky, or those lucky workers with 3-day workweeks.
Problem 2: Sims have a high death rate (natural causes). By about 200 days into the game the death numbers may far exceed the number of worker sims that currently exist. Dead sims are immediately replaced by freshly spawned sims. This appears to prevent all sims from being locked into high happiness (new sims spawn as contented) and allows sims to change jobs (and possibly homes, though I cannot confirm this at this time). It also seems to be the only way to get rid of rogue sims held prisoner by secret police in a Corporate Hive or Corporate One - they die in custody and a new sim spawns at their former home. Combined with problem 1, I wonder if sims would live long enough to get much of an education.
Your workplaces requiring higher education levels may never have any employees.
There's nothing to see when a sim dies. It vanishes, and if you've tagged that particular sim, your tracking jumps to another sim. If everyone in your city is at high happiness levels, you will immediately observe the sudden existence of a contented worker.
03-16-2008, 07:11 AM
I wouldn't be trying to set up a system where you have to gain an eductaion over a long period of time as in the real world, I'm aware we are looking at a compressed timespan. I'm more looking to provide a mechanism that necessitates skilled labour for skilled jobs, and a reason (beyond energy/venue happiness etc) for schools and the like.
A single visit to a school could tag you as basic educated, a uni as degree educated. Even something that simple should make it beneficial to have schools near to where sims live. Workplaces could be tagged as needing None, basic or degree educated sims.
The sims looking for a job straight away isn't an issue if I can hook into the 'find place to work' logic, as I would be able to stop them finding work without the qualifications if that is all there is around. They would then have time to go find a school etc. That is of course the key element here - if I can't alter that logic somehow then I have a problem doing this (hence my question).
I would also likely allow the tagging of houses as spawning sims with a default education level (or a chance of each) if possible. So you could set up your slums to spawn zero/low eductated sims, and high classes houses to spawn degree level sims or however you think it should work.
I'm not sure any of this is a problem, Sims die early (between 30 and 60 days assuming the xml means what it seems to say), That is a compressed lifespan, hence a compressed education (possibly just a couple of days visting). If a dead sim is immedately replaced then that is fine, as there is a continuing need for education for new sims. The happiness of the sims is not a factor I'm overly bothered about for this possible mod. That fact that I don't see anything when a sim dies isn't an issue here, what would I want to see? I'd be surprised if my tag suddenly jumped to another new sim, it's possible, but I would expect the new sim to either be 'new' or if it was re-using the old instance for it to be re-intialised to clear out any old state.
Non of this may be possible - I am still working out what I can or cannot do in the code itself. I'm not trying to provide a real world simulation, but something that in a somewhat stereotypical way approximates real life.
I'm from the old style sim city group, but I'm not slating the game at all, in fact I like to see it as something that may well be better - as it may well allow me to define my own logic as to how the various elements hang together, I can define my own logic for how businesses cope with out a workforce, or how education becomes something you want as it provides the high tech industries with workers etc.
The beauty of doing this via modding is that no one would be forced to have such a mod if they didn't want to play with such features. Or they could further mod it to play in the way they think it ought to work.
I have several other ideas floating around, which when they are all acting together should hopefully provide a lot more interplay between the various elememts that make up a city, with consequences to having to many people and not enough jobs, and vice versa, or to much high tech industry in a place with little educated workforce.
03-16-2008, 04:37 PM
It would appear that they used the American model for educational institutions: baby-sitting and entertainment venues.
American education institutions provide daily warehousing of spoiled brats and serve as organizing centers for sporting events and social gatherings. Any actual education that occurs is purely accidental.
The only way I can get a college graduate away from my front door is to pay for the pizza. I usually tell them to keep the change because they'll never be able to count it out anyway.
The game is actually more realistic than what people believe about the real world.
03-17-2008, 06:50 AM
To get back to my initial point, if any Devs can enlighten me :
1) Is there a way of setting state flags on buildings like there appears to be for Sims?
2) Is there a way of hooking into the exiting sim.findPlaceTowork logic, or the findVenue logic?
With the last question I could presumably just change the TGoal.... classes to not call the existing methods on the sims and put in my own logic there, that however, is way more than I'm wanting to do , and I may end up missing all sorts of useful logic that is part of the existing stuff. What I'm hoping for is someplace that determines whether a building is a potential candidate in the first place. e.g. as it goes round a list of possible workplaces is there somewhere that gets called to ask whether it is possible to place to work that I can add in some extra logic. The same with Venues.
I could probably let the sim go there and then 'bounce' them, but I would rather they realised there is no point even trying in the first place.
3) Getting a bit ahead of myself - but is the UI amenable to any changes (ie could I add sliders/checkboxes or whatever to some part of the UI that allows dynamic changing of modded properties (I'm thinking of the possibility of a tax changing mod, so you set the tax rate in game).
4) I tried to add in a PolledEvent to the GameEventManager thing (can't quite remember the class name now, but it is a source file in the .cs folder), but it didn't work - in fact there was no instance of the manager to add events to, (getInstance() returned null), and 'new'ing one doesn't help as nothing will call the methods to process per hour or day or tick. What is this for if nothing ever uses it, or is there something I can register the instance with that will notify it of the appropiate time intervals going by?
03-17-2008, 09:05 AM
Buildings can't use sim StateFlag system but you can use ModifyBuildingAttribute and GetBuildingAttributeModifier. It stores an integer but you can use 0/1 for booleans.
You can also associate a sim with a building (or any unit with any other) using your own DataID via AddClient, RemoveClient, GetIsUnitClient, GetClientVector. Use this sparingly though. Associating every unit with every other would be bad for memory and performance.
There's not a script hook inside FindPlaceToWork. There are good ways of controlling which venues sims visit from script though. The easiest would probably be the Categories folder and the Visits attribute in the Figures xml folder.
I'm not sure what the best way is to accomplish your goal. Perhaps you could add a category of venues that function like alternate workplaces.
03-17-2008, 11:33 AM
Thanks - I'll have a look at those tonight.
PS any response on the UI or event questions?
vBulletin® v3.7.2, Copyright ©2000-2013, Jelsoft Enterprises Ltd.