Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- отношение персонажа к актеру (или другому NPC) вычисляется по формуле:
- -- attitude = personal_goodwill + -- личное отношение персонажа к актеру (если раньше не встречались, то 0)
- -- community_goodwill + -- отношение группировки персонажа лично к актеру (если раньше контактов не было, то 0)
- -- community_to_community + -- отношение группировки персонажа к группировке актера из [communities_relations]
- -- reputation_goodwill + -- отношение репутации персонажа к репутации актера из [reputation_relations]
- -- rank_goodwill -- отношение ранга персонажа к рангу актера из [rank_relations]
- --- GLOBAL --------------------------------------------------------------------
- default_sympathy = 0.01
- -- TODO check and document this tables layout.
- temp_goodwill_table = {}
- --- LOCAL ---------------------------------------------------------------------
- local FRIENDS = 1000
- local NEUTRALS = 0
- local ENEMIES = -1000
- -- 2013-08-17 13:19: ~Xetrill: Shouldn't really be here, because it's to general, and useful in
- -- other places as well. Could be moved to utils. I keep it in my xs_utils script.
- local function clamp(num, min, max)
- if num < min then
- return min
- elseif num > max then
- return max
- else
- return num
- end
- end
- local function invalidFactions(faction, faction_to)
- return (
- faction == nil or
- faction == 'none' or
- faction_to == 'none'
- )
- end
- local relationTypeToGoodwillMap = {
- enemy = -5000,
- friend = 5000
- }
- local function getGoodwillForRelationType(type)
- return relationTypeToGoodwillMap[type] or 0
- end
- --- GLOBAL --------------------------------------------------------------------
- function set_factions_community(faction, faction_to, relationType)
- if invalidFactions(faction, faction_to) then
- return
- end
- set_factions_community_num(faction, faction_to, getGoodwillForRelationType(relationType))
- end
- function set_factions_community_num(faction, faction_to, new_community_num)
- if invalidFactions(faction, faction_to) then
- return
- end
- relation_registry.set_community_relation(faction, faction_to, new_community_num)
- end
- function get_factions_community(faction, faction_to)
- if invalidFactions(faction, faction_to) then
- return nil
- end
- return relation_registry.community_relation(faction, faction_to)
- end
- function is_factions_friends(faction, faction_to)
- if invalidFactions(faction, faction_to) then
- return false
- end
- return relation_registry.community_relation(faction, faction_to) >= FRIENDS
- end
- function is_factions_enemies(faction, faction_to)
- if invalidFactions(faction, faction_to) then
- return false
- end
- return relation_registry.community_relation(faction, faction_to) <= ENEMIES
- end
- function get_npcs_relation(npc1, npc2)
- return npc1 and npc2 and npc1:relation(npc2)
- end
- function set_npcs_relation(npc1, npc2, new_relation)
- if not npc1 or not npc2 then
- abort("[game_relations.set_npcs_relation]: Invalid arguments; #1 '%s', #2 '%s'.", type(npc1), type(npc2))
- end
- npc1:set_goodwill(getGoodwillForRelationType(new_relation), npc2)
- end
- function get_npc_sympathy(npc)
- return npc:sympathy()
- end
- function set_npc_sympathy(npc, new_sympathy)
- if not npc then
- abort("[game_relations.set_npcs_relation]: Invalid argument #1 '%s', #2 '%s'.", type(npc))
- end
- npc:set_sympathy(clamp(new_sympathy, 0.0, 1.0))
- end
- function set_squad_goodwill(squad_id, new_goodwill)
- local squad = sim_board.get_sim_board().squads[squad_id]
- if not squad then
- abort("[game_relations.set_squad_goodwill] Missing squad with ID '%s'.", tostring(squad_id))
- end
- local goodwill = getGoodwillForRelationType(new_goodwill)
- local st, gw = db.storage, db.goodwill
- local act, obj = db.actor
- -- TODO Check if squad.squad_npc is a list or map and adjust iterators accordingly.
- for k, v in pairs(squad.squad_npc) do
- obj = st[v] and st[v].object
- if obj then
- obj:set_goodwill(goodwill, act)
- if not gw.relations then
- gw.relations = {}
- end
- gw.relations[k] = new_goodwill
- end
- end
- squad.relationship = new_goodwill
- end
- function set_squad_goodwill_to_npc(npc, squad_id, new_goodwill)
- local squad = sim_board.get_sim_board().squads[squad_id]
- if not squad then
- abort("[game_relations.set_squad_goodwill_to_npc] Missing squad with ID '%s'.", tostring(squad_id))
- end
- local goodwill = getGoodwillForRelationType(new_goodwill)
- local st = db.storage
- local obj
- for k, v in pairs(squad.squad_npc) do
- obj = st[v] and st[v].object
- if obj then
- obj:set_goodwill(goodwill, npc)
- end
- end
- end
- function set_squad_community_goodwill(squad_id, community, new_goodwill)
- local squad = sim_board.get_sim_board().squads[squad_id]
- if not squad then
- abort("[game_relations.set_squad_community_goodwill] Missing squad with ID '%s'.", tostring(squad_id))
- end
- local goodwill = getGoodwillForRelationType(new_goodwill)
- local st = db.storage
- local obj
- for k, v in pairs(squad.squad_npc) do
- obj = st[v] and st[v].object
- if obj then
- obj:set_community_goodwill(community, goodwill)
- end
- end
- end
- function set_level_faction_community(obj)
- if not db.actor or not temp_goodwill_table.communities then
- return
- end
- local occ, oid = obj:character_community(), obj:id()
- local act = db.actor
- local aid = act:id()
- -- TODO give proper names to k, v, kk and vv once it's clear what they should be named.
- for k, v in pairs(temp_goodwill_table.communities) do
- if occ == k then
- for kk, vv in pairs(v) do
- if kk == oid then
- relation_registry.set_community_goodwill(k, aid, vv)
- obj:set_goodwill(vv, act)
- v[kk] = nil
- end
- end
- end
- end
- end
- function check_all_squad_members(squad_name, goodwill)
- local act = db.actor
- if not act then
- return false
- end
- local squad = sim_board.get_sim_board().squads[squad_name]
- if not squad then
- return false
- end
- local st, obj = db.storage
- for k, _ in pairs(squad.squad_npc) do
- obj = st[k] and st[k].object
- if obj and obj:general_goodwill(act) <= ENEMIES then
- return goodwill == 'enemy'
- end
- end
- return goodwill == 'friend'
- end
- function get_squad_goodwill_to_actor(squad_name)
- local squad = sim_board.get_sim_board().squads[squad_name]
- if not squad then
- abort("[game_relations.get_squad_goodwill_to_actor] Missing squad with ID '%s'.", tostring(squad_id))
- end
- if squad.relationship ~= nil then
- return squad.relationship
- end
- -- TODO check if 'alife():actor()' is differant somehow than 'db.actor'.
- -- 2013-08-17 14:10: ~Xetrill: I don't think so, it looks like db.actor is set by the game from
- -- the C++ side of things. Because there doesn't seem to be any assignment to db.actor other
- -- then in db.script itself and there its's set to nil.
- -- That would be easy to test, just screw up db.actor and and wait for a crash.
- local goodwill = relation_registry.community_relation(squad.player_id, alife():actor():community())
- if goodwill >= FRIENDS then
- return 'friend'
- elseif goodwill <= ENEMIES then
- return 'enemy'
- else
- return 'neutral'
- end
- end
- function is_squad_enemy_to_actor(squad_name)
- return get_squad_goodwill_to_actor(squad_name) == "enemy"
- end
- function is_squad_friend_to_actor(squad_name)
- return get_squad_goodwill_to_actor(squad_name) == "friend"
- end
- function is_squad_neutral_to_actor(squad_name)
- return get_squad_goodwill_to_actor(squad_name) == "neutral"
- end
- function set_gulag_relation_actor(smart_name, relation)
- local gulag = xr_gulag.get_gulag_by_name(smart_name)
- local goodwill = getGoodwillForRelationType(relation)
- local st, act = db.storage, db.actor
- local acc, obj = act:character_community()
- -- TODO Again, check if gulag.npc_info is a list or map and adjust iterator accordingly.
- for k, v in pairs(gulag.npc_info) do
- obj = st[v.se_obj.id] and st[v.se_obj.id].object
- if obj then
- obj:set_goodwill(goodwill, act)
- obj:set_community_goodwill(acc, goodwill)
- end
- end
- end
- function get_gulag_relation_actor(smart_name, relation)
- local act = db.actor
- if not act then
- return false
- end
- local gulag = xr_gulag.get_gulag_by_name(smart_name)
- if not gulag then
- return false
- end
- local goodwill, npc_count = 0, 0
- local st = db.storage
- local obj, vid
- for k, v in pairs(gulag.npc_info) do
- vid = v.se_obj.id
- obj = st[vid] and st[vid].object
- if obj then
- goodwill = goodwill + obj:general_goodwill(act)
- npc_count = npc_count + 1
- end
- end
- if npc_count == 0 then
- return false
- end
- goodwill = goodwill / npc_count
- if relation == 'enemy' then
- return goodwill <= ENEMIES
- elseif relation == 'friend' then
- return goodwill >= FRIENDS
- else
- return goodwill < FRIENDS and goodwill > ENEMIES
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement