From: <bal...@us...> - 2004-01-02 00:53:07
|
Update of /cvsroot/gemrb/gemrb/gemrb/plugins/Core In directory sc8-pr-cvs1:/tmp/cvs-serv21166/gemrb/plugins/Core Modified Files: GameScript.h GameScript.cpp Log Message: GameScript.cpp / .h : - Added autoFree support to the Action Struct - EvaluateTrigger, GenerateAction, GenerateTrigger, ExecuteString, EvaluateString are now static - Added CreateAction method - Added OpenDoor and CloseDoor OpCodes Index: GameScript.h =================================================================== RCS file: /cvsroot/gemrb/gemrb/gemrb/plugins/Core/GameScript.h,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** GameScript.h 1 Jan 2004 15:45:07 -0000 1.18 --- GameScript.h 2 Jan 2004 00:53:02 -0000 1.19 *************** *** 78,82 **** char* string0Parameter; char* string1Parameter; ! bool EndReached; } Action; --- 78,83 ---- char* string0Parameter; char* string1Parameter; ! bool autoFree; ! bool delayFree; } Action; *************** *** 146,157 **** Object * DecodeObject(const char * line); bool EvaluateCondition(Scriptable * Sender, Condition * condition); ! bool EvaluateTrigger(Scriptable * Sender, Trigger * trigger); void ExecuteResponseSet(Scriptable * Sender, ResponseSet * rS); void ExecuteResponse(Scriptable * Sender, Response * rE); public: static void ExecuteAction(Scriptable * Sender, Action * aC); private: ! Action * GenerateAction(char * String); ! Trigger * GenerateTrigger(char * String); static Scriptable * GetActorFromObject(Scriptable * Sender, Object * oC); static unsigned char GetOrient(short sX, short sY, short dX, short dY); --- 147,159 ---- Object * DecodeObject(const char * line); bool EvaluateCondition(Scriptable * Sender, Condition * condition); ! static bool EvaluateTrigger(Scriptable * Sender, Trigger * trigger); void ExecuteResponseSet(Scriptable * Sender, ResponseSet * rS); void ExecuteResponse(Scriptable * Sender, Response * rE); public: static void ExecuteAction(Scriptable * Sender, Action * aC); + static Action* CreateAction(char *string, bool autoFree = true); private: ! static Action * GenerateAction(char * String); ! static Trigger * GenerateTrigger(char * String); static Scriptable * GetActorFromObject(Scriptable * Sender, Object * oC); static unsigned char GetOrient(short sX, short sY, short dX, short dY); *************** *** 168,173 **** ~GameScript(); void SetVariable(const char * VarName, const char * Context, int value); ! void ExecuteString(char * String); ! bool EvaluateString(char * String); private: //Script Functions //Triggers --- 170,175 ---- ~GameScript(); void SetVariable(const char * VarName, const char * Context, int value); ! static void ExecuteString(Scriptable * Sender, char * String); ! static bool EvaluateString(Scriptable * Sender, char * String); private: //Script Functions //Triggers *************** *** 184,188 **** static int Clicked(Scriptable * Sender, Trigger * parameters); static int Entered(Scriptable * Sender, Trigger * parameters); ! public: //Actions static void SetGlobal(Scriptable * Sender, Action * parameters); --- 186,190 ---- static int Clicked(Scriptable * Sender, Trigger * parameters); static int Entered(Scriptable * Sender, Trigger * parameters); ! private: //Actions static void SetGlobal(Scriptable * Sender, Action * parameters); *************** *** 228,231 **** --- 230,235 ---- static void AmbientActivate(Scriptable * Sender, Action * parameters); static void StartDialogue(Scriptable * Sender, Action * parameters); + static void OpenDoor(Scriptable * Sender, Action * parameters); + static void CloseDoor(Scriptable * Sender, Action * parameters); }; Index: GameScript.cpp =================================================================== RCS file: /cvsroot/gemrb/gemrb/gemrb/plugins/Core/GameScript.cpp,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** GameScript.cpp 1 Jan 2004 15:45:07 -0000 1.27 --- GameScript.cpp 2 Jan 2004 00:53:02 -0000 1.28 *************** *** 95,98 **** --- 95,102 ---- instant[127] = true; actions[137] = StartDialogue; + actions[143] = OpenDoor; + blocking[143] = true; + actions[144] = CloseDoor; + blocking[144] = true; actions[151] = DisplayString; actions[153] = ChangeAllegiance; *************** *** 376,379 **** --- 380,385 ---- while(true) { Action * aC = new Action(); + aC->autoFree = false; + aC->delayFree = false; count = stream->ReadLine(line, 1024); aC->actionID = 0; *************** *** 510,513 **** --- 516,548 ---- if(!blocking[aC->actionID]) Sender->CurrentAction = NULL; + if(aC->autoFree) { + if(aC->delayFree) + aC->delayFree = false; + else { + if(aC->string0Parameter) + free(aC->string0Parameter); + if(aC->string1Parameter) + free(aC->string1Parameter); + for(int c = 0; c < 3; c++) { + Object * oB = aC->objects[c]; + if(oB) { + if(oB->objectName) + free(oB->objectName); + delete(oB); + } + } + delete(aC); + } + } + } + + Action* GameScript::CreateAction(char *string, bool autoFree) + { + Action * aC = GenerateAction(string); + if(aC) { + aC->autoFree = autoFree; + aC->delayFree = false; + } + return aC; } *************** *** 515,534 **** { //TODO: Implement Object Retieval ! ! if(oC->objectName[0] != 0) { ! printf("ActionOverride on %s\n", oC->objectName); ! Map * map = core->GetGame()->GetMap(0); ! return map->GetActor(oC->objectName); ! } ! else { ! if(oC->genderField != 0) { ! switch(oC->genderField) { ! case 21: ! return core->GetGame()->GetPC(0); ! break; ! ! case 17: ! return Sender->LastTrigger; ! break; } } --- 550,570 ---- { //TODO: Implement Object Retieval ! if(oC) { ! if(oC->objectName[0] != 0) { ! //printf("ActionOverride on %s\n", oC->objectName); ! Map * map = core->GetGame()->GetMap(0); ! return map->GetActor(oC->objectName); ! } ! else { ! if(oC->genderField != 0) { ! switch(oC->genderField) { ! case 21: ! return core->GetGame()->GetPC(0); ! break; ! ! case 17: ! return Sender->LastTrigger; ! break; ! } } } *************** *** 568,572 **** } ! void GameScript::ExecuteString(char * String) { if(String[0] == 0) --- 604,608 ---- } ! void GameScript::ExecuteString(Scriptable * Sender, char * String) { if(String[0] == 0) *************** *** 575,601 **** if(!act) return; ! ExecuteAction(this->MySelf, act); ! if(act->string0Parameter) ! free(act->string0Parameter); ! if(act->string1Parameter) ! free(act->string1Parameter); ! for(int c = 0; c < 3; c++) { ! Object * oB = act->objects[c]; ! if(oB) { ! if(oB->objectName) ! free(oB->objectName); ! delete(oB); ! } ! } ! delete(act); return; } ! bool GameScript::EvaluateString(char * String) { if(String[0] == 0) return false; Trigger * tri = GenerateTrigger(String); ! bool ret = EvaluateTrigger(this->MySelf, tri); if(tri->flags&1) ret = !ret; --- 611,626 ---- if(!act) return; ! act->autoFree = true; ! Sender->CurrentAction = act; ! ExecuteAction(Sender, act); return; } ! bool GameScript::EvaluateString(Scriptable * Sender, char * String) { if(String[0] == 0) return false; Trigger * tri = GenerateTrigger(String); ! bool ret = EvaluateTrigger(Sender, tri); if(tri->flags&1) ret = !ret; *************** *** 1356,1359 **** --- 1381,1385 ---- if(scr != Sender) { //this is an Action Override scr->AddAction(Sender->CurrentAction); + Sender->CurrentAction->delayFree = true; Sender->CurrentAction = NULL; return; *************** *** 1372,1375 **** --- 1398,1402 ---- if(scr != Sender) { //this is an Action Override scr->AddAction(Sender->CurrentAction); + Sender->CurrentAction->delayFree = true; Sender->CurrentAction = NULL; return; *************** *** 1386,1389 **** --- 1413,1417 ---- if(scr != Sender) { //this is an Action Override scr->AddAction(Sender->CurrentAction); + Sender->CurrentAction->delayFree = true; Sender->CurrentAction = NULL; return; *************** *** 1399,1402 **** --- 1427,1431 ---- if(scr != Sender) { //this is an Action Override scr->AddAction(Sender->CurrentAction); + Sender->CurrentAction->delayFree = true; Sender->CurrentAction = NULL; return; *************** *** 1430,1433 **** --- 1459,1463 ---- if(scr != Sender) { //this is an Action Override scr->AddAction(Sender->CurrentAction); + Sender->CurrentAction->delayFree = true; Sender->CurrentAction = NULL; return; *************** *** 1450,1453 **** --- 1480,1484 ---- if(scr != Sender) { //this is an Action Override scr->AddAction(Sender->CurrentAction); + Sender->CurrentAction->delayFree = true; Sender->CurrentAction = NULL; return; *************** *** 1467,1470 **** --- 1498,1502 ---- if(scr != Sender) { //this is an Action Override scr->AddAction(Sender->CurrentAction); + Sender->CurrentAction->delayFree = true; Sender->CurrentAction = NULL; return; *************** *** 1486,1489 **** --- 1518,1522 ---- if(scr != Sender) { //this is an Action Override scr->AddAction(Sender->CurrentAction); + Sender->CurrentAction->delayFree = true; Sender->CurrentAction = NULL; return; *************** *** 1503,1506 **** --- 1536,1540 ---- if(scr != Sender) { //this is an Action Override scr->AddAction(Sender->CurrentAction); + Sender->CurrentAction->delayFree = true; Sender->CurrentAction = NULL; return; *************** *** 1524,1527 **** --- 1558,1562 ---- if(scr != Sender) { //this is an Action Override scr->AddAction(Sender->CurrentAction); + Sender->CurrentAction->delayFree = true; Sender->CurrentAction = NULL; return; *************** *** 1567,1570 **** --- 1602,1606 ---- if(scr != Sender) { //this is an Action Override scr->AddAction(Sender->CurrentAction); + Sender->CurrentAction->delayFree = true; Sender->CurrentAction = NULL; return; *************** *** 1583,1586 **** --- 1619,1623 ---- if(scr != Sender) { //this is an Action Override scr->AddAction(Sender->CurrentAction); + Sender->CurrentAction->delayFree = true; Sender->CurrentAction = NULL; return; *************** *** 1608,1611 **** --- 1645,1649 ---- if(scr != Sender) { //this is an Action Override scr->AddAction(Sender->CurrentAction); + Sender->CurrentAction->delayFree = true; Sender->CurrentAction = NULL; return; *************** *** 1643,1646 **** --- 1681,1685 ---- if(scr != Sender) { //this is an Action Override scr->AddAction(Sender->CurrentAction); + Sender->CurrentAction->delayFree = true; Sender->CurrentAction = NULL; return; *************** *** 1695,1698 **** --- 1734,1738 ---- if(scr != Sender) { //this is an Action Override scr->AddAction(Sender->CurrentAction); + Sender->CurrentAction->delayFree = true; Sender->CurrentAction = NULL; return; *************** *** 1712,1715 **** --- 1752,1839 ---- gc->InitDialog(actor, target, dm->GetDialog()); core->FreeInterface(dm); + } + } + + void GameScript::OpenDoor(Scriptable * Sender, Action * parameters) + { + Scriptable * scr = GetActorFromObject(Sender, parameters->objects[0]); + if(!scr) + return; + if(scr->Type != ST_ACTOR) + return; + if(scr != Sender) { //this is an Action Override + scr->AddAction(Sender->CurrentAction); + Sender->CurrentAction->delayFree = true; + Sender->CurrentAction = NULL; + return; + } + Scriptable * tar = core->GetGame()->GetMap(0)->tm->GetDoor(parameters->objects[1]->objectName); + if(!tar) + return; + if(tar->Type != ST_DOOR) + return; + Door * door = (Door*)tar; + Actor * actor = (Actor*)scr; + long x = (actor->XPos - door->XPos); + long y = (actor->YPos - door->YPos); + double distance = sqrt((x*x)+(y*y)); + if(distance <= 128) { + door->SetDoorClosed(false, true); + Sender->CurrentAction = NULL; + } else { + Sender->AddActionInFront(Sender->CurrentAction); + Sender->CurrentAction->delayFree = true; + long x1 = (actor->XPos - door->toOpen[0].x); + long y1 = (actor->YPos - door->toOpen[0].y); + double distance1 = sqrt((x1*x1)+(y1*y1)); + long x2 = (actor->XPos - door->toOpen[1].x); + long y2 = (actor->YPos - door->toOpen[1].y); + double distance2 = sqrt((x2*x2)+(y2*y2)); + if(distance1 < distance2) + actor->WalkTo(door->toOpen[0].x, door->toOpen[0].y); + else + actor->WalkTo(door->toOpen[1].x, door->toOpen[1].y); + } + } + + void GameScript::CloseDoor(Scriptable * Sender, Action * parameters) + { + Scriptable * scr = GetActorFromObject(Sender, parameters->objects[0]); + if(!scr) + return; + if(scr->Type != ST_ACTOR) + return; + if(scr != Sender) { //this is an Action Override + scr->AddAction(Sender->CurrentAction); + Sender->CurrentAction->delayFree = true; + Sender->CurrentAction = NULL; + return; + } + Scriptable * tar = core->GetGame()->GetMap(0)->tm->GetDoor(parameters->objects[1]->objectName); + if(!tar) + return; + if(tar->Type != ST_DOOR) + return; + Door * door = (Door*)tar; + Actor * actor = (Actor*)scr; + long x = (actor->XPos - door->XPos); + long y = (actor->YPos - door->YPos); + double distance = sqrt((x*x)+(y*y)); + if(distance <= 100) { + door->SetDoorClosed(true, true); + Sender->CurrentAction = NULL; + } else { + Sender->AddActionInFront(Sender->CurrentAction); + Sender->CurrentAction->delayFree = true; + long x1 = (actor->XPos - door->toOpen[0].x); + long y1 = (actor->YPos - door->toOpen[0].y); + double distance1 = sqrt((x1*x1)+(y1*y1)); + long x2 = (actor->XPos - door->toOpen[1].x); + long y2 = (actor->YPos - door->toOpen[1].y); + double distance2 = sqrt((x2*x2)+(y2*y2)); + if(distance1 < distance2) + actor->WalkTo(door->toOpen[0].x, door->toOpen[0].y); + else + actor->WalkTo(door->toOpen[1].x, door->toOpen[1].y); } } |