Last visit was: It is currently Thu Dec 05, 2024 11:49 am


All times are UTC-05:00




Post new topic Reply to topic  [2 posts ] 
    Author Message
     Post subject:Improving Uplink
    PostPosted:Thu Oct 17, 2013 6:35 pm 
     

    Joined:Tue Oct 15, 2013 11:09 pm
    Posts:18
    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.


    Last edited by someguy on Sat Oct 19, 2013 6:46 am, edited 1 time in total.

    Top
    Offline  
     Post subject:Re: Improving Uplink
    PostPosted:Sat Oct 19, 2013 6:46 am 
     

    Joined:Tue Oct 15, 2013 11:09 pm
    Posts:18
    Update original post. My apologies for the previous code if this was copied by anyone.


    Top
    Offline  
    Display posts from previous: Sort by 
    Post new topic Reply to topic

      All times are UTC-05:00


      Who is online

      Users browsing this forum: No registered users and 2 guests


      You cannot post new topics in this forum
      You cannot reply to topics in this forum
      You cannot edit your posts in this forum
      You cannot delete your posts in this forum
      You cannot post attachments in this forum

      Search for:
      Jump to:  
      cron
      Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
      Theme created by Miah with assistance from hyprnova