I literally had no experience in c or c++ programming when i popped open this DevCD. I mainly program in php, javascript and the languages below those.
Seemingly simple things like, counting an array, or outputting a variable along beside text became strangely difficult.
The hardest part so far was allowing the world generator to count the amount of hardware upgrades, rather than relying on "NUM_STARTINGHARDWAREUPGRADES".
So creating this piece of code is a benefit for really one reason.
When I add new hardware to data.cpp, I have no need to increment the variable NUM_STARTINGHARDWAREUPGRADES located in data.h. The main reason being, a change made in data.h requires a compile of the entire game, while changes in data.cpp only link in the data.cpp file and finishes up.
In a language like PHP it is as easy as "$c=count(array);" with a likely offset of -1. I tried so many different ways from guides on the internet, although these instructions work on regular programs, just would not work in Uplink.
I finally "settled" on a while loop to count the items and increment a variable which gives off a higher offset than PHP would, but at least it remained constant.
EDIT: [So after some more modifications I realized this code, kinda doesn't work when you add new software. I have updated the code below. It now takes into account the software and hardware upgrade variables. I am sure this can be optimized to look and run better, but I am not that experienced yet.]
Code:
int SW_Count=0;
int HW_Count=0;
int softwareCount=0;
int hardwareCount=0;
char *assignName="fuckmylife";
char *assignName2="fuckmylife";
while (assignName != '\0'){
assignName = SOFTWARE_UPGRADES[SW_Count].name;
SW_Count++;
}
while (assignName2 != '\0'){
assignName2 = HARDWARE_UPGRADES[HW_Count].name;
HW_Count++;
}
softwareCount=(SW_Count - HW_Count);
hardwareCount=(SW_Count - softwareCount)-29;
You would then assign the variables like so:
Code:
// for ( int is = 0; is < NUM_STARTINGSOFTWAREUPGRADES; ++is ) {
for ( int is = 0; is < softwareCount; ++is ) {
Code:
// for ( int ih = 0; ih < NUM_STARTINGHARDWAREUPGRADES; ++ih ) {
for ( int ih = 0; ih < hardwareCount; ++ih ) {
So essentially, this just runs through the name of each hardware unit and whenever its valid it increments. This left me with a high offset of 29 though.
I thought I would share this in case anyone else wants to do the same thing, or maybe has some insight why my offset is so high. I tested by throwing in some extra hardware, different things, the offset remained the same.
Cool forum btw.