Welcome to mirror list, hosted at ThFree Co, Russian Federation.

characterscript.cpp « Game « Source - github.com/WolfireGames/overgrowth.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: bb713cf9b138c8308a72dd2769a73e9857266628 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
//-----------------------------------------------------------------------------
//           Name: characterscript.cpp
//      Developer: Wolfire Games LLC
//    Description:
//        License: Read below
//-----------------------------------------------------------------------------
//
//
//   Copyright 2022 Wolfire Games LLC
//
//   Licensed under the Apache License, Version 2.0 (the "License");
//   you may not use this file except in compliance with the License.
//   You may obtain a copy of the License at
//
//       http://www.apache.org/licenses/LICENSE-2.0
//
//   Unless required by applicable law or agreed to in writing, software
//   distributed under the License is distributed on an "AS IS" BASIS,
//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//   See the License for the specific language governing permissions and
//   limitations under the License.
//
//-----------------------------------------------------------------------------
#include "characterscript.h"

#include <Scripting/angelscript/ascontext.h>
#include <Objects/itemobject.h>
#include <Main/engine.h>

bool CharacterScriptGetter::Load( const std::string& _path ) {
    //Characters::Instance()->ReturnRef(_path);
    character_ref = Engine::Instance()->GetAssetManager()->LoadSync<Character>(_path);
    if( character_ref.valid() ) {
        return true;  
    } else {
        return false;
    }
}

std::string CharacterScriptGetter::GetObjPath( ) {
    return character_ref->GetObjPath();
}

std::string CharacterScriptGetter::GetSkeletonPath( ) {
    return character_ref->GetSkeletonPath();
}

std::string CharacterScriptGetter::GetAnimPath( const std::string& action ) {
    for(unsigned i=0; i<items.size(); ++i){
        if(items[i]->HasAnimOverride(action)){
            return items[i]->GetAnimOverride(action);
        }
    }
    CharAnimOverrideMap::iterator iter = char_anim_overrides_.find(action);
    if(iter == char_anim_overrides_.end()){
        return character_ref->GetAnimPath(action);
    } else {
        return iter->second;
    }
}

const std::string & CharacterScriptGetter::GetTag(const std::string &key) {
    return character_ref->GetTag(key);
}


char CharacterScriptGetter::GetAnimFlags( const std::string& action ) {
    for(unsigned i=0; i<items.size(); ++i){
        if(items[i]->HasAnimOverride(action)){
            return items[i]->GetAnimOverrideFlags(action);
        }
    }
    return 0;
}

std::string CharacterScriptGetter::GetAttackPath( const std::string& action ) {
    for(unsigned i=0; i<items.size(); ++i){
        if(items[i]->HasAttackOverride(action)){
            return items[i]->GetAttackOverride(action);
        }
    }
    return character_ref->GetAttackPath(action);
}

int CharacterScriptGetter::OnSameTeam( const std::string& char_path ) {
    //CharacterRef other = Characters::Instance()->ReturnRef(char_path);
    CharacterRef other = Engine::Instance()->GetAssetManager()->LoadSync<Character>(char_path);
    const std::set<std::string> &team_set = character_ref->GetTeamSet();
    for(std::set<std::string>::const_iterator iter = team_set.begin();
        iter != team_set.end();
        ++iter)
    {
        if(other->IsOnTeam(*iter)){
            return 1;
        }
    }
    return 0;
}

void CharacterScriptGetter::GetTeamString(std::string &str) {
    str.clear();
    const std::set<std::string> &team_set = character_ref->GetTeamSet();
    for(std::set<std::string>::const_iterator iter = team_set.begin();
        iter != team_set.end();
        ++iter)
    {
        if(iter != team_set.begin()){
            str += ", ";
        }
        str += (*iter);
    }
}

void CharacterScriptGetter::AttachToScript( ASContext *as_context, const std::string& as_name ) {
    as_context->RegisterObjectType("CharacterScriptGetter", 0, asOBJ_REF | asOBJ_NOHANDLE, "Can load a character xml and provide access to its data");
    as_context->RegisterObjectMethod("CharacterScriptGetter", "bool Load(const string &in)", asMETHOD(CharacterScriptGetter, Load), asCALL_THISCALL, "Load a character xml file (e.g. \"Data/Characters/guard.xml\")");
    as_context->RegisterObjectMethod("CharacterScriptGetter", "string GetObjPath()", asMETHOD(CharacterScriptGetter, GetObjPath), asCALL_THISCALL);
    as_context->RegisterObjectMethod("CharacterScriptGetter", "string GetSkeletonPath()", asMETHOD(CharacterScriptGetter, GetSkeletonPath), asCALL_THISCALL);
    as_context->RegisterObjectMethod("CharacterScriptGetter", "string GetAnimPath(const string &in anim_label)", asMETHOD(CharacterScriptGetter, GetAnimPath), asCALL_THISCALL);
    as_context->RegisterObjectMethod("CharacterScriptGetter", "const string& GetTag(const string &in key)", asMETHOD(CharacterScriptGetter, GetTag), asCALL_THISCALL);
    as_context->RegisterObjectMethod("CharacterScriptGetter", "string GetAttackPath(const string &in attack_label)", asMETHOD(CharacterScriptGetter, GetAttackPath), asCALL_THISCALL);
    as_context->RegisterObjectMethod("CharacterScriptGetter", "void GetTeamString(string &out team_string)", asMETHOD(CharacterScriptGetter, GetTeamString), asCALL_THISCALL);
    as_context->RegisterObjectMethod("CharacterScriptGetter", "float GetHearing()", asMETHOD(CharacterScriptGetter, GetHearing), asCALL_THISCALL);
    as_context->RegisterObjectMethod("CharacterScriptGetter", "const string& GetChannel(int which_channel)", asMETHOD(CharacterScriptGetter, GetChannel), asCALL_THISCALL, "Get type of given color channel (e.g. \"fur\", \"cloth\")");    
    as_context->RegisterObjectMethod("CharacterScriptGetter", "bool GetMorphMetaPoints(const string &in label, vec3 &out start, vec3 &out end)", asMETHOD(CharacterScriptGetter, GetMorphMetaPoints), asCALL_THISCALL);    
    as_context->DocsCloseBrace();
    as_context->RegisterGlobalProperty(("CharacterScriptGetter "+as_name).c_str(), this);
}

const std::string &CharacterScriptGetter::GetChannel(int which){
    return character_ref->GetChannel(which);
}

void CharacterScriptGetter::AttachExtraToScript( ASContext *as_context, const std::string& as_name ) {
    as_context->RegisterGlobalProperty(("CharacterScriptGetter "+as_name).c_str(), this);
}

void CharacterScriptGetter::ItemsChanged( const std::vector<ItemRef> &_items ) {
    items = _items;
}

const std::string CharacterScriptGetter::GetClothingPath() {
    return character_ref->GetClothingPath();
}

const std::string& CharacterScriptGetter::GetSoundMod() {
    return character_ref->GetSoundMod();
}

float CharacterScriptGetter::GetHearing() {
    return character_ref->GetHearing();
}

void CharacterScriptGetter::OverrideCharAnim( const std::string &label, const std::string &new_path ) {
    char_anim_overrides_[label] = new_path;
}

float CharacterScriptGetter::GetDefaultScale() {
    return character_ref->GetDefaultScale();
}

float CharacterScriptGetter::GetModelScale() {
    return character_ref->GetModelScale();
}

bool CharacterScriptGetter::GetMorphMetaPoints(const std::string& label, vec3 &start, vec3 &end) {
    return character_ref->GetMorphMeta(label, start, end);
}