DysoForums Forum Index DysoForums
 
GalleryGallery   Donate to DysotopiaDonate   Dysotopia.com homepageDyso.com
SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   StatisticsStats   RegisterRegister 
 Login to check your private messagesLogin to check your private messages   LoginLogin 

Include files

 
Post new topic   Reply to topic    DysoForums Forum Index -> Worldbuilders
View previous topic :: View next topic :: Hide signatures  
Author Message
Little Teapot
Deity


Joined: 11 Sep 2002
Posts: 2332

Level: 39
XP
EXP: 31 / 160 EXP: 31 / 160 EXP: 31 / 160
 19%
PostPosted: Sat Oct 25, 2003 4:34 pm    Post subject: Include files Reply with quote

I feel like pumping up this forum's traffic, so here's an include file for extracting words for strings.

due to me not being able to test it (I hate this computer) I don't know if it works. here's the code though:

Code:
//void main(){}
//::///////////////////////////////////////////////
//:: Name WordString include file
//:: FileName inc_word
//:: Copyright (c) 2001 Bioware Corp.
//:: Copyright (c) 2003 Greg Baker
//:://////////////////////////////////////////////
/*
    A small group of functions that deal with character blocks (words) in strings
    fairly useful.
*/
//:://////////////////////////////////////////////
//:: Created By: Greg Baker
//:: Created On: 10/25/03
//:://////////////////////////////////////////////


//trims white space from both ends of the string, returns the trimmed string.
//doesn't trim out extraneous white spaces inside the string.
string StringTrim(string sString);

//returns the number of character blocks separated by whitespace in the string.
//single letters or characters count. punctuation does not, numbers do not.
int GetWordsInString(string sString);

//returns the word #index. increments based on words, not indexes in the string.
string GetWordByIndex(string sString, int index);

string GetWordByIndex(string sString, int index)
{
    sString=StringTrim(sString);
    int count=0;
    int i=0;
    int bLastLetter=0;
    for(i=0; i<GetStringLength(sString); i++)
    {
        if(TestStringAgainstPattern(GetSubString(sString, i, 1), "*a")&&!bLastLetter)
        {
            count++;
            bLastLetter=TRUE;
        }
        else
            bLastLetter=FALSE;
        if(count==index)
        {
            string rString="";
            int j;
            for(j=i; j<GetStringLength(sString); j++)
            {
                if(TestStringAgainstPattern(GetSubString(sString, j, 1), "*a"))
                    rString+=GetSubString(sString, j, 1);
                else
                    return rString;
            }
        }
    }
    return "";
}

int GetWordsInString(string sString)
{
    sString=StringTrim(sString);
    int count=0;
    int i=0;
    int bLastLetter=0;
    for(i=0; i<GetStringLength(sString); i++)
    {
        if(TestStringAgainstPattern(GetSubString(sString, i, 1), "*a")&&!bLastLetter)
        {
            count++;
            bLastLetter=TRUE;
        }
        else
            bLastLetter=FALSE;
    }
    return count;
}

string StringTrim(string sString)
{
    int i=0;
    while(i<GetStringLength(sString) &&  TestStringAgainstPattern(GetSubString(sString, 0, i+1), "*w"))
        i++;
    sString=GetStringRight(sString, i);
    i=GetStringLength(sString);
    while(i>0 &&  TestStringAgainstPattern(GetSubString(sString, i-1, GetStringLength(sString)-i+1), "*w"))
        i--;
    return GetStringLeft(sString, i);
}


some notes: hasn't been tested, so I'm not sure how well it works. if you find a bug, tell me what you put into the functions, and what exactly the error is. thanks.
_________________
Matthijs says:
   oh ja, ik weet het zonet nog niet
Matthijs says:
   het ziet er toch wel een beetje naar uit dat we nederlands praten
Matthijs says:
   mischien moet ik dan maar eens vaker nederlands gaan praten
Matthijs says:
   kan je me ook meteen niet op al mijn spellinsfouten wijzen
There you have it! indisputable proof Solo's a fascist!!!


Last edited by Little Teapot on Sat Oct 25, 2003 5:21 pm, edited 1 time in total
Back to top
View users profile Send private message Send email AIM Address MSN Messenger
Little Teapot
Deity


Joined: 11 Sep 2002
Posts: 2332

Level: 39
XP
EXP: 31 / 160 EXP: 31 / 160 EXP: 31 / 160
 19%
PostPosted: Sat Oct 25, 2003 5:13 pm    Post subject: Reply with quote

Another function group: getting things by their names.
it was annoying me...

Code:
//void main(){}
//::///////////////////////////////////////////////
//:: Name Creature Function include
//:: FileName inc_objcreature
//:: Copyright (c) 2001 Bioware Corp.
//:: Copyright (c) 2003 Greg Baker
//:://////////////////////////////////////////////
/*
    A small group of functions based on "missing" creature based functions
*/
//:://////////////////////////////////////////////
//:: Created By: Greg Baker
//:: Created On:10/25/03
//:://////////////////////////////////////////////
object GetNearestObjectByName(string sName, int nObjectType=OBJECT_TYPE_ALL, object oTarget=OBJECT_SELF, int nNth=1);
object GetNearestObjectToLocationByName(string sName, int nObjectType, location lLocation, int nNth=1);

