04 Aug, 2009, David Haley wrote in the 41st comment:
Votes: 0
Since we're being gripe monkeys… :tongue:
Sequence reversal is actually a definition of inversion:
dictionary.com said:
2. to reverse in position, order, direction, or relationship.
04 Aug, 2009, JohnnyStarr wrote in the 42nd comment:
Votes: 0
@chris,

I think it's cool that you want to offer suggestions. Whether they are the best
way to do things or not, doesn't mean that you shouldn't try. I'm sure that some of
my upcoming contributions might not be *perfect*, but its a practical application
of the code that I am learning. And you won't know why something is buggy or crappy if you dont have someone else to test it and point it out. :smirk:
04 Aug, 2009, Chris Bailey wrote in the 43rd comment:
Votes: 0
Well, what I can say at least is that it works admirably in every scenario I have tried it in. I just want people to be aware that I could make a much better version of the same thing in Ruby, the problem for me is trying to write something that can be easily ported to C++. Thanks for the comments though Stary =)
04 Aug, 2009, JohnnyStarr wrote in the 44th comment:
Votes: 0
I can't imagine that being an easy thing. C / C++ are so different from
Ruby that it would be like trying to play a DVD in a VCR, it just wouldn't
work. Ruby has a ton of cool built in features and is so high level in comparison
to C that i wouldn't even know where to start. Tyche's RocketMud is an example of
C -> Ruby, but IMO it wouldn't work the other way. (at least not in a way that would be useful)
04 Aug, 2009, Chris Bailey wrote in the 45th comment:
Votes: 0
Yeah, that's the problem I ran into. Plus I don't know C/C++ so I couldn't figure out how to even pretend like it would be portable. But things like writing a method to reverse the string? It already exists in ruby, you just do "string".reverse, simple as that. I tried writing out some of the built in functionality so that people could at least look at it, understand what is going on and then port it.

EDIT - The idea behind reversing the string and reversing the color codes intelligently is simple though. You just need to extract the color and remember where in the string it was located, reverse the string, and then insert the color codes back into the string in the same location. That's it. :P
04 Aug, 2009, David Haley wrote in the 46th comment:
Votes: 0
Guys, it's not as hard as you might think to write a simple string inverter in C++ instead of Ruby… :wink: You just need to write the various library functions that are immediately at your disposal in Ruby to begin with. Unless you're using particularly advanced or C-unfriendly Ruby concepts (like generators or whatever you call them… blocks?), it's a sometimes tedious but not really difficult process.
04 Aug, 2009, Guest wrote in the 47th comment:
Votes: 0
Heh, call me crazy, but didn't I already post a C++ string inverter a few clicks back? :P Or are we talking about more than just reversing the text?
04 Aug, 2009, David Haley wrote in the 48th comment:
Votes: 0
Yes, Chris's deals with color codes.
04 Aug, 2009, JohnnyStarr wrote in the 49th comment:
Votes: 0
I'm really eager to learn C++ so that I can use all that cool stuff.
The hard part for me is learning the STL. Ruby is so easy to learn because its
built to just work. With C / C++ you are writing machine code, so there's always a
curve ball it seems when picking things up. Ruby just seems to work. I guess thats the benefit of being interpreted / dynamically typed.

