Jump to content

  • Log In with Google      Sign In   
  • Create Account

thade

Member Since 16 Oct 2000
Offline Last Active Apr 24 2013 08:25 AM
-----

Topics I've Started

Odd usage of friend keyword in C++ class.

27 February 2013 - 02:19 PM

It's my esteemed privilege to try and repair some old legacy code (or at least gather enough evidence to convince the powers at be to let my team rewrite it)...in digging through this code (which is devoid of comments) I've come across something that seems a bit weird. Here's a paraphrasing of the declaration:

 

class foo
{
public:
  class event;
 
private:
  class request
  {
    friend class event;
    public:
      doStuff();
    private:
      LOTS OF INTERNAL METHODS  
  }
 
  class response
  {
    friend class event;
    public:
      doStuff();
    private:
      LOTS OF INTERNAL METHODS  
  }
}

 

Now, I've seen nested class definitions before, and I've seen the friend keyword in use before, but I've never seen the friend keyword used like this. There are several other classes with this very structure, unspecified class 'event' friended to 'response' and 'request' and others. Is the goal to instantiate foo1, foo2, etc. then iterate over unspecified object pointers, controlling them through this 'event interface'?

 

Maybe it's a design paradigm one of you has seen in the past (and not just something this programmer made up) so I thought I'd ask. What could be gained from this? (Other than some obfuscation, which isn't out of the question.) Naturally it's hard (maybe impossible) to determine what the point is without the code base (which I can't share directly). However, these classes aren't instantiated in the code I have because it's a library, and while I technically know what the library accomplishes, I'm now at a loss as to how I might wield it.

 

Oh, I found a comment. It says "// TODO: FIX". It's the only one. I lol'd.

 

So, possibly you've seen this or have a sharper imagination than I. In any case, thanks in advance for your time. :)


Carrying capacity (primarily for RPGs)

18 January 2013 - 07:07 PM

I'd like to talk about the purpose of weight capacity in a game, beyond just the simple reduction to "it's more realistic." Some games give you all of the numbers: weight of each object, how much you can carry, and how much you're currently carrying. Some games (modern FPSs mostly) restrict purely the number of items you can carry regardless of how much they might 'weigh'. Still, other games eschew this entirely (e.g. many JRPGs) and allow you to carry 99 Tents and 99 Cabins and 99 Great Big Swords as well as whatever else.

 

I find myself wondering what in-game functions are supported by restricting how much a character can carry.

 

The less you can carry, the less you can bring home to sell from a long haul. Diablo is well known for this (though really it just forces repeated laps to and from town) but even a game like Fallout sees the same restriction (and the lack of teleportation/quick travel makes the limitation even more tangible). This puts a cap on the amount of resources a player can gain from an expedition, as it were; you may need to make choices on what to bring to town to sell and what to leave behind, perhaps not knowing which is more valuable.

 

Carrying capacity also restricts your flexibility; this is its primary use case in modern FPSs (which allow you typically a primary weapon, a sidearm, and some kind of utility item) but it comes up in other games as well; while it might be nice to have two kinds of rocket launchers, a grenade launcher, a flame thrower, two kinds of chainguns, and several rifles - something for every occasion - you just can't carry them all. This very often meshes with the previous effect: you now need to budget carrying capacity between:

  • your ability to address different situations with the ideal weapon;
  • and your ability to carry more junk to sell for money.

Fallout 3 (and New Vegas unless you kicked in Hardcore mode) ignored the weight of ammunition and 'chems' (stimpacks for healing and other things that granted buffs) but its predecessors did not; stim packs were light (and expensive), but first aid kits and doctor bags were heavy, adding your ability to address character injury to the 'what do I carry' budgeting.

 

Items are resources (either they serve an intrinsic function or they can be sold for currency or maybe broken down and used to build things that serve one of those two purposes) which ultimately assist the player accomplish tasks; restricting how many you can have puts a limit on your resources. Additionally, it does add a touch of realism to the game. ;)

 

Does it have any other effect that I'm missing? What do you think?


PARTNERS