object GetNearestCreatureByName(string sName, int nFirstCriteriaType, int nFirstCriteriaValue,  object oTarget=OBJECT_SELF, int nNth=1, int nSecondCriteriaType=-1, int nSecondCriteriaValue=-1, int nThirdCriteriaType=-1,  int nThirdCriteriaValue=-1);
object GetNearestCreatureToLocationByName(string sName, int nFirstCriteriaType, int nFirstCriteriaValue,  location lLocation, int nNth=1, int nSecondCriteriaType=-1, int nSecondCriteriaValue=-1, int nThirdCriteriaType=-1,  int nThirdCriteriaValue=-1);


object GetNearestObjectByName(string sName, int nObjectType=OBJECT_TYPE_ALL, object oTarget=OBJECT_SELF, int nNth=1)
{
    int nCounter=0;
    int i=1;
    object working=GetNearestObject(nObjectType, oTarget, i);
    while (nCounter<nNth&&GetIsObjectValid(working))
    {
        if(GetName(working)==sName)
            nCounter++;
        i++;
        working=GetNearestObject(nObjectType, oTarget, i);
    }
    if(nCounter==nNth)
        return working;
    return OBJECT_INVALID;
}

object GetNearestCreatureByName(string sName, int nFirstCriteriaType, int nFirstCriteriaValue,  object oTarget=OBJECT_SELF, int nNth=1, int nSecondCriteriaType=-1, int nSecondCriteriaValue=-1, int nThirdCriteriaType=-1,  int nThirdCriteriaValue=-1)
{
    int nCounter=0;
    int i=1;
    object working=GetNearestCreature(nFirstCriteriaType, nFirstCriteriaValue, oTarget, i,  nSecondCriteriaType=-1,  nSecondCriteriaValue=-1,  nThirdCriteriaType=-1,   nThirdCriteriaValue=-1);
    while (nCounter<nNth&&GetIsObjectValid(working))
    {
        if(GetName(working)==sName)
            nCounter++;
        i++;
        working=GetNearestCreature(nFirstCriteriaType, nFirstCriteriaValue, oTarget, i,  nSecondCriteriaType=-1,  nSecondCriteriaValue=-1,  nThirdCriteriaType=-1,   nThirdCriteriaValue=-1);
    }
    if(nCounter==nNth)
        return working;
    return OBJECT_INVALID;
}

object GetNearestObjectToLocationByName(string sName, int nObjectType, location lLocation, int nNth=1)
{
    int nCounter=0;
    int i=1;
    object working=GetNearestObjectToLocation(nObjectType, lLocation, i);
    while (nCounter<nNth&&GetIsObjectValid(working))
    {
        if(GetName(working)==sName)
            nCounter++;
        i++;
        working=GetNearestObjectToLocation(nObjectType, lLocation, i);
    }
    if(nCounter==nNth)
        return working;
    return OBJECT_INVALID;
}

object GetNearestCreatureToLocationByName(string sName, int nFirstCriteriaType, int nFirstCriteriaValue,  location lLocation, int nNth=1, int nSecondCriteriaType=-1, int nSecondCriteriaValue=-1, int nThirdCriteriaType=-1,  int nThirdCriteriaValue=-1)
{
    int nCounter=0;
    int i=1;
    object working=GetNearestCreatureToLocation(nFirstCriteriaType, nFirstCriteriaValue, lLocation, i,  nSecondCriteriaType=-1,  nSecondCriteriaValue=-1,  nThirdCriteriaType=-1,   nThirdCriteriaValue=-1);
    while (nCounter<nNth&&GetIsObjectValid(working))
    {
        if(GetName(working)==sName)
            nCounter++;
        i++;
        working=GetNearestCreatureToLocation(nFirstCriteriaType, nFirstCriteriaValue, lLocation, i,  nSecondCriteriaType=-1,  nSecondCriteriaValue=-1,  nThirdCriteriaType=-1,   nThirdCriteriaValue=-1);
    }
    if(nCounter==nNth)
        return working;
    return OBJECT_INVALID;
}

_________________
Matthijs says:
   oh ja, ik weet het zonet nog niet
Matthijs says:
   het ziet er toch wel een beetje naar uit dat we nederlands praten
Matthijs says:
   mischien moet ik dan maar eens vaker nederlands gaan praten
Matthijs says:
   kan je me ook meteen niet op al mijn spellinsfouten wijzen
There you have it! indisputable proof Solo's a fascist!!!
Back to top
View users profile Send private message Send email AIM Address MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    DysoForums Forum Index -> Worldbuilders All times are GMT
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum


Powered by phpBB 2.0.2 © 2001, 2002 phpBB Group