Call me weird, but I am more intrigued by the harder route. Mainly because I've been
putting off learning it for years. Ok, this post was almost pointless. :biggrin:
04 Aug, 2009, Kline wrote in the 50th comment:
Votes: 0
STL has been the easiest thing for me so far, and saved me a lot of work. Take the following STL to get a random item from a list (vector). So much simpler than some of the "roll your own" for( … ) loops I've found scattered about my code so far.
random_shuffle(list.begin(),list.end()
item = list.begin()
04 Aug, 2009, David Haley wrote in the 51st comment:
Votes: 0
Learning the "hard stuff" is often not that useless, actually, because it gives you a better understanding of what's actually going on, and appreciation for what a language is doing for you.

Of course, you don't have to completely understand all the details, but understanding the idea is important. For example, while I think knowing something about machine architecture is useful if you are writing performance-sensitive code, I don't think you need to know x86 assembly inside out, but I do think it's helpful to know the general principles of assembly programming, and maybe have had exposure to a far simpler assembly language such as MIPS.
05 Aug, 2009, JohnnyStarr wrote in the 52nd comment:
Votes: 0
David Haley said:
Learning the "hard stuff" is often not that useless

Who said they thought it was worthless? Or were you just saying in general?
05 Aug, 2009, David Haley wrote in the 53rd comment:
Votes: 0
Well, it was a general comment, also prompted by you saying it was weird to like to learn the complicated stuff. But several people also think it's worthless to know about implementation when working in a high-level language.
05 Aug, 2009, flumpy wrote in the 54th comment:
Votes: 0
David Haley said:
Since we're being gripe monkeys… :tongue:
Sequence reversal is actually a definition of inversion:
dictionary.com said:
2. to reverse in position, order, direction, or relationship.


That's why I said "tends to imply"…:D
05 Aug, 2009, boblinski wrote in the 55th comment:
Votes: 0
Alright.. well rather then jumping straight in and trying to add it in the code for the spell affect right away.. I've decided to try and get my head around this first..

This is what I have:
char *reverse_txt(char *text, int length)
{
int i;
char rev_buf[MAX_STRING_LENGTH];

for(i = 0; i < length; i++)
{
int pos= length - i - 1;

if (text[pos] == '{' && i > 0 && pos < length-1)
{
rev_buf[i=1] = text[pos];
rev_buf[i] = text[pos+1];
}
else
rev_buf[i] = text[pos];
}

rev_buf[length] = '\0';

return rev_buf;
}

void do_reverse(CHAR_DATA *ch, char *argument)
{
char buf[MAX_STRING_LENGTH];

sprintf(buf, "%s\r\n", reverse_txt(argument, strlen(argument)));
send_to_char(buf, ch);
return;
}


This is the warning:
Quote
gcc -Wall -O -ggdb -DNOCRYPT -DQMFIXES -c -o obj/comm.o comm.c
comm.c: In function `reverse_txt':
comm.c:2868: warning: function returns address of local variable
rm -f rom


It seems to work when I try things without color.. but when I try using color.. my mud freezes completely.
05 Aug, 2009, Davion wrote in the 56th comment:
Votes: 0
This is why when we wrote it, it passed the variable it was setting, but! You can put a fix in, and change

char rev_buf[MAX_STRING_LENGTH];


To a static variable

static char rev_buf[MAX_STRING_LENGTH];


But don't try to use it twice in the same statement. Eg.

sprintf(buf, "%s, %s", reverse_txt(str, strlen(str) ), reverse_txt(otr),  strlen(otr) );

Because it wont work ;).


EDIT: You also have a syntax error!
rev_buf[i=1] = text[pos];

Should be
rev_buf[i-1] = text[pos];
05 Aug, 2009, boblinski wrote in the 57th comment:
Votes: 0
Thanks for that! My little reverse function is working perfectly!

I am wondering whether maybe I could simply add my IS_AFFECTED check into write_to_buffer():

void write_to_buffer (DESCRIPTOR_DATA * d, const char *txt, int length)
{
if (length <= 0)
length = strlen (txt);

if (d->outtop == 0 && !d->fcommand)
{
d->outbuf[0] = '\n';
d->outbuf[1] = '\r';
d->outtop = 2;
}

while (d->outtop + length >= d->outsize)
{
char *outbuf;

if (d->outsize >= 32000)
{
bug ("Buffer overflow. Closing.\n\r", 0);
close_socket (d);
return;
}
outbuf = alloc_mem (2 * d->outsize);
strncpy (outbuf, d->outbuf, d->outtop);
free_mem (d->outbuf, d->outsize);
d->outbuf = outbuf;
d->outsize *= 2;
}

strncpy (d->outbuf + d->outtop, txt, length);
d->outtop += length;
return;
}


Would it be too much to ask your opinions of adding my reverse code here? Also maybe a quick explanation as to how this write_to_buffer() works!?

Thanks,
Bob.
13 Aug, 2009, Davion wrote in the 58th comment:
Votes: 0
I wouldn't put it in write to buffer because I think colour is processed before this happens. Stick to plugging it into send_to_char, atleast that way you always have a character to ping, write_to_buffer could be called prior to having a player.

write_to_buffer works just like the name. It writes to a buffer. Every loop through the game_loop() does three things, checks for new connections, processes output, and processes input. When output is processed, it empties the buffer (in this case, d->outbuf) and sends it off to the descriptor.
14 Aug, 2009, boblinski wrote in the 59th comment:
Votes: 0
WAS:
Quote
<29859hp 5643m 6198mv> look

Center Arena
You stand with a small arena. This place has
a divine feeling, as if touched by the gods
themselves. A fine death you shall have.

[Exits: north east south west]
A shotgun with a sawn off barrel lies on the ground here.
Bob is here.
(White Aura) Mr testifa stands here looking about the arena L

<29859hp 5643m 6198mv>




BECOMES:
Quote
<29851hp 5643m 6198mv> look

anerA retneC

.evah llahs uoy htaed enif A .sevlesmeht
sdog eht yb dehcuot fi sa ,gnileef enivid a
sah ecalp sihT .anera llams a htiw dnats uoY

]tsew htuos tsae htron :stixE[ A shotgun with a sawn off barrel lies on the ground here.

.ereh si boB
L anera eht tuoba gnikool ereh sdnats afitset rM )aruA etihW(
<29851hp 5643m 6198mv> [/quote]




[b]SHOULD BE:[/b]
[quote]>vm8916 m3465 ph15892< look

anerA retneC
.evah llahs uoy htaed enif A .sevlesmeht
sdog eht yb dehcuot fi sa ,gnileef enivid a
sah ecalp sihT .anera llams a htiw dnats uoY

]tsew htuos tsae htron :stixEtsew htuos tsae htron :stixE[ .ereh dnuorg eht no seil lerreb ffo nwas htiw nugtohs A
.ereh si boB
L anera eht tuoba gnikool ereh sdnats afitset rM )aruA etihW(

>vm8916 m3465 ph15892<[/quote]


This is my [b]reverse_txt[/b] :
[code]char *reverse_txt(char *text, int length)
{
int i;
static char rev_buf[MAX_STRING_LENGTH];

for(i = 0; i < length; i++)
{
int pos= length - i - 1;

if (text[pos] == '{' && i > 0 && pos < length-1)
{
rev_buf[i-1] = text[pos];
rev_buf[i] = text[pos+1];
}
else
rev_buf[i] = text[pos];
}

rev_buf[length] = '\0';

return rev_buf;
}[/code]

This is my [b]send_to_char[/b] :
[code]void send_to_char (const char *txt, CHAR_DATA * ch)
{
const char *point;
char *point2;
char buf[MAX_STRING_LENGTH * 4];
int skip = 0;


//PERPLEX STUFF:
if (IS_AFFECTED2(ch, AFF_LOOKING_GLASS))
{
txt = reverse_txt((char*)txt, strlen(txt));
}


buf[0] = '\0';
point2 = buf;
if (txt && ch->desc)
{
if (IS_SET (ch->act, PLR_COLOUR))
{
for (point = txt; *point; point++)
{
if (*point == '{')
{
point++;
skip = colour (*point, ch, point2);
while (skip– > 0)
++point2;
continue;
}
*point2 = *point;
*++point2 = '\0';
}
*point2 = '\0';
write_to_buffer (ch->desc, buf, point2 - buf);
}
else
{
for (point = txt; *point; point++)
{
if (*point == '{')
{
point++;
continue;
}
*point2 = *point;
*++point2 = '\0';
}
*point2 = '\0';
write_to_buffer (ch->desc, buf, point2 - buf);
}
}
return;
}[/code]

It's messing up with the spacings at the end of lines I think.. my score sheet looks even more horrible.

Color seems to be reversing great though.. And not sure why it's not reversing the Items..

Any advice?
14 Aug, 2009, Hades_Kane wrote in the 60th comment:
Votes: 0
I noticed my brackets and parentheses were not properly being reversed as well (look at it again, it seems to be doing that more on brackets regardless of where in the text they are), but didn't really know how to fix that :p

Also keep in mind that aside from send_to_char (as Davion suggested), ROM also sends text to characters through the act, write_to_buffer, send_to_desc, page_to_char, and printf_to_char functions… so those may be some things to keep in mind depending on how exactly and where exactly you stick this.
40.0/89