Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

/prog/ - RPG

Name: Anonymous 2010-10-29 15:44

Lets program a roleplaying game together. Each post must contain either a new function or an edited version of an old function in psudocode. I will start:

int dealDamage(int hp, int damage){
    return hp - damage;
}

Name: Anonymous 2010-10-30 0:52

THE floor() IS LAVA!

Name: Anonymous 2010-10-30 1:48

>>40
That will fail whenever damage >= hp (technically, damage >= hp - 0.5 and hp <= 0.5, but we're using integers).

Name: Anonymous 2010-10-30 7:42

int attack(struct character *target, struct character *attacker) {
    int damage = calculateDamage(target->armor, attacker->weapon);
    target->hp = dealDamage(target->hp, damage);
    return damage;
}

Name: Anonymous 2010-10-30 7:54

>>43
Every attack hits, then? Also, what about the skill, strength, and speed of the attacker and target?

Name: Anonymous 2010-10-30 9:20

>>44

int hit(struct character *target, struct character *attacker, struct weapon *weapon) {
   return attacker->accuracy * weapon->accuracy_factor > target->evasiveness;
}

enum effect attack(struct character *target, struct character *attacker) {
    if (hit(target, attacker, attacker->current_weapon)) {
        int damage = calculateDamage(target->armor, attacker->weapon);
        target->hp = dealDamage(target->hp, damage);
        return E_DAMAGE_INFLICTED;
    } else {
        return E_COUNTER_ATTACK;
    }
}

Name: Anonymous 2010-10-30 9:28

>>45
int hit(struct character *target, struct character *attacker, struct weapon *weapon, int die) {
   return die * attacker->accuracy * weapon->accuracy_factor > target->evasiveness;
}
enum effect attack(struct character *target, struct character *attacker) {
    struct weapon *w = attacker->current_weapon;
    if (hit(target, attacker, weapon, throw_dice(w->n_dice, w->die_sides)) {
        int damage = calculateDamage(target->armor, weapon);
        target->hp = dealDamage(target->hp, damage);
        return E_DAMAGE_INFLICTED;
    } else {
        return E_COUNTER_ATTACK;
    }
}

Name: Anonymous 2010-10-30 13:47

>>46
Your parentheses are unbalanced, and you can't decide whether your weapon variable is weapon or w.

I would also remove int damage and inline its value since it's only used once, but that's sort of a stylistic thing.

Name: Anonymous 2010-10-30 14:27

>>47
Don't forget:
int hit(struct character *target, struct character *attacker, int die) {
   return die * attacker->accuracy * attacker->weapon->accuracy_factor > target->evasiveness;
}

Name: Anonymous 2010-10-30 15:22

>>48
Well, that could conceivably be updated later to handle much more complicated cases, and inlining it would become unwieldy.

Name: Anonymous 2010-10-30 16:05

>>49
I'm not sure the attacker would ever use anything other than his current_weapon.

Name: Anonymous 2010-10-30 17:37

>>50
What about his secondary weapon? You can equip two weapons simultaneously.

Name: Anonymous 2010-10-30 17:41

••

Name: Anonymous 2010-10-30 17:55

>>51
Then his secondary weapon becomes his current weapon.

Name: Anonymous 2010-10-30 18:31

void hax(Anus* a)
{
    a->haxed = true;
}

Name: Anonymous 2010-10-30 19:08

void Anus::hax() {
  this->haxed = true;
}

Name: Anonymous 2010-10-30 20:02

>>53
No, in that case both weapons would be current. You'd have to tell the function which weapon you really mean to use, unless you suggest swapping pointers around all the time so that whichever was used last is "current" (and then handling the resulting cumbersome necessity of identifying in some other wholly contrived way of which weapon is considered primary and which is secondary).

Name: Anonymous 2010-10-30 20:22

>>56
or you make it ENTERPRISE and do:

Weapon *weapon;
// 0 = single weapon, 1 dual, attack with first, 2 dual, attack with second
// it's ugly but I need to deliver the code by tomorrow, or else the boss will kill me.
if(attacker->dual_wield != 0) {
    weapon = (attacker->dual_wield == 1) ? attacker->first_weapon : attacker->second_weapon;
} else {
    weapon = attacker->weapon;
}
// Now your active weapon is ``weapon''! please be careful with it.

Name: Anonymous 2010-10-30 20:33

>>57
That would constitute "swapping pointers".

Name: Anonymous 2010-10-30 20:39

Name: Anonymous 2010-10-30 21:45

>>59
Identifiers that begin with an underscore are reserved in the tag name space at file scope, so you should rename your struct tags, or just remove them since you're using typedefs anyway. Your vector functions are passing structs by value but it looks like you wanted to pass pointers. You should rename "norm" to "normal" because "norm" means "length" for vectors.

Name: Anonymous 2010-10-30 22:42

Final Fantasy I (NES) code:


short do_damage(btl_stat_t *attacker,
                btl_stat_t *defender,
                atk_t atk_type)
{
    if (defender->hp == 0)
    {
        /*
         * TODO: don't attack enemy if already dead
         * -- Nasir
         */
        return 0;
    }
    short dmg = attacker->atk_stat[atk_type] * rand(&LL)
                - defender->def_stat[atk_type];
    return dmg > 0 ? dmg : 0;
}

Name: Anonymous 2010-10-30 22:53

>>61
Final Fantasy X (PS2) code:


#include "MainCharacter.h"
#include "WaveFile.h"
#include "linear_story.h"
#include "men_who_look_like_faggots.h"

//#define TEXT_TO_SPEECH
//#include "TextToSpeech.h"

WaveFile MainCharacter::SoundClip()
{
    //if (name == "Tidus") {
    //    return WaveFile("tidus.wav");
    //}
    //#ifdef TEXT_TO_SPEECH
    //   return WaveFile( TextToSpeech::ToWav(name) );
    //#else
       return WaveFile("Our newest team member.wav");
    //#endif
}

Name: Anonymous 2010-10-30 23:34

>>2
int dealDamage(int hp, int damage){
    return max(0, hp - damage);
}

Name: Anonymous 2010-10-31 0:15

What's wrong with negative hit points or non-positive damage?

int dealDamage(int hp, int damage) {
    if (damage < 0)
        assert(hp <= INT_MAX + damage);
    else
        assert(hp >= INT_MIN + damage);
    return hp - damage;
}

Name: Anonymous 2010-10-31 1:04

>>64
non-positive damage would heal the object being attacked

Name: Anonymous 2010-10-31 1:23

>>65
No, only negative damage would.

Name: Anonymous 2010-10-31 1:34

negative == non-positive
if you don't know that already

Name: Anonymous 2010-10-31 1:37

>>65
Don't you want to be able to attack your allies with your Sword of Healing?

Name: Anonymous 2010-10-31 1:44

>>67
1/10

Name: Anonymous 2010-10-31 2:26

>>69
Oh come on, it's gotta be worth more than that!

Name: Anonymous 2010-10-31 3:01

>>70
The price of obtuseness has decreased.

Name: Anonymous 2010-10-31 3:02


if(++hitcount > 50)
  chicken_swarm();

Name: Anonymous 2010-10-31 3:06

struct Player
{
  String name;
  int hp;
  int mp;
  Class class;
}

Name: Anonymous 2010-10-31 3:08

>>73
Oh fuck class is a reserved keyword.

Name: Anonymous 2010-10-31 3:13

>>74
Not in C.

Name: Anonymous 2010-10-31 4:16

>>75
It is in C/C++.

Name: Anonymous 2010-10-31 4:35

>>76
That doesn't mean anything.

Name: Anonymous 2010-10-31 4:40

>>76
0/10

Name: Anonymous 2010-10-31 4:59

>>73
Prefer structtag var; to typedefs (tag_t var;, or Class and String), since if it is a struct, make it look like a struct. Typedefs make code confusing and pollutes the namespace, while struct tags have their own namespace. Only typedef if it is compilation target dependent, and often not even then. It is allowed, though, to typedef function pointer, if you must.

If you use a struct very often in a file, then you can typedef it locally within that file and give it a locally relevant name.

PS. Don't use a C++ compiler to compile C. It will rape your brain.

Name: Anonymous 2010-10-31 8:56

>>79
"It is allowed" to do whatever the fuck compiles. You can take your little style rules and sodomize yourself with them.

This is C we're talking about, it's a very rough language. Rough like the sex I had with your mother. No one is painting the fucking Sistine Chapel with it, we're using it to get shit done.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List