Changeset 481 for Daodan/src


Ignore:
Timestamp:
Nov 15, 2009, 3:13:50 AM (15 years ago)
Author:
gumby
Message:

Added d_distance and d_location

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Daodan/src/Daodan_BSL.c

    r476 r481  
    33#include <time.h>
    44#include <ffi.h>
    5 
     5#include <math.h>
    66#include "inifile.h"
    77
     
    218218        else index = args[0].value_int32;
    219219        Character* Chr = ONgGameState + 0x1260 ;
    220         int* health = (int*)&Chr[index] + 0x144;
     220        int* health = (int)&Chr[index] + 0x144;
    221221
    222222        ret->value_int32 = *health;
     
    226226                *health = args[1].value_int32;
    227227        }
    228         ret->value_int32 = *health;
    229         ret->type = sl_int32;
    230         return 0;
    231 }
    232 
     228        return 0;
     229}
     230
     231uint16_t ONICALL bsl_distance(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) {
     232       
     233        if (numargs < 2) return 1;
     234        int index;
     235        int index2;
     236        if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].value_str32);
     237        else index = args[0].value_int32;
     238        if (index == -1) index = args[0].value_int32;
     239
     240        if (args[1].type == sl_str32) index2 = DDrGetCharacterIndexFromName(args[1].value_str32);
     241        else index2 = args[1].value_int32;
     242        if (index2 == -1) index2 = args[1].value_int32;
     243       
     244        Character* Chr = ONgGameState + 0x1260;
     245        Character* Char1 = &Chr[index];
     246        Character* Char2 = &Chr[index2];
     247
     248        ret->value_float = sqrt( pow((Char1->Location.X - Char2->Location.X), 2) + pow((Char1->Location.Y - Char2->Location.Y), 2) + pow((Char1->Location.Z - Char2->Location.Z),2));
     249        ret->type = sl_float;
     250        return 0;
     251}
     252uint16_t ONICALL bsl_location(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) {
     253        int index;
     254        if (numargs < 2) return 1;
     255        if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].value_str32);
     256        else index = args[0].value_int32;
     257        if (index == -1) index = args[0].value_int32;
     258        Character* Chr = ONgGameState + 0x1260;
     259        float* loc;
     260        if (!strcmp(args[1].value_str32,"X") || !strcmp(args[1].value_str32,"x"))
     261        loc = &(Chr[index].Position.X);
     262        else if (!strcmp(args[1].value_str32,"Y") || !strcmp(args[1].value_str32,"y"))
     263        loc = &(Chr[index].Position.Y);
     264        else if (!strcmp(args[1].value_str32,"Z") || !strcmp(args[1].value_str32,"z"))
     265        loc = &(Chr[index].Position.Z);
     266        else if (numargs == 4) {
     267                //currently broken. crashes oni.
     268                Chr[index].Position.X = args[1].value_float;
     269                Chr[index].Position.Y = args[2].value_float;
     270                Chr[index].Position.Z = args[3].value_float;
     271                ret->value_float = 1;
     272                ret->type = sl_float;
     273                return 0;
     274        }
     275        else return 1;
     276       
     277        ret->value_float = *loc;
     278        ret->type = sl_float;
     279       
     280        if(numargs == 3) {
     281                //currently broken, does nothing.
     282                *loc = args[2].value_float;
     283        }
     284        return 0;
     285}
    233286
    234287uint16_t ONICALL bsl_maxhealth(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
     
    332385uint16_t ONICALL bsl_nametoindex(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
    333386{
     387
    334388        ret->type = sl_int32;
    335389        ret->value_int32 = DDrGetCharacterIndexFromName(args[0].value_str32);
     390
    336391        return 0;
    337392}
     
    397452        {
    398453                int index;
    399                 if (numargs < 4) index = 0;
    400                 else    if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].value_str32);
     454               
     455                if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].value_str32);
    401456                else index = args[0].value_int32;
    402 
     457               
    403458                Character* Chr = ONgGameState + 0x1260;
    404459        ActiveCharacter* Active = (ActiveCharacter*)ONrGetActiveCharacter(&Chr[index]);
     
    408463        int Input1 = 0;
    409464        int Input2 = 0;
    410         for(i = 1; i < numargs; i++) {
     465        for(i = 1; i < numargs - 1; i++) {
    411466                for(j = 0; j < 32; j++) {
    412                         if(strcmp(args[i].value_str32, Actions1[j].Name)) Input1 = Input1 | Actions1[j].Bit;
    413                         DDrConsole_PrintF("Testing %s against %s 0x%x", args[i].value_str32, Actions1[j].Name, Actions1[j].Bit);
     467                        if(!strcmp(args[i].value_str32, Actions1[j].Name)) {
     468                                Input1 = Input1 | Actions1[j].Bit;
     469                        }
    414470                }
    415471                for(j = 0; j < 9; j++) {
    416                         if(!strcmp(args[i].value_str32, Actions2[j].Name)) Input2 = Input2 | Actions2[j].Bit;
    417        
    418                 }
    419                 }
    420         for(i = 0; i < numargs; i++) {
    421                 DDrConsole_PrintF("%s", args[i].value_str32);
    422         }
    423 //      if
     472                        if(!strcmp(args[i].value_str32, Actions2[j].Name)) {
     473                                Input2 = Input2 | Actions2[j].Bit;
     474                        }
     475                }
     476        }
     477        Active->Input.Current.Actions1 = Active->Input.Current.Actions1 | Input1;
     478        Active->Input.Current.Actions2 = Active->Input.Current.Actions1 | Input2;
     479        if( Input1 + Input2 == 0 ) {
     480                DDrConsole_PrintF("Func \"%s\", File \"%s\", Line %d: semantic error, \"%s\": No valid keys given.", callinfo->name, callinfo->calllocation, callinfo->linenumber, callinfo->name);
     481                return 0;
     482        }
     483        if (  args[numargs - 1].value_int32 <= 0) {
     484                return 0;
     485        }
     486        else {
     487                 args[numargs - 1].value_int32 -= 1;
     488                *dontuse2 = 1;
     489                *dontuse1 = 1;
     490        }
    424491        return 0;
    425492}
     
    673740}
    674741
    675 uint16_t ONICALL bsl_findmsg(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
    676 {
    677         //DDrMake_Weapon_Message(args[0].value_str32);
    678         return false;
    679 }
    680742void SLrDaodan_Initalize()
    681743{
     
    689751
    690752        SLrConfig();
    691         SLrScript_Command_Register_ReturnType("d_wp", "Shows weapon message", "wpn:string", sl_void, bsl_findmsg);
    692753
    693754        SLrScript_Command_Register_ReturnType("int32mul", "Multiplies two numbers", "n1:int n2:int", sl_int32, bsl_int32mul);
     
    703764        SLrScript_Command_Register_ReturnType("d_getdamage","Gets the amount of damage a character has caused", "[ai_name:string | script_id:int]", sl_int32, bsl_getdamage);
    704765        SLrScript_Command_Register_ReturnType("d_name","Gets or sets a character's name", "[ai_name:str | script_id:int] [newname:string]", sl_str32, bsl_chrname);
    705         SLrScript_Command_Register_ReturnType("d_getindex","Converts a character's name to its index", "script_id:int", sl_int32, bsl_nametoindex);
     766        SLrScript_Command_Register_ReturnType("d_getindex","Converts a character's name to its index", "ai_name:string", sl_int32, bsl_nametoindex);
    706767        SLrScript_Command_Register_ReturnType("d_health","Gets or sets a character's health", "[ai_name:str | script_id:int] [newhealth:int]", sl_str32, bsl_health);
    707768        SLrScript_Command_Register_ReturnType("d_regen","Gets or sets a character's health", "[ai_name:str | script_id:int] [newhealth:int]", sl_str32, bsl_regen);
    708769        SLrScript_Command_Register_ReturnType("d_maxhealth","Gets or sets a character's maximum health", "[ai_name:str | script_id:int] [newmaxhealth:int] [scalehealth:bool]", sl_str32, bsl_maxhealth);
    709770        SLrScript_Command_Register_ReturnType("d_powerup","Gets or sets a character's powerups", "ai_name:str|script_id:int powerup:str", sl_int32, bsl_powerup);
    710         SLrScript_Command_Register_ReturnType("d_holdkey","Makes an AI hold a key", "[ai_name:string | script_id:int] keys", sl_int32, bsl_holdkey);
    711         SLrScript_Command_Register_ReturnType("d_isheld","Checks for a held key", "keys", sl_int32, bsl_isheld);
    712         SLrScript_Command_Register_Void("d_waitforkey","Waits for a keypress.", "keys", bsl_waitforkey);
    713 
    714         //broken. sometimes crashes, and sometimes returns a string... : /
    715         SLrScript_Command_Register_ReturnType("d_getattacker","Gets the last person to hurt a character", "[ai_name:string | script_id:int]", sl_int32, bsl_getattacker);
    716        
    717         SLrScript_Command_Register_ReturnType("d_active","Gets the last person to hurt a character", "[ai_name:string | script_id:int]", sl_int32, bsl_getactiveoffset);
     771        SLrScript_Command_Register_ReturnType("d_holdkey","Makes a character hold a key", "[ai_name:string | script_id:int] keys frames:int", sl_int32, bsl_holdkey);
     772        SLrScript_Command_Register_ReturnType("d_isheld","Checks if player is holding a key", "keys", sl_int32, bsl_isheld);
     773        SLrScript_Command_Register_ReturnType("d_location","Returns the X, Y or Z coord of a character", "ai_name:str | script_id:int xyz:string [newlocation:float]", sl_float, bsl_location);
     774        SLrScript_Command_Register_ReturnType("d_distance","Returns the distance between two characters", "ai_name:str | script_id:int ai_name:str | script_id:int ", sl_float, bsl_distance);
     775        SLrScript_Command_Register_Void("d_waitforkey","Waits for a keypress from the player", "keys", bsl_waitforkey);
     776
     777        //broken, only works for one damage type.
     778        //SLrScript_Command_Register_ReturnType("d_getattacker","Gets the last person to hurt a character", "[ai_name:string | script_id:int]", sl_int32, bsl_getattacker);
     779       
     780        //used for debugging.
     781        SLrScript_Command_Register_ReturnType("d_active","Returns a hex offset. ;)", "[ai_name:string | script_id:int]", sl_int32, bsl_getactiveoffset);
    718782
    719783        SLrScript_Command_Register_ReturnType("sprintf", "C-style sprintf.", "format:string arg1 arg2 ...", sl_str32, bsl_sprintf);
Note: See TracChangeset for help on using the changeset viewer.